问题描述
在注册付款向导中,我添加了 2 个字段。我想根据'move_type'使字段不可见
if move_type == 'in_invoice' --> field1:不可见
if move_type == 'out_invoice' --> field2 : 不可见
<record id="view_account_payment_register_form_inherit_payment_test" model="ir.ui.view">
<field name="name">account.payment.register.form.inherit.payment.test</field>
<field name="model">account.payment.register</field>
<field name="inherit_id" ref="account.view_account_payment_register_form"/>
<field name="arch" type="xml">
<xpath expr="//group/field[@name='communication']" position="after">
<field name="field1"/>
<field name="field2"/>
</xpath>
</field>
</record>
我该怎么做? 谢谢。
解决方法
您可以使用 payment_type
,供应商账单的付款类型为 Send Money
,客户发票的付款类型为 Receive Money
。
示例:
<!-- move_type == in_invoice (Vendor Bill) -> payment_type == outbound (Send Money) -->
<field name="field1" attrs="{'invisible': [('payment_type','=','outbound')]}"/>
<!-- move_type == out_invoice (Customer Invoice) -> payment_type == inbound (Receive Money) -->
<field name="field2" attrs="{'invisible': [('payment_type','inbound')]}"/>
,
您应该使用 attrs
属性。
<field name="move_type" invisible="1" /> <!-- you need this for attrs domain work -->
<field name="field1" attrs='{"invisible":[("move_type","=","in_invoice")]}' />
<field name="field2" attrs='{"invisible":[("move_type","out_invoice")]}' />
您需要在数据模型中有 move_type
才能使其工作。如果没有,请将其添加为相对字段。你可以在你的向导代码中这样做
move_type = fields.String(related="account_move.move_type")