mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
account_payment_mode: use _check_company_auto = True on account.payment.mode
This commit is contained in:
committed by
Thomas Binsfeld
parent
bea0421f39
commit
8a7c9c88d8
@@ -14,6 +14,7 @@ class AccountPaymentMode(models.Model):
|
||||
_name = "account.payment.mode"
|
||||
_description = "Payment Modes"
|
||||
_order = "name"
|
||||
_check_company_auto = True
|
||||
|
||||
name = fields.Char(required=True, translate=True)
|
||||
company_id = fields.Many2one(
|
||||
@@ -41,6 +42,7 @@ class AccountPaymentMode(models.Model):
|
||||
string="Fixed Bank Journal",
|
||||
domain=[("type", "=", "bank")],
|
||||
ondelete="restrict",
|
||||
check_company=True,
|
||||
)
|
||||
# I need to explicitly define the table name
|
||||
# because I have 2 M2M fields pointing to account.journal
|
||||
@@ -121,20 +123,6 @@ class AccountPaymentMode(models.Model):
|
||||
)
|
||||
)
|
||||
|
||||
@api.constrains("company_id", "fixed_journal_id")
|
||||
def company_id_fixed_journal_id_constrains(self):
|
||||
for mode in self.filtered(
|
||||
lambda x: x.fixed_journal_id
|
||||
and x.company_id != x.fixed_journal_id.company_id
|
||||
):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The company of the payment mode '%s', does not match "
|
||||
"with the company of journal '%s'."
|
||||
)
|
||||
% (mode.name, mode.fixed_journal_id.name)
|
||||
)
|
||||
|
||||
@api.constrains("company_id", "variable_journal_ids")
|
||||
def company_id_variable_journal_ids_constrains(self):
|
||||
for mode in self:
|
||||
@@ -142,7 +130,7 @@ class AccountPaymentMode(models.Model):
|
||||
raise ValidationError(
|
||||
_(
|
||||
"The company of the payment mode '%s', does not match "
|
||||
"with the one of the Allowed Bank Journals."
|
||||
"with one of the Allowed Bank Journals."
|
||||
)
|
||||
% mode.name
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Copyright 2016-2020 ForgeFlow S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
@@ -48,9 +48,9 @@ class TestAccountPaymentMode(TransactionCase):
|
||||
def test_payment_mode_company_consistency_change(self):
|
||||
# Assertion on the constraints to ensure the consistency
|
||||
# for company dependent fields
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.payment_mode_c1.write({"fixed_journal_id": self.journal_c2.id})
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.payment_mode_c1.write(
|
||||
{
|
||||
"variable_journal_ids": [
|
||||
@@ -72,7 +72,7 @@ class TestAccountPaymentMode(TransactionCase):
|
||||
def test_payment_mode_company_consistency_create(self):
|
||||
# Assertion on the constraints to ensure the consistency
|
||||
# for company dependent fields
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.payment_mode_model.create(
|
||||
{
|
||||
"name": "Direct Debit of suppliers from Bank 2",
|
||||
@@ -83,7 +83,7 @@ class TestAccountPaymentMode(TransactionCase):
|
||||
}
|
||||
)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.payment_mode_model.create(
|
||||
{
|
||||
"name": "Direct Debit of suppliers from Bank 3",
|
||||
@@ -94,7 +94,7 @@ class TestAccountPaymentMode(TransactionCase):
|
||||
}
|
||||
)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
with self.assertRaises(UserError):
|
||||
self.payment_mode_model.create(
|
||||
{
|
||||
"name": "Direct Debit of suppliers from Bank 4",
|
||||
|
||||
Reference in New Issue
Block a user