我需要顯示在樹視圖從one2many字段值,所以我決定創建功能領域,並宣佈它在我的XML樹視圖:顯示fields.function
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>
在我的控制檯,我可以看到正確的記錄打印,但我在我的樹視圖中不顯示任何內容。
任何人都可以幫助我嗎?
你的回答是正確的...嘗試向OP解釋更多爲什麼'store = True'不起作用。所以它會對你遇到的其他人有用 – danidee
http://stackoverflow.com/questions/16185195/openerp-fields-function-explanation/16206895#16206895 – OmaL