Skip to content

Commit

Permalink
[IMP] l10n_be_iso20022_pain: check BBA structured communication on pa…
Browse files Browse the repository at this point in the history
…yment line

check BBA structured communication on payment line only if  the journal invoice reference model is "be"

Co-authored-by: Thomas Binsfeld (ACSONE) <[email protected]>
  • Loading branch information
sbejaoui and ThomasBinsfeld committed Jul 15, 2024
1 parent f65c848 commit f6a8c8f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
3 changes: 2 additions & 1 deletion l10n_be_iso20022_pain/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
}
9 changes: 6 additions & 3 deletions l10n_be_iso20022_pain/models/account_payment_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 !"))
40 changes: 40 additions & 0 deletions l10n_be_iso20022_pain/tests/test_l10n_be_iso20022_pain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -50,13 +52,21 @@ 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 {
"currency_id": self.env.ref("base.EUR").id,
"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):
Expand Down Expand Up @@ -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)
21 changes: 21 additions & 0 deletions l10n_be_iso20022_pain/views/account_journal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 ACSONE SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="account_journal_form_view">
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='invoice_reference_type']/parent::group"
position="attributes"
>
<attribute name="invisible">type not in ('sale', 'bank')</attribute>
</xpath>
</field>
</record>



</odoo>

0 comments on commit f6a8c8f

Please sign in to comment.