Skip to content

Commit

Permalink
[IMP] remove bba option from communication_type on payment line
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Jul 9, 2024
1 parent d2ebb70 commit f65c848
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 62 deletions.
2 changes: 1 addition & 1 deletion l10n_be_iso20022_pain/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions l10n_be_iso20022_pain/migrations/16.0.1.0.2/pre-migrate.py
Original file line number Diff line number Diff line change
@@ -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'"
)
52 changes: 11 additions & 41 deletions l10n_be_iso20022_pain/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
11 changes: 5 additions & 6 deletions l10n_be_iso20022_pain/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 4 additions & 12 deletions l10n_be_iso20022_pain/models/account_payment_line.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions l10n_be_iso20022_pain/tests/test_l10n_be_iso20022_pain.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def setUpClass(cls):
},
)
],
"reference_type": "bba",
"reference_type": "structured",
"ref": "+++868/0542/73023+++",
"payment_mode_id": cls.payment_mode.id,
}
Expand All @@ -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):
Expand Down

0 comments on commit f65c848

Please sign in to comment.