在树视图odoo上显示fields.function

时间:2015-04-07 16:57:02

标签: python treeview odoo

我需要在树视图中显示one2many字段的值,所以我决定创建功能字段并在我的xml树视图中声明它:

def get_product_brands(self, cr, uid, ids, fields, arg, context):
    res={}
    for record in self.browse(cr, uid, ids, context=None).application_data_product_template_ids:
        brands = record.brand.name or ''
    print brands
    res[record.id] = brands
    return res

和我的现场声明:

'brands' : fields.function(get_product_brands, method=True, string="Product brands", type='char', store=True)

xml示例代码:

<record model="ir.ui.view" id="product_tree_inherit">
    <field name="name">product.tree.inherit</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_tree_view"/>
    <field name="arch" type="xml">
         <xpath expr="//field[@name='categ_id']" position="after"> 
             <field name="brands"/>
         </xpath>
    </field>
</record>

在我的控制台中,我可以看到正确的记录打印但我在树视图中没有显示任何内容。

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:1)

从功能字段中删除商店属性

答案 1 :(得分:0)

这只是因为代码中的错误缩进。试试以下,

def get_product_brands(self, cr, uid, ids, fields, arg, context):
    res={}
    for record in self.browse(cr, uid, ids, context=None).application_data_product_template_ids:
        brands = record.brand.name or ''
        print brands
        res[record.id] = brands
    return res

您已将res[record.id]放在循环旁边,这就是它。

相关问题