OpenERP - using name_get() function and associated field definition to display specific value

混江龙づ霸主 提交于 2019-12-11 17:39:10

问题


What I am trying to accomplish is to display formatted result, "[class_code]class_description" as defined in name_get() function in my product_category class. I have defined field, please see code below, "x_categ_id" to be many2one, in class mrp_bom, but I am getting empty rows. How I can make that formatted output (from name_get()) to appear in a field in mrp.bom? How I must define the field? What would be the reason I am getting empty column values for "x_categ_id" field?

Thanks in advance for your help.

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),
           'x_nk_item_desc': fields.related('product_tmpl_id', 'name', 
               type='char', relation='product.template', string='Item 
               Description', store=True, readonly=True),
           'x_categ_id': fields.many2one('product.category','Item Class', 
               required=True, change_default=True),
    }

Here is my XML code:

<record id="adamson_mrp_bom_form_view_2" model="ir.ui.view">
    <field name="name">adamson.mrp.bom.form.view.2</field>
    <field name="model">mrp.bom</field>
    <field name="type">form</field>
    <field name="inherit_id" 
                ref="product_extended.mrp_bom_form_view_product_extended" /> 
    <field name="arch" type="xml">
        <field name="product_tmpl_id" position="replace">
            <field name="x_categ_id" />
        </field>
        <field name="product_id" position="replace">
            <field name="x_nk_item_desc" />                 
        </field>
    </field>
</record>

来源:https://stackoverflow.com/questions/28433488/openerp-using-name-get-function-and-associated-field-definition-to-display-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!