【问题标题】:Display fields.function on tree view odoo在树视图odoo上显示fields.function
【发布时间】:2015-04-07 16:57:01
【问题描述】:

我需要在树视图中显示 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>

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

谁能帮帮我?

【问题讨论】:

    标签: python treeview odoo


    【解决方案1】:

    从函数字段中移除 store 属性

    【讨论】:

    【解决方案2】:

    这只是因为代码中的错误缩进。尝试关注,

    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] 放在循环之外,就是这样。

    【讨论】:

    • 文件 "/home/odoo/openerp/models.py",第 5219 行,在 ensure_one 中引发 except_orm("ValueError", "Expected singleton: %s" % self) except_orm: ('ValueError' , '预期的单例:product.template(8, 4, 5, 9, 2, 3, 7)')
    • 如果我使用这个功能,我会得到这个错误,你知道为什么会这样吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多