0
votes

I have two related fields in question, x_nk_categ_id and x_nk_class_desc. For some reason field "x_nk_class_desc" is returning empty rows. I have checked in the table mrp_bom, field x_nk_categ_id is correctly populated with categ_id values, but column x_nk_class_desc is empty.

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_categ_id': fields.related('product_id', 'categ_id', 
                    type='many2one', relation='product.product', 
                    string='Product Category', store=True, readonly=True),
                'x_nk_class_desc': fields.related('x_nk_categ_id', 'name', 
                    type='char', relation='product.category', string='Class 
                    Description', store=True, readonly=True),
                'x_nk_item_desc': fields.related('product_tmpl_id', 'name', 
                    type='char', relation='product.template', string='Item 
                    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" />
            <field name="x_nk_item_desc" />                         
        </xpath>
    </field>
</record>

Here is how empty Class Description looks in view:

enter image description here

1

1 Answers

2
votes

my odoo installation is a little different, but this (adapated to your case) works for me :

'x_nk_class_desc': fields.related('product_id', 'categ_id', 'name',
    type='char', string='Class Description', store=True, readonly=True),

the two changes I did are :

  • removing relation='product.category' : from this I get (maybe wrongly) that it's only useful if the last term of the reference chain is a reference ( here it's a char field )

    with this change (on master version), the Class Description of a crm.bom record is filled when I change the product of that record.

  • not using x_nk_categ_id directly but duplicating the reference chain

    this change made it work ok at installation of the module: all the Class Description column is filled.

I guess that when the module is installed, only existing field are used to fill related fields.