I try to do this: When an invoice is created, if the customer is "x" some journals must be restricted in "Register Payment" form
This is my .py model
from odoo import api, fields, models
class AccountPayment(models.Model):
_inherit = "account.payment"
_description = "Restrict Journals"
partner_id_check = fields.Integer(compute="_compute_value")
restriction_value = fields.Boolean(related="journal_id.restriction")
@api.onchange("partner_id")
def _compute_value(self):
if self.partner_id.name == "Generic":
self.partner_id_check = 1
else:
self.partner_id_check = 0
class AccountJournal(models.Model):
_inherit = "account.journal"
_description = ""
restriction = fields.Boolean(string="Generic Restriction")
And this is my .xml file
<record id="account_journal_view_form" model="ir.ui.view">
<field name="name">account.journal.view.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet//field[@name='type']" position="before">
<field name="restriction"/>
</xpath>
</field>
</record>
<record id="payment_invoice_form" model="ir.ui.view">
<field name="name">payment.invoice.form</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_invoice_form"/>
<field name="priority" eval="16"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='journal_id']" position="attributes">
<attribute name="domain">
[('restriction_value','=',True),('partner_id_check','=',1)]
</attribute>
</xpath>
</field>
</record>
The problem is that, the domain from xpath is not working. I don't get any errors but it doesn't have effect. If turn on developer mode and get the fields, the domain is there, xpath is correct, I don't think that domain syntax is correct. I tried everything but it doesn't seem to work