Search code examples
openerp-7

show product category in stock move tree in openerp7


How can I show Category in stock move tree. This is my coding.

My view file.

<record id="royalfood_stock_move_tree_view" model="ir.ui.view">
    <field name="name">stock.move.tree</field>
    <field name="model">stock.move</field>
    <field name="inherit_id" ref="stock.view_move_tree" />
    <field name="arch" type="xml"> 
              <xpath expr="//field[@name='product_id']" position="before">  
            <field name="categ_id" groups="base.group_user"/>   
              </xpath> 
    </field>
</record>

My .py File

class custom_stock_move_tree(osv.osv_memory):
_columns = {    
             'categ_id': fields.related('product_id', 'categ_id', type='many2one' ,relation='product.category', store=True),              
            }
custom_stock_move_tree()

Any Help is Appreciated.


Solution

  • try this files.

    your .py file

    class custom_stock_move_tree(osv.Model): #their is different b/w osv.Model and osv.osv_memory before to use it read it's usage
    
        _inherit = 'stock.move' # if you want to add data in existing module use inherit  
        _columns = 
        {    
            'categ_id': fields.related('product_id', 'categ_id', type='many2one' ,relation='product.category', store=True, string='Product Category'),              
        }
    

    Your view.xml file

    <record id="royalfood_stock_move_tree_view" model="ir.ui.view">
    <field name="name">stock.move.tree</field>
    <field name="model">stock.move</field>
    <field name="inherit_id" ref="stock.view_move_tree" />
    <field name="arch" type="xml"> 
        <xpath expr="//field[@name='product_id']" position="before">  
            <field name="categ_id" groups="base.group_user"/>   
        </xpath> 
    </field>
    

    After this see your Stock Move Tree view.