我不明白,为什么按钮的不可见属性不能在相关字段中工作。但是,当基于另一个字段类型条件的不可见属性,比如布尔值时,这是可行的。
我在模块或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.对不起,我语法不好,
发布于 2019-09-26 18:48:31
更新您的代码以使用当前的ORM。不应再使用以前声明列和相关字段的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字段('location_id.measurement_id.type')的measurement_type参数,以反映模型结构以获得类型值。
您可以在这里找到Odoo开发人员指南: v9。您可以找到关于新api不支持定义相关字段的旧api方式的github问题:https://github.com/odoo/odoo/issues/3270
https://stackoverflow.com/questions/58109002
复制相似问题