From a77f162b26330db906a62de5d3da4fdc59d69fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=A7al=20Isern?= Date: Wed, 24 Nov 2021 09:41:15 +0100 Subject: [PATCH] [MIG] account_payment_mode: Migration to 15.0 --- account_payment_mode/__manifest__.py | 2 +- .../models/account_journal.py | 27 ++++----- .../models/account_payment_method.py | 8 --- .../models/account_payment_mode.py | 57 +++++++++---------- account_payment_mode/readme/CONTRIBUTORS.rst | 1 + .../tests/test_account_payment_mode.py | 44 +++++++------- .../views/account_payment_method.xml | 1 - 7 files changed, 64 insertions(+), 76 deletions(-) diff --git a/account_payment_mode/__manifest__.py b/account_payment_mode/__manifest__.py index 88e2cc000..98591d455 100644 --- a/account_payment_mode/__manifest__.py +++ b/account_payment_mode/__manifest__.py @@ -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)", diff --git a/account_payment_mode/models/account_journal.py b/account_payment_mode/models/account_journal.py index 526ccdb1d..b970671fe 100644 --- a/account_payment_mode/models/account_journal.py +++ b/account_payment_mode/models/account_journal.py @@ -2,7 +2,7 @@ # @author: Alexis de Lattre # 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) ) diff --git a/account_payment_mode/models/account_payment_method.py b/account_payment_mode/models/account_payment_method.py index 1b460eb54..4c5a74531 100644 --- a/account_payment_mode/models/account_payment_method.py +++ b/account_payment_mode/models/account_payment_method.py @@ -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", - ) - ] diff --git a/account_payment_mode/models/account_payment_mode.py b/account_payment_mode/models/account_payment_mode.py index 82015ed51..a8db617b9 100644 --- a/account_payment_mode/models/account_payment_mode.py +++ b/account_payment_mode/models/account_payment_mode.py @@ -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 ) diff --git a/account_payment_mode/readme/CONTRIBUTORS.rst b/account_payment_mode/readme/CONTRIBUTORS.rst index 9d4546c37..a5f50f58b 100644 --- a/account_payment_mode/readme/CONTRIBUTORS.rst +++ b/account_payment_mode/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * Alexis de Lattre * Eric Lembregts * Andrea Stirpe +* Marçal Isern diff --git a/account_payment_mode/tests/test_account_payment_mode.py b/account_payment_mode/tests/test_account_payment_mode.py index 48b561ea7..db23e176e 100644 --- a/account_payment_mode/tests/test_account_payment_mode.py +++ b/account_payment_mode/tests/test_account_payment_mode.py @@ -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( { diff --git a/account_payment_mode/views/account_payment_method.xml b/account_payment_mode/views/account_payment_method.xml index b96d5a22b..b6c7c2923 100644 --- a/account_payment_mode/views/account_payment_method.xml +++ b/account_payment_mode/views/account_payment_method.xml @@ -31,7 +31,6 @@ here. I hate the objects that don't have a view... --> account.payment.method -