首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >属性不可见属性在odoo不起作用。

属性不可见属性在odoo不起作用。
EN

Stack Overflow用户
提问于 2019-09-26 03:02:05
回答 1查看 1.1K关注 0票数 1

我不明白,为什么按钮的不可见属性不能在相关字段中工作。但是,当基于另一个字段类型条件的不可见属性,比如布尔值时,这是可行的。

我在模块或python文件上的代码是

代码语言:javascript
复制
'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文件上的脚本

代码语言:javascript
复制
<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.对不起,我语法不好,

EN

回答 1

Stack Overflow用户

发布于 2019-09-26 18:48:31

更新您的代码以使用当前的ORM。不应再使用以前声明列和相关字段的API方式。您的代码只显示代码片段,不公开您的自定义模型是什么,因此我们无法知道您应该如何定义相关字段。转换之后,它应该如下所示:

代码语言:javascript
复制
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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58109002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档