2015-02-06 44 views
2

我想通過相關的x_nk_class_desc字段將product.category表中的「name」字段引入樹視圖。這裏是我的PY代碼:OpenERP - 從另一張桌子的相關領域進入樹形視圖

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), 
     } 

這裏是我的XML代碼:

<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> 

的問題是,我得到 「product.category(209)」 的結果x_nk_class_desc列。我期待product.category表中「name」列的值。這可以如何實現?提前致謝。

回答

2

嘗試使用此代碼:

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), 
    } 

Here is an example of related field in Odoo.

+0

x_nk_category_id ':fields.many2one(' product.category」, '分類')試試這個 – 2015-02-06 18:09:11

+0

嗨Odedra。你的答案中的代碼是正確的,我使用你的代碼,x_nk_categ_id被填充了實際的類別id(而不是x_category_code),所以沒有必要從product.category中獲取id。然而,我仍然得到空行,調查爲什麼。 (我刪除了我之前的一些評論,因爲它們不相關)。 – Nash 2015-02-06 18:16:38

+0

你知道爲什麼還有空行被返回嗎?代碼似乎是正確的,但。 – Nash 2015-02-06 18:48:14

相關問題