diff --git a/l10n_be_iso20022_pain/__manifest__.py b/l10n_be_iso20022_pain/__manifest__.py index e36d97b7..9267f85a 100644 --- a/l10n_be_iso20022_pain/__manifest__.py +++ b/l10n_be_iso20022_pain/__manifest__.py @@ -9,6 +9,7 @@ "license": "AGPL-3", "author": "ACSONE SA/NV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/l10n-belgium", - "depends": ["account_payment_order"], + "depends": ["account_payment_order", "l10n_be"], "installable": True, + "data": ["views/account_journal.xml"], } diff --git a/l10n_be_iso20022_pain/models/account_payment_line.py b/l10n_be_iso20022_pain/models/account_payment_line.py index e96ab90c..1ddab1b6 100644 --- a/l10n_be_iso20022_pain/models/account_payment_line.py +++ b/l10n_be_iso20022_pain/models/account_payment_line.py @@ -10,10 +10,13 @@ class AccountPaymentLine(models.Model): _inherit = "account.payment.line" - @api.constrains("communication", "communication_type") + @api.constrains("order_id", "communication", "communication_type") def _check_communication(self): for rec in self: - if rec.communication_type == "structured" and not check_bbacomm( - rec.communication + if ( + rec.order_id.journal_id.invoice_reference_type == "invoice" + and rec.order_id.journal_id.invoice_reference_model == "be" + and rec.communication_type == "structured" + and not check_bbacomm(rec.communication) ): raise ValidationError(_("Invalid BBA Structured Communication !")) diff --git a/l10n_be_iso20022_pain/tests/test_l10n_be_iso20022_pain.py b/l10n_be_iso20022_pain/tests/test_l10n_be_iso20022_pain.py index 0a0ef966..eca76841 100644 --- a/l10n_be_iso20022_pain/tests/test_l10n_be_iso20022_pain.py +++ b/l10n_be_iso20022_pain/tests/test_l10n_be_iso20022_pain.py @@ -20,6 +20,8 @@ def setUpClass(cls): cls.journal_model = cls.env["account.journal"] # INSTANCES cls.bank_journal = cls.journal_model.search([("type", "=", "bank")], limit=1) + cls.bank_journal.invoice_reference_type = "invoice" + cls.bank_journal.invoice_reference_model = "be" # Instance: Payment Mode cls.payment_mode = cls.payment_mode_model.create( { @@ -50,6 +52,13 @@ def setUpClass(cls): "payment_mode_id": cls.payment_mode.id, } ) + cls.payment_order = cls.env["account.payment.order"].create( + { + "payment_type": "inbound", + "payment_mode_id": cls.payment_mode.id, + "journal_id": cls.bank_journal.id, + } + ) def _prepare_payment_line_creation_dict(self): return { @@ -57,6 +66,7 @@ def _prepare_payment_line_creation_dict(self): "partner_id": self.env.ref("base.res_partner_2").id, "amount_currency": 123.321, "communication_type": "structured", + "order_id": self.payment_order.id, } def test_create_account_payment_line_01(self): @@ -132,3 +142,33 @@ def test_create_account_payment_line_05(self): vals = self._prepare_payment_line_creation_dict() vals["communication"] = "868054273023" self.payment_line_model.create(vals) + + def test_create_account_payment_line_06(self): + """ + Data: + - No invoice, no payment line, nothing + Test case: + - Create a new payment line with invalid BBA communication + (too long) but the bank journal invoice_reference_type is none + Expected result: + - The payment line is created with the valid communication + """ + self.bank_journal.invoice_reference_type = "none" + vals = self._prepare_payment_line_creation_dict() + vals["communication"] = "86805427302" + self.payment_line_model.create(vals) + + def test_create_account_payment_line_07(self): + """ + Data: + - No invoice, no payment line, nothing + Test case: + - Create a new payment line with invalid BBA communication + (too long) but the bank journal invoice_reference_model is not be + Expected result: + - The payment line is created with the valid communication + """ + self.bank_journal.invoice_reference_model = False + vals = self._prepare_payment_line_creation_dict() + vals["communication"] = "86805427302" + self.payment_line_model.create(vals) diff --git a/l10n_be_iso20022_pain/views/account_journal.xml b/l10n_be_iso20022_pain/views/account_journal.xml new file mode 100644 index 00000000..239a5965 --- /dev/null +++ b/l10n_be_iso20022_pain/views/account_journal.xml @@ -0,0 +1,21 @@ + + + + + + account.journal + + + + type not in ('sale', 'bank') + + + + + + +