diff --git a/l10n_be_iso20022_pain/__manifest__.py b/l10n_be_iso20022_pain/__manifest__.py index e07a526b..e36d97b7 100644 --- a/l10n_be_iso20022_pain/__manifest__.py +++ b/l10n_be_iso20022_pain/__manifest__.py @@ -5,7 +5,7 @@ "name": "ISO 20022 PAIN Support for Belgium", "summary": """ This module adds Belgium-specific support to account_payment_order.""", - "version": "16.0.1.0.0", + "version": "16.0.1.0.2", "license": "AGPL-3", "author": "ACSONE SA/NV,Odoo Community Association (OCA)", "website": "https://github.com/OCA/l10n-belgium", diff --git a/l10n_be_iso20022_pain/migrations/16.0.1.0.2/pre-migrate.py b/l10n_be_iso20022_pain/migrations/16.0.1.0.2/pre-migrate.py new file mode 100644 index 00000000..35c21483 --- /dev/null +++ b/l10n_be_iso20022_pain/migrations/16.0.1.0.2/pre-migrate.py @@ -0,0 +1,12 @@ +# Copyright 2024 ACSONE SA/NV + + +def migrate(cr, version): + cr.execute( + "UPDATE account_move SET reference_type='structured' " + "WHERE reference_type='bba'" + ) + cr.execute( + "UPDATE account_payment_line SET communication_type='structured' " + "WHERE communication_type='bba'" + ) diff --git a/l10n_be_iso20022_pain/models/account_move.py b/l10n_be_iso20022_pain/models/account_move.py index 1829a03d..4e6d394c 100644 --- a/l10n_be_iso20022_pain/models/account_move.py +++ b/l10n_be_iso20022_pain/models/account_move.py @@ -3,8 +3,7 @@ import re -from odoo import _, api, fields, models -from odoo.exceptions import UserError +from odoo import api, models def check_bbacomm(val): @@ -24,47 +23,18 @@ def check_bbacomm(val): class AccountMove(models.Model): _inherit = "account.move" - reference_type = fields.Selection( - selection_add=[("bba", "BBA Structured Communication")], - ondelete={"bba": "set default"}, - ) - @api.constrains("reference_type", "ref") def _check_communication(self): for rec in self: - if rec.reference_type == "bba": + if ( + rec.journal_id.invoice_reference_model == "be" + and rec.journal_id.invoice_reference_type == "invoice" + and rec.reference_type == "structured" + ): return check_bbacomm(rec.ref) - return True - - @api.model - def _update_reference_vals(self, vals): - reference = vals.get("ref", False) - reference_type = vals.get("reference_type", False) - if reference_type == "bba": - if not reference: - raise UserError( - _( - "Empty BBA Structured Communication! " - "Please fill in a unique BBA Structured Communication." - ) - ) - reference = re.sub(r"\D", "", reference) - vals["ref"] = ( - "+++" - + reference[0:3] - + "/" - + reference[3:7] - + "/" - + reference[7:] - + "+++" - ) - - @api.model_create_multi - def create(self, vals_list): - for vals in vals_list: - self._update_reference_vals(vals) - return super().create(vals_list) - def write(self, vals): - self._update_reference_vals(vals) - return super().write(vals) + def _get_invoice_reference_be_invoice(self): + self.ensure_one() + if self.reference_type == "none": + return "" + return super()._get_invoice_reference_be_invoice() diff --git a/l10n_be_iso20022_pain/models/account_move_line.py b/l10n_be_iso20022_pain/models/account_move_line.py index cd69051d..bb73d278 100644 --- a/l10n_be_iso20022_pain/models/account_move_line.py +++ b/l10n_be_iso20022_pain/models/account_move_line.py @@ -7,10 +7,9 @@ class AccountMoveLine(models.Model): _inherit = "account.move.line" - def _prepare_payment_line_vals(self, payment_order): + def _get_communication(self): self.ensure_one() - vals = super()._prepare_payment_line_vals(payment_order) - communication_type = self.move_id.reference_type - if "communication" in vals and communication_type == "bba": - vals["communication"] = self.move_id.ref.replace("+", "").replace("/", "") - return vals + communication_type, communication = super()._get_communication() + if self.move_id.reference_type == "structured": + communication = communication.replace("+", "").replace("/", "") + return communication_type, communication diff --git a/l10n_be_iso20022_pain/models/account_payment_line.py b/l10n_be_iso20022_pain/models/account_payment_line.py index 92a77bb8..e96ab90c 100644 --- a/l10n_be_iso20022_pain/models/account_payment_line.py +++ b/l10n_be_iso20022_pain/models/account_payment_line.py @@ -1,7 +1,7 @@ # Copyright 2017 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import _, api, fields, models +from odoo import _, api, models from odoo.exceptions import ValidationError from .account_move import check_bbacomm @@ -10,18 +10,10 @@ class AccountPaymentLine(models.Model): _inherit = "account.payment.line" - communication_type = fields.Selection( - selection_add=[("bba", _("BBA Structured Communication"))], - ondelete={"bba": "set default"}, - ) - @api.constrains("communication", "communication_type") def _check_communication(self): for rec in self: - if rec.communication_type == "bba" and not check_bbacomm(rec.communication): + if rec.communication_type == "structured" and not check_bbacomm( + rec.communication + ): raise ValidationError(_("Invalid BBA Structured Communication !")) - - def invoice_reference_type2communication_type(self): - res = super().invoice_reference_type2communication_type() - res["bba"] = "bba" - return res 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 33a1f477..0a0ef966 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 @@ -45,7 +45,7 @@ def setUpClass(cls): }, ) ], - "reference_type": "bba", + "reference_type": "structured", "ref": "+++868/0542/73023+++", "payment_mode_id": cls.payment_mode.id, } @@ -55,8 +55,8 @@ def _prepare_payment_line_creation_dict(self): return { "currency_id": self.env.ref("base.EUR").id, "partner_id": self.env.ref("base.res_partner_2").id, - "communication_type": "bba", "amount_currency": 123.321, + "communication_type": "structured", } def test_create_account_payment_line_01(self):