【问题标题】:attribute invisible is not working at odoo属性不可见在 odoo 中不起作用
【发布时间】:2019-09-26 03:02:05
【问题描述】:

我不明白,为什么按钮的不可见属性在相关字段中不起作用。但是,当基于另一个字段类型条件的不可见属性(例如布尔值)时,就可以了。

我的模块或 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。对不起我的语法不好

【问题讨论】:

  • 你升级模块了吗?你想要的是,当你选择一条 id != 2 的记录时,按钮就会消失?
  • 是的,我做到了。是的当然。当记录不是 2 时,按钮消失。但是按钮上的不可见属性不能正常工作
  • 即使选择其他记录,按钮仍然存在?
  • 对不起。我的意思是,当记录为 2 时,会出现按钮。但发生的事情是按钮没有出现
  • 如果你反转域会出现按钮,你确定记录ID是2吗?

标签: python xml odoo odoo-8 odoo-9


【解决方案1】:

更新您的代码以使用当前的 ORM API。不应再使用旧的 API 声明列和相关字段的方式。您的代码仅显示 sn-ps 并没有准确地公开您的自定义模型是什么,因此我们无法知道您应该如何定义相关字段。转换后应该是这样的:

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)

如有必要,修复 measure_type 字段 ('location_id.measurement_id.type') 的 related 参数以反映您的模型结构以获得类型值。

您可以在此处找到 Odoo v9 ORM API 开发人员指南:https://www.odoo.com/documentation/9.0/reference/orm.html#related-fields。您可以在 github 上找到关于新 api 不支持旧 api 定义相关字段方式的问题:https://github.com/odoo/odoo/issues/3270

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多