mirror of
https://github.com/bringout/oca-ocb-l10n_europe.git
synced 2026-04-27 00:02:00 +02:00
19.0 vanilla
This commit is contained in:
parent
ff721d030e
commit
7721452493
1826 changed files with 124775 additions and 274114 deletions
|
|
@ -3,8 +3,5 @@
|
|||
|
||||
from . import test_ch_qr_code
|
||||
from . import test_swissqr
|
||||
from . import test_l10n_ch_isr_print
|
||||
from . import test_l10n_ch_qr_print
|
||||
from . import test_vendor_bill_isr
|
||||
from . import test_onchange_l10n_ch_postal
|
||||
from . import test_gen_isr_reference
|
||||
from . import test_gen_qrr_reference
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
|
||||
from reportlab.graphics.barcode import createBarcodeDrawing
|
||||
|
||||
from odoo import Command
|
||||
from odoo.tests import tagged
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools.barcode import createBarcodeDrawing
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
|
||||
|
||||
|
|
@ -14,11 +11,11 @@ class TestSwissQRCode(AccountTestInvoicingCommon):
|
|||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref='l10n_ch.l10nch_chart_template'):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
@AccountTestInvoicingCommon.setup_country('ch')
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
cls.company_data['company'].qr_code = True
|
||||
cls.company_data['company'].country_id = None
|
||||
|
||||
cls.swiss_iban = cls.env['res.partner.bank'].create({
|
||||
'acc_number': 'CH15 3881 5158 3845 3843 7',
|
||||
|
|
@ -60,6 +57,9 @@ class TestSwissQRCode(AccountTestInvoicingCommon):
|
|||
"""
|
||||
self.ch_qr_invoice.qr_code_method = 'ch_qr'
|
||||
|
||||
# flush manually to have the right env to get possible values of `qr_code_method`
|
||||
self.env.flush_all()
|
||||
|
||||
# First check with a regular IBAN
|
||||
with self.assertRaises(UserError, msg="It shouldn't be possible to generate a Swiss QR-code for partners without a complete Swiss address."):
|
||||
self.ch_qr_invoice._generate_qr_code()
|
||||
|
|
@ -83,6 +83,24 @@ class TestSwissQRCode(AccountTestInvoicingCommon):
|
|||
self.ch_qr_invoice.company_id.partner_id.country_id = self.env.ref('base.fr')
|
||||
self.ch_qr_invoice._generate_qr_code()
|
||||
|
||||
def test_qr_code_generation_with_newlines(self):
|
||||
""" Check that the generated QR removes newlines from field content, as newlines
|
||||
shift the field content causing the submitted QR code to be rejected.
|
||||
"""
|
||||
# add the address with a newline
|
||||
self._assign_partner_address(self.ch_qr_invoice.company_id.partner_id)
|
||||
self._assign_partner_address(self.ch_qr_invoice.partner_id)
|
||||
self.ch_qr_invoice.partner_id.write({"street2": "123 \nStreet"})
|
||||
|
||||
# generate the field values, instead of the QR image.
|
||||
unstruct_ref = self.ch_qr_invoice.ref and self.ch_qr_invoice.ref or self.ch_qr_invoice.name
|
||||
vals = self.ch_qr_invoice.partner_bank_id._build_qr_code_vals(
|
||||
self.ch_qr_invoice.amount_residual, unstruct_ref, self.ch_qr_invoice.payment_reference,
|
||||
self.ch_qr_invoice.currency_id, self.ch_qr_invoice.partner_id, self.ch_qr_invoice.qr_code_method)
|
||||
value_list = self.ch_qr_invoice.partner_bank_id._get_qr_vals(**vals)
|
||||
|
||||
self.assertEqual(''.join(value_list).count('\n'), 0, "Each element of the Swiss QR-code must be contained on one line.")
|
||||
|
||||
def test_ch_qr_code_detection(self):
|
||||
""" Checks Swiss QR-code auto-detection when no specific QR-method
|
||||
is given to the invoice.
|
||||
|
|
|
|||
|
|
@ -1,114 +0,0 @@
|
|||
# -*- 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.product_a.taxes_id = cls.product_b.taxes_id = None
|
||||
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 = "0100001297203>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 = "0100001297203>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)
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import Command
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
from odoo.tests import tagged
|
||||
|
||||
QR_IBAN = 'CH21 3080 8001 2345 6782 7'
|
||||
|
||||
|
||||
@tagged('post_install_l10n', 'post_install', '-at_install')
|
||||
class TestGenQRRReference(AccountTestInvoicingCommon):
|
||||
"""Check condition of generation of and content of the structured ref"""
|
||||
|
||||
@classmethod
|
||||
@AccountTestInvoicingCommon.setup_country('ch')
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.bank = cls.env["res.bank"].create(
|
||||
{
|
||||
"name": "Alternative Bank Schweiz AG",
|
||||
"bic": "ALSWCH21XXX",
|
||||
}
|
||||
)
|
||||
cls.partner = cls.env['res.partner'].create({
|
||||
'name': 'Bobby',
|
||||
'country_id': cls.env.ref('base.ch').id,
|
||||
})
|
||||
cls.bank_acc_qriban = cls.env["res.partner.bank"].create(
|
||||
{
|
||||
"acc_number": QR_IBAN,
|
||||
"bank_id": cls.bank.id,
|
||||
"partner_id": cls.partner.id,
|
||||
}
|
||||
)
|
||||
cls.qr_bank_account = cls.env['res.partner.bank'].create({
|
||||
'acc_number': "CH4431999123000889012",
|
||||
'partner_id': cls.partner.id,
|
||||
})
|
||||
|
||||
cls.invoice = cls.init_invoice("out_invoice", products=cls.product_a+cls.product_b)
|
||||
|
||||
def test_qrr(self):
|
||||
test_invoice = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner.id,
|
||||
'partner_bank_id': self.bank_acc_qriban.id,
|
||||
'currency_id': self.env.ref('base.EUR').id,
|
||||
'invoice_date': '2019-01-01',
|
||||
'invoice_line_ids': [Command.create({'product_id': self.product_a.id})],
|
||||
})
|
||||
test_invoice.name = "INV/01234567890"
|
||||
expected_qrr = "000000000000000012345678903"
|
||||
self.assertEqual(test_invoice.get_l10n_ch_qrr_number(), expected_qrr)
|
||||
|
||||
def test_qrr_long_reference(self):
|
||||
test_invoice = self.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
'partner_id': self.partner.id,
|
||||
'partner_bank_id': self.bank_acc_qriban.id,
|
||||
'currency_id': self.env.ref('base.EUR').id,
|
||||
'invoice_date': '2019-01-01',
|
||||
'invoice_line_ids': [Command.create({'product_id': self.product_a.id})],
|
||||
})
|
||||
test_invoice.name = "INV/123456789012345678901234567890"
|
||||
expected_qrr = "567890123456789012345678901"
|
||||
self.assertEqual(test_invoice.get_l10n_ch_qrr_number(), expected_qrr)
|
||||
|
||||
def test_no_bank_account(self):
|
||||
self.invoice.partner_bank_id = False
|
||||
self.assertFalse(self.invoice.get_l10n_ch_qrr_number())
|
||||
|
||||
def test_wrong_currency(self):
|
||||
self.invoice.partner_bank_id = self.bank_acc_qriban
|
||||
self.invoice.currency_id = self.env.ref("base.BTN")
|
||||
self.assertFalse(self.invoice.get_l10n_ch_qrr_number())
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
# -*- 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_l10n', '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.action_invoice_sent()
|
||||
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('CH6309000000250097798', 'iban', expected_postal='25-9779-8')
|
||||
assertBankAccountValid('GR1601101250000000012300695', 'iban', expected_postal=False)
|
||||
|
||||
partner_bank = self.env['res.partner.bank'].create({
|
||||
'acc_number': '010391394',
|
||||
'partner_id': self.partner_a.id,
|
||||
})
|
||||
self.assertNotEqual(partner_bank.acc_type, 'postal')
|
||||
|
||||
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))
|
||||
self.env.ref('base.EUR').active = True
|
||||
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()
|
||||
#a normal invoice will still get printed
|
||||
self.assertTrue(self.print_isr(invoice_eur))
|
||||
# However, a isr bill can't be printed with those infos
|
||||
self.assertFalse(invoice_eur.l10n_ch_isr_valid)
|
||||
|
|
@ -12,8 +12,9 @@ _logger = logging.getLogger(__name__)
|
|||
class QRPrintTest(AccountTestInvoicingCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref='l10n_ch.l10nch_chart_template'):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
@AccountTestInvoicingCommon.setup_country('ch')
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
# the partner must be located in Switzerland.
|
||||
cls.partner = cls.env['res.partner'].create({
|
||||
'name': 'Bobby',
|
||||
|
|
@ -23,7 +24,7 @@ class QRPrintTest(AccountTestInvoicingCommon):
|
|||
cls.qr_bank_account = cls.env['res.partner.bank'].create({
|
||||
'acc_number': "CH4431999123000889012",
|
||||
'partner_id': cls.env.company.partner_id.id,
|
||||
'l10n_ch_isr_subscription_chf': '01-39139-1',
|
||||
'allow_out_payment': True,
|
||||
})
|
||||
cls.correct_invoice_chf = cls.env['account.move'].create({
|
||||
'move_type': 'out_invoice',
|
||||
|
|
@ -57,7 +58,7 @@ class QRPrintTest(AccountTestInvoicingCommon):
|
|||
invoice.action_invoice_sent()
|
||||
return True
|
||||
except UserError as e:
|
||||
_logger.warning(e.name)
|
||||
_logger.warning(str(e))
|
||||
return False
|
||||
|
||||
def test_print_qr(self):
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests.common import Form, TransactionCase
|
||||
|
||||
|
||||
CH_ISR_ISSUER = '01-162-8'
|
||||
CH_IBAN = 'CH15 3881 5158 3845 3843 7'
|
||||
FR_IBAN = 'FR83 8723 4133 8709 9079 4002 530'
|
||||
CH_POST_IBAN = 'CH09 0900 0000 1000 8060 7'
|
||||
CH_POSTAL_ACC = '10-8060-7'
|
||||
|
||||
|
||||
@tagged('post_install_l10n', 'post_install', '-at_install')
|
||||
class TestOnchangePostal(TransactionCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||
|
||||
cls.partner = cls.env['res.partner'].create({
|
||||
'name': 'Swiss Company',
|
||||
'street': 'Route de Berne 41',
|
||||
'zip': '1000',
|
||||
'city': 'Lausanne',
|
||||
'is_company': 1,
|
||||
'country_id': cls.env.ref('base.ch').id,
|
||||
})
|
||||
cls.ch_bank = cls.env['res.bank'].create({
|
||||
'name': 'Alternative Bank Schweiz AG',
|
||||
'bic': 'ALSWCH21XXX',
|
||||
})
|
||||
cls.post_bank = cls.env['res.bank'].search(
|
||||
[('bic', '=', 'POFICHBEXXX')])
|
||||
if not cls.post_bank:
|
||||
cls.post_bank = cls.env['res.bank'].create({
|
||||
'name': 'PostFinance AG',
|
||||
'bic': 'POFICHBEXXX',
|
||||
})
|
||||
|
||||
def new_partner_bank_form(self):
|
||||
form = Form(
|
||||
self.env['res.partner.bank'],
|
||||
view="l10n_ch.isr_partner_bank_form",
|
||||
)
|
||||
form.partner_id = self.partner
|
||||
return form
|
||||
|
||||
def test_onchange_acc_number_isr_issuer(self):
|
||||
"""The user entered ISR issuer number into acc_number
|
||||
|
||||
We detect and move it to l10n_ch_postal.
|
||||
It must be moved as it is not unique.
|
||||
"""
|
||||
bank_acc = self.new_partner_bank_form()
|
||||
bank_acc.acc_number = CH_ISR_ISSUER
|
||||
account = bank_acc.save()
|
||||
|
||||
self.assertEqual(
|
||||
account.acc_number,
|
||||
"{} {}".format(CH_ISR_ISSUER, self.partner.name)
|
||||
)
|
||||
self.assertEqual(account.l10n_ch_postal, CH_ISR_ISSUER)
|
||||
self.assertEqual(account.acc_type, 'postal')
|
||||
|
||||
def test_onchange_acc_number_postal(self):
|
||||
"""The user entered postal number into acc_number
|
||||
|
||||
We detect and copy it to l10n_ch_postal.
|
||||
"""
|
||||
bank_acc = self.new_partner_bank_form()
|
||||
bank_acc.acc_number = CH_POSTAL_ACC
|
||||
account = bank_acc.save()
|
||||
|
||||
self.assertEqual(account.acc_number, CH_POSTAL_ACC)
|
||||
self.assertEqual(account.l10n_ch_postal, CH_POSTAL_ACC)
|
||||
self.assertEqual(account.acc_type, 'postal')
|
||||
|
||||
def test_onchange_acc_number_iban_ch(self):
|
||||
bank_acc = self.new_partner_bank_form()
|
||||
bank_acc.acc_number = CH_IBAN
|
||||
account = bank_acc.save()
|
||||
|
||||
self.assertEqual(account.acc_number, CH_IBAN)
|
||||
self.assertFalse(account.l10n_ch_postal)
|
||||
self.assertEqual(account.acc_type, 'iban')
|
||||
|
||||
def test_onchange_acc_number_iban_ch_postfinance(self):
|
||||
"""The user enter a postal IBAN, postal number can be deduced"""
|
||||
bank_acc = self.new_partner_bank_form()
|
||||
bank_acc.acc_number = CH_POST_IBAN
|
||||
account = bank_acc.save()
|
||||
|
||||
self.assertEqual(account.acc_number, CH_POST_IBAN)
|
||||
self.assertEqual(account.l10n_ch_postal, CH_POSTAL_ACC)
|
||||
self.assertEqual(account.acc_type, 'iban')
|
||||
|
||||
def test_onchange_acc_number_iban_foreign(self):
|
||||
"""Check IBAN still works changed"""
|
||||
bank_acc = self.new_partner_bank_form()
|
||||
bank_acc.acc_number = FR_IBAN
|
||||
account = bank_acc.save()
|
||||
|
||||
self.assertEqual(account.acc_number, FR_IBAN)
|
||||
self.assertFalse(account.l10n_ch_postal)
|
||||
self.assertEqual(account.acc_type, 'iban')
|
||||
|
||||
def test_onchange_acc_number_none(self):
|
||||
"""Check misc format still works"""
|
||||
bank_acc = self.new_partner_bank_form()
|
||||
bank_acc.acc_number = 'anything'
|
||||
account = bank_acc.save()
|
||||
|
||||
self.assertEqual(account.acc_number, 'anything')
|
||||
self.assertFalse(account.l10n_ch_postal)
|
||||
self.assertEqual(account.acc_type, 'bank')
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
import time
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools.misc import mod10r
|
||||
|
||||
|
|
@ -15,8 +14,9 @@ QR_IBAN = 'CH21 3080 8001 2345 6782 7'
|
|||
class TestSwissQR(AccountTestInvoicingCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref='l10n_ch.l10nch_chart_template'):
|
||||
super().setUpClass(chart_template_ref=chart_template_ref)
|
||||
@AccountTestInvoicingCommon.setup_country('ch')
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
def setUp(self):
|
||||
super(TestSwissQR, self).setUp()
|
||||
|
|
@ -89,21 +89,22 @@ class TestSwissQR(AccountTestInvoicingCommon):
|
|||
{
|
||||
'acc_number': number,
|
||||
'partner_id': self.env.user.company_id.partner_id.id,
|
||||
'allow_out_payment': True,
|
||||
}
|
||||
)
|
||||
|
||||
def swissqr_not_generated(self, invoice):
|
||||
""" Prints the given invoice and tests that no Swiss QR generation is triggered. """
|
||||
self.assertFalse(
|
||||
invoice.partner_bank_id._eligible_for_qr_code('ch_qr', invoice.partner_id, invoice.currency_id),
|
||||
self.assertTrue(
|
||||
invoice.partner_bank_id._get_error_messages_for_qr('ch_qr', invoice.partner_id, invoice.currency_id),
|
||||
'No Swiss QR should be generated for this invoice',
|
||||
)
|
||||
|
||||
def swissqr_generated(self, invoice, ref_type='NON'):
|
||||
""" Ensure correct params for Swiss QR generation. """
|
||||
|
||||
self.assertTrue(
|
||||
invoice.partner_bank_id._eligible_for_qr_code('ch_qr', invoice.partner_id, invoice.currency_id), 'A Swiss QR can be generated'
|
||||
self.assertFalse(
|
||||
invoice.partner_bank_id._get_error_messages_for_qr('ch_qr', invoice.partner_id, invoice.currency_id), 'A Swiss QR can be generated'
|
||||
)
|
||||
|
||||
if ref_type == 'QRR':
|
||||
|
|
@ -120,20 +121,22 @@ class TestSwissQR(AccountTestInvoicingCommon):
|
|||
"0200\n"
|
||||
"1\n"
|
||||
"{iban}\n"
|
||||
"K\n"
|
||||
"S\n"
|
||||
"company_1_data\n"
|
||||
"Route de Berne 88\n"
|
||||
"2000 Neuchâtel\n"
|
||||
"\n\n"
|
||||
"Route de Berne\n"
|
||||
"88\n"
|
||||
"2000\n"
|
||||
"Neuchâtel\n"
|
||||
"CH\n"
|
||||
"\n\n\n\n\n\n\n"
|
||||
"42.00\n"
|
||||
"CHF\n"
|
||||
"K\n"
|
||||
"S\n"
|
||||
"Partner\n"
|
||||
"Route de Berne 41\n"
|
||||
"1000 Lausanne\n"
|
||||
"\n\n"
|
||||
"Route de Berne\n"
|
||||
"41\n"
|
||||
"1000\n"
|
||||
"Lausanne\n"
|
||||
"CH\n"
|
||||
"{ref_type}\n"
|
||||
"{struct_ref}\n"
|
||||
|
|
@ -151,7 +154,7 @@ class TestSwissQR(AccountTestInvoicingCommon):
|
|||
'barLevel': 'M',
|
||||
'width': 256,
|
||||
'height': 256,
|
||||
'quiet': 1,
|
||||
'quiet': 0,
|
||||
'mask': 'ch_cross',
|
||||
'value': payload,
|
||||
}
|
||||
|
|
@ -163,11 +166,8 @@ class TestSwissQR(AccountTestInvoicingCommon):
|
|||
self.assertEqual(params, expected_params)
|
||||
|
||||
def test_swissQR_missing_bank(self):
|
||||
# Let us test the generation of a SwissQR for an invoice, first by showing an
|
||||
# QR is included in the invoice is only generated when Odoo has all the data it needs.
|
||||
with self.assertRaises(UserError), self.cr.savepoint():
|
||||
self.invoice1.action_post()
|
||||
self.swissqr_not_generated(self.invoice1)
|
||||
self.invoice1.action_post()
|
||||
self.swissqr_not_generated(self.invoice1)
|
||||
|
||||
def test_swissQR_iban(self):
|
||||
# Now we add an account for payment to our invoice
|
||||
|
|
@ -185,13 +185,14 @@ class TestSwissQR(AccountTestInvoicingCommon):
|
|||
self.invoice1.action_post()
|
||||
self.swissqr_generated(self.invoice1, ref_type="QRR")
|
||||
|
||||
def test_swiss_order_reference_isr_for_qr_code(self):
|
||||
def test_swiss_order_reference_qrr_for_qr_code(self):
|
||||
"""
|
||||
Test that the order reference is correctly generated for QR-Code
|
||||
We summon the skipTest if Sale is not installed (instead of creating a whole module for one test)
|
||||
"""
|
||||
if 'sale.order' not in self.env:
|
||||
self.skipTest('`sale` is not installed')
|
||||
self.env.user.group_ids += self.env.ref('sales_team.group_sale_salesman')
|
||||
|
||||
payment_custom = self.env['ir.module.module']._get('payment_custom')
|
||||
if payment_custom.state != 'installed':
|
||||
|
|
@ -213,11 +214,13 @@ class TestSwissQR(AccountTestInvoicingCommon):
|
|||
})
|
||||
payment_transaction = self.env['payment.transaction'].create({
|
||||
'provider_id': provider.id,
|
||||
'payment_method_id': self.env.ref('payment.payment_method_unknown').id,
|
||||
'sale_order_ids': [order.id],
|
||||
'partner_id': self.env['res.partner'].search([("name", '=', 'Partner')])[0].id,
|
||||
'amount': 100,
|
||||
'currency_id': self.env.company.currency_id.id,
|
||||
})
|
||||
payment_transaction._set_pending()
|
||||
payment_transaction._post_process()
|
||||
|
||||
self.assertEqual(order.reference, mod10r(order.reference[:-1]))
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo.tests import Form, common, tagged
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
CH_ISR_SUBSCRIPTION = "01-162-8"
|
||||
CH_POSTAL = "10-8060-7"
|
||||
CH_IBAN = "CH15 3881 5158 3845 3843 7"
|
||||
ISR_REFERENCE_GOOD = "16 00011 23456 78901 23456 78901"
|
||||
ISR_REFERENCE_ZEROS = "00 00000 00000 00001 23456 78903"
|
||||
ISR_REFERENCE_NO_ZEROS = "1 23456 78903"
|
||||
ISR_REFERENCE_BAD = "11 11111 11111 11111 11111 11111"
|
||||
|
||||
|
||||
@tagged('post_install_l10n', 'post_install', '-at_install')
|
||||
class TestVendorBillISR(common.TransactionCase):
|
||||
"""Check we can encode Vendor bills with ISR references
|
||||
|
||||
The ISR is a structured reference with a checksum.
|
||||
User are guided to ensure they don't encode wrong ISR references.
|
||||
Only vendors with ISR issuer accounts send ISR references.
|
||||
|
||||
ISR references can be received at least till 2022.
|
||||
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestVendorBillISR, cls).setUpClass()
|
||||
cls.abs_bank = cls.env["res.bank"].create(
|
||||
{"name": "Alternative Bank Schweiz", "bic": "ABSOCH22XXX"}
|
||||
)
|
||||
cls.supplier1 = cls.env["res.partner"].create({"name": "Supplier ISR"})
|
||||
cls.supplier2 = cls.env["res.partner"].create({"name": "Supplier postal"})
|
||||
cls.supplier3 = cls.env["res.partner"].create({"name": "Supplier IBAN"})
|
||||
|
||||
cls.bank_acc_isr = cls.env['res.partner.bank'].create({
|
||||
"acc_number": "ISR 01-162-8 Supplier ISR",
|
||||
"partner_id": cls.supplier1.id,
|
||||
"l10n_ch_postal": CH_ISR_SUBSCRIPTION,
|
||||
})
|
||||
cls.bank_acc_postal = cls.env['res.partner.bank'].create({
|
||||
"acc_number": CH_POSTAL,
|
||||
"partner_id": cls.supplier2.id,
|
||||
"l10n_ch_postal": CH_POSTAL,
|
||||
})
|
||||
cls.bank_acc_iban = cls.env['res.partner.bank'].create({
|
||||
"acc_number": CH_IBAN,
|
||||
"partner_id": cls.supplier2.id,
|
||||
"l10n_ch_postal": False,
|
||||
})
|
||||
|
||||
def test_isr_ref(self):
|
||||
"""Enter ISR reference with ISR subscription account number
|
||||
|
||||
The vendor bill can be saved.
|
||||
"""
|
||||
self.env.company.country_id = self.env.ref('base.ch')
|
||||
self.env.company.account_fiscal_country_id = self.env.company.country_id
|
||||
form = Form(self.env["account.move"].with_context(
|
||||
default_move_type="in_invoice"), view="l10n_ch.isr_invoice_form")
|
||||
form.partner_id = self.supplier1
|
||||
form.partner_bank_id = self.bank_acc_isr
|
||||
|
||||
form.payment_reference = ISR_REFERENCE_GOOD
|
||||
invoice = form.save()
|
||||
|
||||
self.assertFalse(invoice.l10n_ch_isr_needs_fixing)
|
||||
|
||||
def test_isr_ref_with_zeros(self):
|
||||
"""Enter ISR reference with ISR subscription account number
|
||||
|
||||
An ISR Reference can have lots of zeros on the left.
|
||||
|
||||
The vendor bill can be saved.
|
||||
"""
|
||||
self.env.company.country_id = self.env.ref('base.ch')
|
||||
self.env.company.account_fiscal_country_id = self.env.company.country_id
|
||||
form = Form(self.env["account.move"].with_context(
|
||||
default_move_type="in_invoice"), view="l10n_ch.isr_invoice_form")
|
||||
form.partner_id = self.supplier1
|
||||
form.partner_bank_id = self.bank_acc_isr
|
||||
|
||||
form.payment_reference = ISR_REFERENCE_ZEROS
|
||||
invoice = form.save()
|
||||
|
||||
self.assertFalse(invoice.l10n_ch_isr_needs_fixing)
|
||||
|
||||
def test_isr_ref_no_zeros(self):
|
||||
"""Enter ISR reference with ISR subscription account number
|
||||
|
||||
An ISR Reference full of zeros can be entered starting by the
|
||||
first non zero digit.
|
||||
|
||||
The vendor bill can be saved.
|
||||
"""
|
||||
self.env.company.country_id = self.env.ref('base.ch')
|
||||
self.env.company.account_fiscal_country_id = self.env.company.country_id
|
||||
form = Form(self.env["account.move"].with_context(
|
||||
default_move_type="in_invoice"), view="l10n_ch.isr_invoice_form")
|
||||
form.partner_id = self.supplier1
|
||||
form.partner_bank_id = self.bank_acc_isr
|
||||
|
||||
form.payment_reference = ISR_REFERENCE_NO_ZEROS
|
||||
invoice = form.save()
|
||||
|
||||
self.assertFalse(invoice.l10n_ch_isr_needs_fixing)
|
||||
|
||||
def test_isr_wrong_ref(self):
|
||||
"""Mistype ISR reference with ISR subscription account number
|
||||
Check it will show the warning
|
||||
"""
|
||||
self.env.company.country_id = self.env.ref('base.ch')
|
||||
self.env.company.account_fiscal_country_id = self.env.company.country_id
|
||||
form = Form(self.env["account.move"].with_context(
|
||||
default_move_type="in_invoice"), view="l10n_ch.isr_invoice_form")
|
||||
form.partner_id = self.supplier1
|
||||
form.partner_bank_id = self.bank_acc_isr
|
||||
|
||||
form.payment_reference = ISR_REFERENCE_BAD
|
||||
invoice = form.save()
|
||||
|
||||
self.assertTrue(invoice.l10n_ch_isr_needs_fixing)
|
||||
Loading…
Add table
Add a link
Reference in a new issue