2

In register payment wizard , I added 2 fields. I want to make fields invisibles according to 'move_type'

if move_type == 'in_invoice' --> field1 : invisible

if move_type == 'out_invoice' --> field2 : invisible

<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>

How can I do it ? Thanks.

CZoellner
  • 13,553
  • 3
  • 25
  • 38
K.ju
  • 541
  • 5
  • 20

2 Answers2

3

You can use the payment_type, the payment type will be Send Money for vendor bills and Receive Money for customer invoices.

Example:

<!-- 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')]}"/>
Kenly
  • 24,317
  • 7
  • 44
  • 60
1

You should use attrs attribute.

<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")]}' />

You need to have move_type in your datamodel for this to work. If not, add it as relative field. You can do it like this in your wizard code

    move_type = fields.String(related="account_move.move_type")
ex4
  • 2,289
  • 1
  • 14
  • 21
  • I haven't move_type , How can I add it as relative it in 'account.payment.register' model? – K.ju Feb 22 '21 at 17:32
  • What model has that move_type you want to use and how that model is related to your account.payment.register? And to be exact that move_type has to be in the view to use it as a condition for attrs. But to get that field into a view you need to have it in a data model. – ex4 Feb 23 '21 at 02:28
  • move_type is from standard Odoo : when creating a Vender Bill or Customer Invoice, there is a wizard when clicking on register payement .Here I added 2 fields . I Want to show /hide fields in wiard according to move_type(in_invoice/out_invoice) , meaning If it 's Vendre Bill: in wizard if register payment showing only field2 , and for Customer Invoice showing only field1. – K.ju Feb 23 '21 at 06:58