Files
odoo_source/addons/l10n_ch/tests/test_gen_isr_reference.py
T
Yannick Vaucher 2af6b7dcf6 [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#58398

X-original-commit: 4790b8e57aa357cda32818392d795b8c0dc48f43
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
2020-09-24 09:56:14 +00:00

99 lines
3.7 KiB
Python

# -*- 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)