我不明白,为什么按钮的invisible属性在相关字段中不起作用。但是,当基于另一个字段类型条件的不可见属性(如boolean)有效时。
我的模块或python文件上的代码为
'location_id' : fields.many2one('stock.location', string='Storage'),
'measurement_type' : fields.related('location_id','measurement_id', type="many2one",
relation="flow.measure.type", string = "Measurement Type", readonly=True, store=True),
这是我在xml文件上的脚本
<field name="measurement_type" />
<field name="location_id" required="1" context="{'full':1}"
on_change="onchange_location(location_id,measure_date)"
domain="[('usage','not in',['view','transit','inventory']),
('location_id','child_of',parent.location_id)]" />
<button name="open_flowmeter" string="Flowmeter Measurement"
type="object" icon="fa-exchange"
attrs="{'invisible':[('measurement_type','!=',2)]}"/>
并且数据库中measurement_type字段的数据类型为整数。
我的目标是当记录(measurement_type)为2时,将出现按钮。但是,发生的是按钮没有出现。而且无论获得的记录值如何,该按钮仍然不会出现
PS。对不起,我的语法不好
更新您的代码以使用当前的ORM API。声明列和相关字段的旧API方法不再使用。您的代码仅显示摘录,而不能完全显示您的自定义模型,因此我们无法知道您应该如何定义相关字段。转换后,它应该看起来像这样:
location_id = Fields.Many2One('stock.location', string='Storage')
measurement_type = Fields.Integer(related='location_id.measurement_id.type', string = "Measurement Type", readonly=True, store=True)
[如有必要,将measurement_type字段的related
参数固定为“ location_id.measurement_id.type”,以反映您的模型结构以获取类型值。
您可以在以下位置找到Odoo v9 ORM API开发人员指南:https://www.odoo.com/documentation/9.0/reference/orm.html#related-fields。您可以找到有关新api的github问题,该问题不支持定义相关字段的旧api方法:https://github.com/odoo/odoo/issues/3270