如何隐藏字段取决于条件odoo?
How to hide field depend on condition odoo?
attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}"
上面的代码不起作用,我该如何解决这个问题?
class test_list(models.Model):
_name = 'test.list'
type_test = fields.Selection([('A', 'aaaa'),('B','bbbbb')], default='A', string="Type", required=True)
rule_list = fields.One2many('test.rule', 'rule_id')
class test_rule(models.Model):
_name = 'test.rule'
rule_id = fields.Many2one('test.list', required=True)
ul = fields.Many2one('product.ul', string='Package Logistic Unit'
<record model="ir.ui.view" id="rules_form_view">
<field name="name">test.rules.form.view</field>
<field name="model">test.rule</field>
<field name="arch" type="xml">
<form string="Test Rules">
<field name="ul" attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}"/>
</form>
</field>
</record>
您在 attrs
中使用的字段需要出现在当前视图中。
您可以将此字段添加到模型中:
class test_rule(models.Model):
_name = 'test.rule'
rule_id = fields.Many2one('test.list', required=True)
type_test = fields.Selection(related='rule_id.type_test')
ul = fields.Many2one('product.ul', string='Package Logistic Unit')
然后到你的表格:
<form string="Test Rules">
<field name="type_test" invisible="1"/>
<field name="ul" attrs="{'invisible': [('type_test', '!=', 'A')]}"/>
</form>
attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}"
上面的代码不起作用,我该如何解决这个问题?
class test_list(models.Model):
_name = 'test.list'
type_test = fields.Selection([('A', 'aaaa'),('B','bbbbb')], default='A', string="Type", required=True)
rule_list = fields.One2many('test.rule', 'rule_id')
class test_rule(models.Model):
_name = 'test.rule'
rule_id = fields.Many2one('test.list', required=True)
ul = fields.Many2one('product.ul', string='Package Logistic Unit'
<record model="ir.ui.view" id="rules_form_view">
<field name="name">test.rules.form.view</field>
<field name="model">test.rule</field>
<field name="arch" type="xml">
<form string="Test Rules">
<field name="ul" attrs="{'invisible': [('rule_id.type_test', '!=', 'A')]}"/>
</form>
</field>
</record>
您在 attrs
中使用的字段需要出现在当前视图中。
您可以将此字段添加到模型中:
class test_rule(models.Model):
_name = 'test.rule'
rule_id = fields.Many2one('test.list', required=True)
type_test = fields.Selection(related='rule_id.type_test')
ul = fields.Many2one('product.ul', string='Package Logistic Unit')
然后到你的表格:
<form string="Test Rules">
<field name="type_test" invisible="1"/>
<field name="ul" attrs="{'invisible': [('type_test', '!=', 'A')]}"/>
</form>