summaryrefslogtreecommitdiff
path: root/addons/l10n_ch/tests/test_l10n_ch_isr_print.py
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/l10n_ch/tests/test_l10n_ch_isr_print.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/l10n_ch/tests/test_l10n_ch_isr_print.py')
-rw-r--r--addons/l10n_ch/tests/test_l10n_ch_isr_print.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/addons/l10n_ch/tests/test_l10n_ch_isr_print.py b/addons/l10n_ch/tests/test_l10n_ch_isr_print.py
new file mode 100644
index 00000000..9bdba9b7
--- /dev/null
+++ b/addons/l10n_ch/tests/test_l10n_ch_isr_print.py
@@ -0,0 +1,67 @@
+# -*- 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 tagged
+from odoo.exceptions import ValidationError
+
+
+@tagged('post_install', '-at_install')
+class ISRTest(AccountTestInvoicingCommon):
+
+ @classmethod
+ def setUpClass(cls, chart_template_ref='l10n_ch.l10nch_chart_template'):
+ super().setUpClass(chart_template_ref=chart_template_ref)
+
+ def print_isr(self, invoice):
+ try:
+ invoice.isr_print()
+ return True
+ except ValidationError:
+ return False
+
+ def test_l10n_ch_postals(self):
+
+ def assertBankAccountValid(account_number, expected_account_type, expected_postal=None):
+ partner_bank = self.env['res.partner.bank'].create({
+ 'acc_number': account_number,
+ 'partner_id': self.partner_a.id,
+ })
+ expected_vals = {'acc_type': expected_account_type}
+ if expected_postal is not None:
+ expected_vals['l10n_ch_postal'] = expected_postal
+
+ self.assertRecordValues(partner_bank, [expected_vals])
+
+ assertBankAccountValid('010391391', 'postal', expected_postal='010391391')
+ assertBankAccountValid('010391394', 'bank')
+ assertBankAccountValid('CH6309000000250097798', 'iban', expected_postal='25-9779-8')
+ assertBankAccountValid('GR1601101250000000012300695', 'iban', expected_postal=False)
+
+ def test_isr(self):
+ isr_bank_account = self.env['res.partner.bank'].create({
+ 'acc_number': "ISR {} number",
+ 'partner_id': self.env.company.partner_id.id,
+ 'l10n_ch_isr_subscription_chf': '01-39139-1',
+ })
+
+ invoice_chf = self.env['account.move'].create({
+ 'move_type': 'out_invoice',
+ 'partner_id': self.partner_a.id,
+ 'partner_bank_id': isr_bank_account.id,
+ 'currency_id': self.env.ref('base.CHF').id,
+ 'invoice_date': '2019-01-01',
+ 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id})],
+ })
+ invoice_chf.action_post()
+ self.assertTrue(self.print_isr(invoice_chf))
+
+ invoice_eur = self.env['account.move'].create({
+ 'move_type': 'out_invoice',
+ 'partner_id': self.partner_a.id,
+ 'partner_bank_id': isr_bank_account.id,
+ 'currency_id': self.env.ref('base.EUR').id,
+ 'invoice_date': '2019-01-01',
+ 'invoice_line_ids': [(0, 0, {'product_id': self.product_a.id})],
+ })
+ invoice_eur.action_post()
+ self.assertFalse(self.print_isr(invoice_eur))