summaryrefslogtreecommitdiff
path: root/addons/account_qr_code_sepa/tests
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/account_qr_code_sepa/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/account_qr_code_sepa/tests')
-rw-r--r--addons/account_qr_code_sepa/tests/__init__.py3
-rw-r--r--addons/account_qr_code_sepa/tests/test_sepa_qr.py63
2 files changed, 66 insertions, 0 deletions
diff --git a/addons/account_qr_code_sepa/tests/__init__.py b/addons/account_qr_code_sepa/tests/__init__.py
new file mode 100644
index 00000000..b570597d
--- /dev/null
+++ b/addons/account_qr_code_sepa/tests/__init__.py
@@ -0,0 +1,3 @@
+# *-* coding:utf-8 *-*
+
+from . import test_sepa_qr \ No newline at end of file
diff --git a/addons/account_qr_code_sepa/tests/test_sepa_qr.py b/addons/account_qr_code_sepa/tests/test_sepa_qr.py
new file mode 100644
index 00000000..cf8d4280
--- /dev/null
+++ b/addons/account_qr_code_sepa/tests/test_sepa_qr.py
@@ -0,0 +1,63 @@
+# -*- coding:utf-8 -*-
+
+from odoo.exceptions import UserError
+from odoo.addons.account.tests.common import AccountTestInvoicingCommon
+
+
+class TestSEPAQRCode(AccountTestInvoicingCommon):
+ """ Tests the generation of Swiss QR-codes on invoices
+ """
+
+ @classmethod
+ def setUpClass(cls, chart_template_ref=None):
+ super().setUpClass(chart_template_ref=chart_template_ref)
+
+ cls.company_data['company'].qr_code = True
+ cls.acc_sepa_iban = cls.env['res.partner.bank'].create({
+ 'acc_number': 'BE15001559627230',
+ 'partner_id': cls.company_data['company'].partner_id.id,
+ })
+
+ cls.acc_non_sepa_iban = cls.env['res.partner.bank'].create({
+ 'acc_number': 'SA4420000001234567891234',
+ 'partner_id': cls.company_data['company'].partner_id.id,
+ })
+
+ cls.sepa_qr_invoice = cls.env['account.move'].create({
+ 'move_type': 'out_invoice',
+ 'partner_id': cls.partner_a.id,
+ 'currency_id': cls.env.ref('base.EUR').id,
+ 'partner_bank_id': cls.acc_sepa_iban.id,
+ 'company_id': cls.company_data['company'].id,
+ 'invoice_line_ids': [
+ (0, 0, {'quantity': 1, 'price_unit': 100})
+ ],
+ })
+
+ def test_sepa_qr_code_generation(self):
+ """ Check different cases of SEPA QR-code generation, when qr_method is
+ specified beforehand.
+ """
+ self.sepa_qr_invoice.qr_code_method = 'sct_qr'
+
+ # Using a SEPA IBAN should work
+ self.sepa_qr_invoice.generate_qr_code()
+
+ # Using a non-SEPA IBAN shouldn't
+ self.sepa_qr_invoice.partner_bank_id = self.acc_non_sepa_iban
+ with self.assertRaises(UserError, msg="It shouldn't be possible to generate a SEPA QR-code for IBAN of countries outside SEPA zone."):
+ self.sepa_qr_invoice.generate_qr_code()
+
+ # Changing the currency should break it as well
+ self.sepa_qr_invoice.partner_bank_id = self.acc_sepa_iban
+ self.sepa_qr_invoice.currency_id = self.env.ref('base.USD').id
+ with self.assertRaises(UserError, msg="It shouldn't be possible to generate a SEPA QR-code for another currency as EUR."):
+ self.sepa_qr_invoice.generate_qr_code()
+
+ def test_sepa_qr_code_detection(self):
+ """ Checks SEPA QR-code auto-detection when no specific QR-method
+ is given to the invoice.
+ """
+ self.sepa_qr_invoice.generate_qr_code()
+ self.assertEqual(self.sepa_qr_invoice.qr_code_method, 'sct_qr', "SEPA QR-code generator should have been chosen for this invoice.")
+