mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
account_payment_partner: FIX form view of account.move
Replace python constraint by check_company=True on payment_mode_id of account.move
This commit is contained in:
committed by
Thomas Binsfeld
parent
f067a0eea4
commit
3e2c2b8cea
@@ -2,8 +2,7 @@
|
||||
# Copyright 2014 Serv. Tecnol. Avanzados - Pedro M. Baeza
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
@@ -21,6 +20,7 @@ class AccountMove(models.Model):
|
||||
store=True,
|
||||
ondelete="restrict",
|
||||
readonly=False,
|
||||
check_company=True,
|
||||
)
|
||||
bank_account_required = fields.Boolean(
|
||||
related="payment_mode_id.payment_method_id.bank_account_required", readonly=True
|
||||
@@ -101,18 +101,6 @@ class AccountMove(models.Model):
|
||||
move_vals["partner_bank_id"] = self.partner_bank_id.id
|
||||
return move_vals
|
||||
|
||||
@api.constrains("company_id", "payment_mode_id")
|
||||
def _check_payment_mode_company_constrains(self):
|
||||
for rec in self.sudo():
|
||||
if rec.payment_mode_id and rec.company_id != rec.payment_mode_id.company_id:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The company of the invoice %s does not match "
|
||||
"with that of the payment mode"
|
||||
)
|
||||
% rec.name
|
||||
)
|
||||
|
||||
def partner_banks_to_show(self):
|
||||
self.ensure_one()
|
||||
if self.partner_bank_id:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import _, fields
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
@@ -288,7 +288,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
self.assertEqual(invoice.payment_mode_id, aml[0].payment_mode_id)
|
||||
|
||||
def test_invoice_constrains(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.move_model.create(
|
||||
{
|
||||
"partner_id": self.supplier.id,
|
||||
@@ -306,7 +306,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
"company_id": self.company.id,
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.supplier_payment_mode.company_id = self.company_2
|
||||
|
||||
def test_payment_mode_constrains_02(self):
|
||||
@@ -343,7 +343,7 @@ class TestAccountPaymentPartner(common.SavepointCase):
|
||||
],
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.supplier_payment_mode.company_id = self.company_2
|
||||
|
||||
def test_invoice_refund(self):
|
||||
|
||||
@@ -23,22 +23,18 @@
|
||||
<field name="model">account.move</field>
|
||||
<field name="inherit_id" ref="account.view_move_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath
|
||||
expr="//div[field[@name='invoice_payment_term_id']]"
|
||||
position="after"
|
||||
>
|
||||
<field name="partner_bank_id" position="before">
|
||||
<field
|
||||
name="payment_mode_id"
|
||||
domain="[('payment_type', '=', payment_mode_filter_type_domain), ('company_id', '=', company_id)]"
|
||||
widget="selection"
|
||||
attrs="{'readonly': [('state', '!=', 'draft')]}"
|
||||
invisible="context.get('default_type') not in ('out_invoice','out_refund','in_invoice','in_refund')"
|
||||
attrs="{'readonly': [('state', '!=', 'draft')], 'invisible': [('move_type', 'not in', ('out_invoice','out_refund','in_invoice','in_refund'))]}"
|
||||
/>
|
||||
<field name="commercial_partner_id" invisible="1" />
|
||||
<field name="bank_account_required" invisible="1" />
|
||||
<field name="payment_mode_filter_type_domain" invisible="1" />
|
||||
<field name="partner_bank_filter_type_domain" invisible="1" />
|
||||
</xpath>
|
||||
</field>
|
||||
<field name="partner_bank_id" position="attributes">
|
||||
<attribute name="domain">
|
||||
[('partner_id', '=', partner_bank_filter_type_domain),
|
||||
|
||||
Reference in New Issue
Block a user