0
votes

I have a custom Odoo module which, among other things, records payments. In order to do this I am using the Make Payment form from the Accounting module.

I want to allow the user to filter the options in the Payment Journal drop down based on a flag on the account.journal entity, so I have extended the entity as follows:

class AccountJournal(models.Model):
  _inherit = 'account.journal'
  available_as_payment_method = fields.Boolean(string='Available as payment method')

... and added the field in the view used to edit the payment journal:

<field name="available_as_booking_payment_method"/>

This functionality works as expected and the field exists in the database.

Finally I extended the payment form:

<record model="ir.ui.view" id="payment_form_update_form">
  <field name="name">payment_form_update</field>
  <field name="model">account.payment</field>
  <field name="inherit_id" ref="account.view_account_payment_form" />
  <field name="type">form</field>
  <field name="arch" type="xml">
    <xpath expr="//field[@name='journal_id']" position="attributes">
     <attribute name="domain">[('available_as_booking_payment_method', '=', True)]</attribute>
     <!-- <attribute name="invisible">1</attribute> -->
    </xpath>
  </field>
</record>

For some reason, if I modify the domain attribute, it is not applied. The screenshot shows the existing domain in the Odoo debug popup - this remains unchanged with my view or the default view.

If I apply the invisible flag, the field disappears, so I know that the view and the xpath are correct.

Grateful for any help as to why the domain is not being applied.

Thanks in advance

The default Odoo payment form (account.view_account_payment_form) The debug popup for the Pament Journal field

1

1 Answers

1
votes

Because journal_id has a domain definition in the .py file, you can try override the domain in the .py file too, something like this:

journal_id = fields.Many2one(domain=[('available_as_booking_payment_method', '=', True),('type', 'in', ('bank', 'cash'))])

I hope this answer can be helful for you.