summaryrefslogtreecommitdiff
path: root/addons/l10n_fi/tests/test_references.py
blob: 38cf8a7b41140c140ce63345f3edde735273f8c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.exceptions import UserError


@tagged('standard', 'at_install')
class PaymentReferenceTest(AccountTestInvoicingCommon):
    """
    All references validated with the reference calculator by Nordea Bank
    http://www.nordea.fi/en/corporate-customers/payments/invoicing-and-payments/reference-number-calculator.html
    """

    @classmethod
    def setUpClass(cls, chart_template_ref='l10n_fi.fi_chart_template'):
        super().setUpClass(chart_template_ref=chart_template_ref)

        cls.invoice = cls.init_invoice('out_invoice', products=cls.product_a+cls.product_b)

    def test_payment_reference_fi(self):

        compute = self.invoice.compute_payment_reference_finnish

        # Common
        self.assertEqual('1232', compute('INV123'))
        self.assertEqual('1326', compute('132'))
        self.assertEqual('1290', compute('ABC1B2B9C'))

        # Insufficient
        self.assertEqual('1119', compute('-1'))
        self.assertEqual('1106', compute('0'))
        self.assertEqual('1261', compute('26'))

        # Excess length
        self.assertEqual('12345678901234567894', compute('123456789012345678901234567890'))

        # Invalid
        with self.assertRaises(UserError):
            compute('QWERTY')

    def test_payment_reference_rf(self):

        compute = self.invoice.compute_payment_reference_finnish_rf

        # Common
        self.assertEqual('RF111232', compute('INV123'))
        self.assertEqual('RF921326', compute('132'))
        self.assertEqual('RF941290', compute('ABC1B2B9C'))

        # Insufficient
        self.assertEqual('RF551119', compute('-1'))
        self.assertEqual('RF181106', compute('0'))
        self.assertEqual('RF041261', compute('26'))

        # Excess length
        self.assertEqual('RF0912345678901234567894', compute('123456789012345678901234567890'))

        # Invalid
        with self.assertRaises(UserError):
            compute('QWERTY')