Search code examples
odoo

OpenERP - bringing related field from another table into tree view


I am trying to bring in "name" field from product.category table into the tree view via related x_nk_class_desc field. Here is my py code:

class mrp_bom(osv.osv):
    _inherit = 'mrp.bom'
        _name = 'mrp.bom'

        _columns = {
                'x_nk_default_code': fields.related('product_id', 'default_code', type='char', relation='product.product', string='Part Number', store=True, readonly=True),
                'x_nk_class_desc': fields.related('product_tmpl_id', 'categ_id', type='char', relation='product.template', string='Class Description', store=True, readonly=True),
        }

Here is my XML code:

<record id="adamson_mrp_bom_tree_view_2" model="ir.ui.view">
    <field name="name">adamson.mrp.bom.tree.view.2</field>
    <field name="model">mrp.bom</field>
    <field name="type">tree</field>
    <field name="inherit_id" 
                 ref="adamson_systems_engineering.adamson_mrp_bom_tree_view" 
                 />
    <field name="arch" type="xml">
        <xpath expr="/tree/field[@name='product_id']" position="replace">
            <field name="x_nk_default_code" />
            <field name="x_nk_class_desc" />                            
        </xpath>
    </field>
</record>

The issue is I am getting "product.category(209,)" as the result in x_nk_class_desc column. I am expecting value of "name" column from product.category table. How this can be achieved? Thanks in advance.


Solution

  • try with this code:

    class mrp_bom(osv.osv):
        _inherit = 'mrp.bom'
        _name = 'mrp.bom'
    
        _columns = {
            'x_nk_default_code': fields.related('product_id', 'default_code', type='char', relation='product.product', string='Part Number', store=True, readonly=True),
            'x_nk_class_desc': fields.related('product_id', categ_id', 'name', type='char', string='Class Description', store=True, readonly=True),
        }