Files
odoo_source/addons/l10n_ch/tests/test_gen_isr_reference.py
T
Shawcker 37609c7e83 [IMP] account: improve display of invoices/bills in list view
Canceled and draft entries are the same color as posted entries. They should be in a different color (grey/blue) in order to be distinguished from other invoices/bills.

Amount Due, a.k.a. amount_residual(_signed), is not 0 for draft and canceled entries. It should be 0 since they haven't been posted yet.

A few tests have to be adapted to reflect this change in spec.

Task=2801521

closes odoo/odoo#88295

X-original-commit: 498a4a52b5fbc5466d8d0652db10563ccba55032
Related: odoo/upgrade#3435
Signed-off-by: Laurent Smet <las@odoo.com>
2022-04-27 13:26:50 +02:00

114 lines
4.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 tagged
QR_IBAN = 'CH21 3080 8001 2345 6782 7'
ISR_SUBS_NUMBER = "01-162-8"
@tagged('post_install_l10n', 'post_install', '-at_install')
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"
# Post invoice to have the expected amount due (amount_residual)
self.invoice.action_post()
expected_isr = "000000000000000012345678903"
expected_isr_spaced = "00 00000 00000 00001 23456 78903"
expected_optical_line = "0100001307807>000000000000000012345678903+ 010001628>"
self.assertEqual(self.invoice.l10n_ch_isr_number, expected_isr)
self.assertEqual(self.invoice.l10n_ch_isr_number_spaced, expected_isr_spaced)
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"
expected_isr_spaced = "00 00000 00000 00001 23456 78903"
self.assertEqual(self.invoice.l10n_ch_isr_number, expected_isr)
self.assertEqual(self.invoice.l10n_ch_isr_number_spaced, expected_isr_spaced)
# 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"
# Post invoice to have the expected amount due (amount_residual)
self.invoice.action_post()
expected_isr = "567890123456789012345678901"
expected_isr_spaced = "56 78901 23456 78901 23456 78901"
expected_optical_line = "0100001307807>567890123456789012345678901+ 010001628>"
self.assertEqual(self.invoice.l10n_ch_isr_number, expected_isr)
self.assertEqual(self.invoice.l10n_ch_isr_number_spaced, expected_isr_spaced)
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_number_spaced)
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_number_spaced)
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_number_spaced)
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_number_spaced)
self.assertFalse(self.invoice.l10n_ch_isr_optical_line)