【发布时间】:2016-09-06 18:22:54
【问题描述】:
我需要根据 Char 字段中是否包含特定字符串来隐藏或显示按钮。 'like' 运算符似乎是完美的。在我的 xml 中,我有:
<record model="ir.ui.view" id="my_view">
<field name="name">my.form</field>
<field name="model">mymodule.my</field>
<field name="arch" type="xml">
<form string="My Form">
<header>
<button name="test_like_1" type="object"
string="Should not appear"
attrs="{'invisible':[('state2','like','measure')]}"
/>
<button name="test_like_2" type="object"
string="Should appear"
attrs="{'invisible':[('state2','not like','measure')]}"
/>
...
State2 包含“measure,prelien”,所以我希望第一个按钮不可见,而第二个按钮可见。但是,两者都是不可见的。
我错过了什么?
编辑
我运行了我认为 Odoo 将从该域创建的查询 -
select id, description, state2 from mymodule_my where state2 like '%measure%';
它按预期运行,返回具有“测量”作为子字符串的记录。不知何故,这个 SQL 没有被生成/使用。我的下一步是挖掘 Odoo 代码并查看发生了什么。
谁能提供关于发生了什么的见解?
【问题讨论】:
-
@Kenly - 我已经读了好几遍了。根据我在该答案中的理解,我所拥有的应该可以工作,但事实并非如此。感觉好像我遗漏了一些明显的东西,但我找不到它。