summaryrefslogtreecommitdiff
path: root/addons/l10n_ch/tests
diff options
context:
space:
mode:
authorYannick Vaucher <yannick.vaucher@camptocamp.com>2020-05-21 00:08:11 +0000
committeroco-odoo <oco@odoo.com>2020-09-24 09:31:24 +0000
commit37d75ecbce3f77c159db12c0247e053b873c685a (patch)
treef3c01cd15d743709528652c6d9b7faacdc73169d /addons/l10n_ch/tests
parentbacc0b0922f958c09287aebab3facda1ca9ef7a1 (diff)
[REF] l10n_ch ISR number computation
Add hooks to be able to tweak the Bank customer ID number for ISR-B Those hooks will allow to not use of the field l10n_ch_postal for multiple purposes. Fixes conditions on which the reference is generated. It shouldn't be always generated if l10n_ch_postal is set. Only if a l10n_ch_subscription_xxx is set. closes odoo/odoo#58393 X-original-commit: 4790b8e57aa357cda32818392d795b8c0dc48f43 Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com> Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
Diffstat (limited to 'addons/l10n_ch/tests')
-rw-r--r--addons/l10n_ch/tests/__init__.py1
-rw-r--r--addons/l10n_ch/tests/test_gen_isr_reference.py98
2 files changed, 99 insertions, 0 deletions
diff --git a/addons/l10n_ch/tests/__init__.py b/addons/l10n_ch/tests/__init__.py
index 65de010232a..e9792e787e3 100644
--- a/addons/l10n_ch/tests/__init__.py
+++ b/addons/l10n_ch/tests/__init__.py
@@ -6,3 +6,4 @@ from . import test_swissqr
from . import test_l10n_ch_isr_print
from . import test_vendor_bill_isr
from . import test_onchange_l10n_ch_postal
+from . import test_gen_isr_reference
diff --git a/addons/l10n_ch/tests/test_gen_isr_reference.py b/addons/l10n_ch/tests/test_gen_isr_reference.py
new file mode 100644
index 00000000000..6d8a75dd083
--- /dev/null
+++ b/addons/l10n_ch/tests/test_gen_isr_reference.py
@@ -0,0 +1,98 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.addons.account.tests.common import AccountTestInvoicingCommon
+from odoo.tests import common, Form
+
+QR_IBAN = 'CH21 3080 8001 2345 6782 7'
+ISR_SUBS_NUMBER = "01-162-8"
+
+
+class TestGenISRReference(AccountTestInvoicingCommon):
+ """Check condition of generation of and content of the structured ref"""
+
+ @classmethod
+ def setUpClass(cls, chart_template_ref="l10n_ch.l10nch_chart_template"):
+ super().setUpClass(chart_template_ref=chart_template_ref)
+ cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
+ cls.bank = cls.env["res.bank"].create(
+ {
+ "name": "Alternative Bank Schweiz AG",
+ "bic": "ALSWCH21XXX",
+ }
+ )
+ cls.bank_acc_isr = cls.env["res.partner.bank"].create(
+ {
+ "acc_number": "ISR",
+ "l10n_ch_isr_subscription_chf": "01-162-8",
+ "bank_id": cls.bank.id,
+ "partner_id": cls.partner_a.id,
+ }
+ )
+ cls.bank_acc_qriban = cls.env["res.partner.bank"].create(
+ {
+ "acc_number": QR_IBAN,
+ "bank_id": cls.bank.id,
+ "partner_id": cls.partner_a.id,
+ }
+ )
+ cls.invoice = cls.init_invoice("out_invoice", products=cls.product_a+cls.product_b)
+
+ def test_isr(self):
+
+ self.invoice.partner_bank_id = self.bank_acc_isr
+ self.invoice.name = "INV/01234567890"
+
+ expected_isr = "000000000000000012345678903"
+ expected_optical_line = "0100001307807>000000000000000012345678903+ 010001628>"
+ self.assertEqual(self.invoice.l10n_ch_isr_number, expected_isr)
+ self.assertEqual(self.invoice.l10n_ch_isr_optical_line, expected_optical_line)
+
+ def test_qrr(self):
+ self.invoice.partner_bank_id = self.bank_acc_qriban
+
+ self.invoice.name = "INV/01234567890"
+
+ expected_isr = "000000000000000012345678903"
+ self.assertEqual(self.invoice.l10n_ch_isr_number, expected_isr)
+ # No need to check optical line, we have no use for it with QR-bill
+
+ def test_isr_long_reference(self):
+ self.invoice.partner_bank_id = self.bank_acc_isr
+
+ self.invoice.name = "INV/123456789012345678901234567890"
+
+ expected_isr = "567890123456789012345678901"
+ expected_optical_line = "0100001307807>567890123456789012345678901+ 010001628>"
+ self.assertEqual(self.invoice.l10n_ch_isr_number, expected_isr)
+ self.assertEqual(self.invoice.l10n_ch_isr_optical_line, expected_optical_line)
+
+ def test_missing_isr_subscription_num(self):
+ self.bank_acc_isr.l10n_ch_isr_subscription_chf = False
+
+ self.invoice.partner_bank_id = self.bank_acc_isr
+
+ self.assertFalse(self.invoice.l10n_ch_isr_number)
+ self.assertFalse(self.invoice.l10n_ch_isr_optical_line)
+
+ def test_missing_isr_subscription_num_in_wrong_field(self):
+ self.bank_acc_isr.l10n_ch_isr_subscription_chf = False
+ self.bank_acc_isr.l10n_ch_postal = ISR_SUBS_NUMBER
+
+ self.invoice.partner_bank_id = self.bank_acc_isr
+
+ self.assertFalse(self.invoice.l10n_ch_isr_number)
+ self.assertFalse(self.invoice.l10n_ch_isr_optical_line)
+
+ def test_no_bank_account(self):
+ self.invoice.partner_bank_id = False
+
+ self.assertFalse(self.invoice.l10n_ch_isr_number)
+ self.assertFalse(self.invoice.l10n_ch_isr_optical_line)
+
+ def test_wrong_currency(self):
+ self.invoice.partner_bank_id = self.bank_acc_isr
+ self.invoice.currency_id = self.env.ref("base.BTN")
+
+ self.assertFalse(self.invoice.l10n_ch_isr_number)
+ self.assertFalse(self.invoice.l10n_ch_isr_optical_line)