如何使按钮出现在 Odoo 中
How to make a button appear in condition in Odoo
我创建了一个继承模块 stock.inventory 的模块,
我希望按钮“第一次验证”仅在 "real quantity" 与 "theoretical quantity" 不同时出现。
这是界面:
enter image description here
这是我的 xml 代码:
<record id="linh_view_inventory_form_ext" model="ir.ui.view">
<field name="name">linh.view.inventory.form.ext</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock_account.view_inventory_form_inherit"/>
<field name="form">form</field>
<field name="arch" type="xml">
<button name="action_cancel_inventory" states="confirm" string="Cancel Inventory" type="object" position="before">
<button name="inventory_1st_validate" states="need_validate" string="1st Validate" class="oe_highlight" type="object" attrs="{'invisible':[('theoretical_qty','=','product_qty')]}/>
</button>
<field name="state" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,confirm,acct_validated,done"/>
</field>
</field>
</record>
但是我得到了这个错误:
Error: Unknown field theoretical_qty in domain
[["theoretical_qty","=","product_qty"],["state","not
in",["need_validate"]]]
"theoretical_qty" 是我从模型 "stock.picking" 得到的 "theoretical quantity" 的字段名称。不知道为什么view不识别
非常感谢您的帮助。
theoretical_qty
是stock.inventory.line的字段,不能在stock.inventory[=22=里面直接使用].
您只能在 stock.inventory.line 的 tree/form 视图中使用它。
还有一件事,要在 attrs 中使用字段,它 必须 也出现在视图中。
(在当前视图或继承的父视图中)。
我创建了一个继承模块 stock.inventory 的模块, 我希望按钮“第一次验证”仅在 "real quantity" 与 "theoretical quantity" 不同时出现。 这是界面: enter image description here
这是我的 xml 代码:
<record id="linh_view_inventory_form_ext" model="ir.ui.view">
<field name="name">linh.view.inventory.form.ext</field>
<field name="model">stock.inventory</field>
<field name="inherit_id" ref="stock_account.view_inventory_form_inherit"/>
<field name="form">form</field>
<field name="arch" type="xml">
<button name="action_cancel_inventory" states="confirm" string="Cancel Inventory" type="object" position="before">
<button name="inventory_1st_validate" states="need_validate" string="1st Validate" class="oe_highlight" type="object" attrs="{'invisible':[('theoretical_qty','=','product_qty')]}/>
</button>
<field name="state" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,confirm,acct_validated,done"/>
</field>
</field>
</record>
但是我得到了这个错误:
Error: Unknown field theoretical_qty in domain [["theoretical_qty","=","product_qty"],["state","not in",["need_validate"]]]
"theoretical_qty" 是我从模型 "stock.picking" 得到的 "theoretical quantity" 的字段名称。不知道为什么view不识别
非常感谢您的帮助。
theoretical_qty
是stock.inventory.line的字段,不能在stock.inventory[=22=里面直接使用].
您只能在 stock.inventory.line 的 tree/form 视图中使用它。
还有一件事,要在 attrs 中使用字段,它 必须 也出现在视图中。
(在当前视图或继承的父视图中)。