[MIG] account_payment_mode: Migration to 15.0

This commit is contained in:
Marçal Isern
2021-11-24 09:41:15 +01:00
committed by Thomas Binsfeld
parent 63d4dde50c
commit a77f162b26
7 changed files with 64 additions and 76 deletions

View File

@@ -4,7 +4,7 @@
{
"name": "Account Payment Mode",
"version": "14.0.1.0.2",
"version": "15.0.1.0.0",
"development_status": "Production/Stable",
"license": "AGPL-3",
"author": "Akretion,Odoo Community Association (OCA)",

View File

@@ -2,7 +2,7 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo import _, api, models
from odoo.exceptions import ValidationError
@@ -21,13 +21,6 @@ class AccountJournal(models.Model):
)
return all_in
outbound_payment_method_ids = fields.Many2many(
default=_default_outbound_payment_methods
)
inbound_payment_method_ids = fields.Many2many(
default=_default_inbound_payment_methods
)
@api.constrains("company_id")
def company_id_account_payment_mode_constrains(self):
for journal in self:
@@ -41,11 +34,12 @@ class AccountJournal(models.Model):
if mode:
raise ValidationError(
_(
"The company of the journal '%s' does not match "
"with the company of the payment mode '%s' where it is "
"being used as Fixed Bank Journal."
"The company of the journal %(journal)s does not match "
"with the company of the payment mode %(paymode)s where it is "
"being used as Fixed Bank Journal.",
journal=journal.name,
paymode=mode.name,
)
% (journal.name, mode.name)
)
mode = self.env["account.payment.mode"].search(
[
@@ -57,9 +51,10 @@ class AccountJournal(models.Model):
if mode:
raise ValidationError(
_(
"The company of the journal '%s' does not match "
"with the company of the payment mode '%s' where it is "
"being used in the Allowed Bank Journals."
"The company of the journal %(journal)s does not match "
"with the company of the payment mode %(paymode)s where it is "
"being used in the Allowed Bank Journals.",
journal=journal.name,
paymode=mode.name,
)
% (journal.name, mode.name)
)

View File

@@ -38,11 +38,3 @@ class AccountPaymentMethod(models.Model):
)
)
return result
_sql_constraints = [
(
"code_payment_type_unique",
"unique(code, payment_type)",
"A payment method of the same type already exists with this code",
)
]

View File

@@ -80,47 +80,44 @@ class AccountPaymentMode(models.Model):
if not mode.fixed_journal_id:
raise ValidationError(
_(
"On the payment mode '%s', the bank account link is "
"'Fixed' but the fixed bank journal is not set"
"On the payment mode %(name)s, the bank account link is "
"'Fixed' but the fixed bank journal is not set",
name=mode.name,
)
% mode.name
)
else:
f_journal = mode.fixed_journal_id
if mode.payment_method_id.payment_type == "outbound":
if (
mode.payment_method_id.id
not in mode.fixed_journal_id.outbound_payment_method_ids.ids
):
p_modes = f_journal.outbound_payment_method_line_ids.mapped(
"payment_method_id.id"
)
if mode.payment_method_id.id not in p_modes:
raise ValidationError(
_(
"On the payment mode '%s', the payment method "
"is '%s', but this payment method is not part "
"On the payment mode %(paymode)s, the payment method "
"is %(paymethod)s, but this payment method is not part "
"of the payment methods of the fixed bank "
"journal '%s'"
)
% (
mode.name,
mode.payment_method_id.name,
mode.fixed_journal_id.name,
"journal %(journal)s",
paymode=mode.name,
paymethod=mode.payment_method_id.name,
journal=mode.fixed_journal_id.name,
)
)
else:
if (
mode.payment_method_id.id
not in mode.fixed_journal_id.inbound_payment_method_ids.ids
):
p_modes = f_journal.inbound_payment_method_line_ids.mapped(
"payment_method_id.id"
)
if mode.payment_method_id.id not in p_modes:
raise ValidationError(
_(
"On the payment mode '%s', the payment method "
"is '%s' (it is in fact a debit method), "
"On the payment mode %(paymode)s, the payment method "
"is %(paymethod)s (it is in fact a debit method), "
"but this debit method is not part "
"of the debit methods of the fixed bank "
"journal '%s'"
)
% (
mode.name,
mode.payment_method_id.name,
mode.fixed_journal_id.name,
"journal %(journal)s",
paymode=mode.name,
paymethod=mode.payment_method_id.name,
journal=mode.fixed_journal_id.name,
)
)
@@ -130,8 +127,8 @@ class AccountPaymentMode(models.Model):
if any(mode.company_id != j.company_id for j in mode.variable_journal_ids):
raise ValidationError(
_(
"The company of the payment mode '%s', does not match "
"with one of the Allowed Bank Journals."
"The company of the payment mode %(paymode)s, does not match "
"with one of the Allowed Bank Journals.",
paymode=mode.name,
)
% mode.name
)

View File

@@ -1,3 +1,4 @@
* Alexis de Lattre <alexis.delattre@akretion.com>
* Eric Lembregts <eric@lembregts.eu>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Marçal Isern <marsal.isern@qubiq.es>

View File

@@ -6,41 +6,45 @@ from odoo.tests.common import TransactionCase
class TestAccountPaymentMode(TransactionCase):
def setUp(self):
super(TestAccountPaymentMode, self).setUp()
self.res_users_model = self.env["res.users"]
self.journal_model = self.env["account.journal"]
self.payment_mode_model = self.env["account.payment.mode"]
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.res_users_model = cls.env["res.users"]
cls.journal_model = cls.env["account.journal"]
cls.payment_mode_model = cls.env["account.payment.mode"]
# refs
self.manual_out = self.env.ref("account.account_payment_method_manual_out")
cls.manual_out = cls.env.ref("account.account_payment_method_manual_out")
# Company
self.company = self.env.ref("base.main_company")
cls.company = cls.env.ref("base.main_company")
# Company 2
self.company_2 = self.env["res.company"].create({"name": "Company 2"})
cls.company_2 = cls.env["res.company"].create({"name": "Company 2"})
self.journal_c1 = self._create_journal("J1", self.company)
self.journal_c2 = self._create_journal("J2", self.company_2)
self.journal_c3 = self._create_journal("J3", self.company)
cls.journal_c1 = cls._create_journal("J1", cls.company)
cls.journal_c2 = cls._create_journal("J2", cls.company_2)
cls.journal_c3 = cls._create_journal("J3", cls.company)
self.payment_mode_c1 = self.payment_mode_model.create(
cls.payment_mode_c1 = cls.payment_mode_model.create(
{
"name": "Direct Debit of suppliers from Bank 1",
"bank_account_link": "variable",
"payment_method_id": self.manual_out.id,
"company_id": self.company.id,
"fixed_journal_id": self.journal_c1.id,
"payment_method_id": cls.manual_out.id,
"company_id": cls.company.id,
"fixed_journal_id": cls.journal_c1.id,
"variable_journal_ids": [
(6, 0, [self.journal_c1.id, self.journal_c3.id])
(6, 0, [cls.journal_c1.id, cls.journal_c3.id])
],
}
)
def _create_journal(self, name, company):
@classmethod
def _create_journal(cls, name, company):
# Create a cash account
# Create a journal for cash account
journal = self.journal_model.create(
journal = cls.journal_model.create(
{"name": name, "code": name, "type": "bank", "company_id": company.id}
)
return journal
@@ -103,7 +107,7 @@ class TestAccountPaymentMode(TransactionCase):
"company_id": self.company.id,
}
)
self.journal_c1.outbound_payment_method_ids = False
self.journal_c1.outbound_payment_method_line_ids = False
with self.assertRaises(ValidationError):
self.payment_mode_model.create(
{
@@ -114,7 +118,7 @@ class TestAccountPaymentMode(TransactionCase):
"fixed_journal_id": self.journal_c1.id,
}
)
self.journal_c1.inbound_payment_method_ids = False
self.journal_c1.inbound_payment_method_line_ids = False
with self.assertRaises(ValidationError):
self.payment_mode_model.create(
{

View File

@@ -31,7 +31,6 @@ here. I hate the objects that don't have a view... -->
<field name="model">account.payment.method</field>
<field name="arch" type="xml">
<tree>
<field name="sequence" widget="handle" />
<field name="name" />
<field name="code" />
<field name="payment_type" />