在Odoo中的Many2one字段值上设置域

时间:2015-08-04 06:47:51

标签: python openerp odoo openerp-7 openerp-8

我使用自定义域 res.partner 模块填充 Many2one 字段。

当用户从 Many2one 字段中选择一个值时,我想根据所选值隐藏一些字段。

我试试这个:

<group string="My group name" attrs="{'invisible': [('mym2ofield', 'not ilike', 'mym2ofield value')]}">

但它不起作用。那我怎么能实现呢?

1 个答案:

答案 0 :(得分:1)

首先,我们需要在模型中添加相关字段。而不是在attrs

中使用新的相关字段

例如:

type是你的many2one表上的一个char字段。

class model_name(models.Model):
    _name = 'model.name'

    test_id = fields.Many2one('relation.table.name', string="Many2One Label")
    type = fields.Char(related='test_id.type', string="Type")

然后到你的表格:

<group string="group name" attrs="{'invisible': [('type', '!=', 'value')]}">
相关问题