test_references.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. from odoo.tests import tagged
  3. from odoo.addons.account.tests.common import AccountTestInvoicingCommon
  4. from odoo.exceptions import UserError
  5. @tagged('post_install_l10n', 'post_install', '-at_install')
  6. class PaymentReferenceTest(AccountTestInvoicingCommon):
  7. """
  8. All references validated with the reference calculator by Nordea Bank
  9. http://www.nordea.fi/en/corporate-customers/payments/invoicing-and-payments/reference-number-calculator.html
  10. """
  11. @classmethod
  12. def setUpClass(cls, chart_template_ref='l10n_fi.fi_chart_template'):
  13. super().setUpClass(chart_template_ref=chart_template_ref)
  14. cls.invoice = cls.init_invoice('out_invoice', products=cls.product_a+cls.product_b)
  15. def test_payment_reference_fi(self):
  16. compute = self.invoice.compute_payment_reference_finnish
  17. # Common
  18. self.assertEqual('1232', compute('INV123'))
  19. self.assertEqual('1326', compute('132'))
  20. self.assertEqual('1290', compute('ABC1B2B9C'))
  21. # Insufficient
  22. self.assertEqual('1119', compute('-1'))
  23. self.assertEqual('1106', compute('0'))
  24. self.assertEqual('1261', compute('26'))
  25. # Excess length
  26. self.assertEqual('12345678901234567894', compute('123456789012345678901234567890'))
  27. # Invalid
  28. with self.assertRaises(UserError):
  29. compute('QWERTY')
  30. def test_payment_reference_rf(self):
  31. compute = self.invoice.compute_payment_reference_finnish_rf
  32. # Common
  33. self.assertEqual('RF111232', compute('INV123'))
  34. self.assertEqual('RF921326', compute('132'))
  35. self.assertEqual('RF941290', compute('ABC1B2B9C'))
  36. # Insufficient
  37. self.assertEqual('RF551119', compute('-1'))
  38. self.assertEqual('RF181106', compute('0'))
  39. self.assertEqual('RF041261', compute('26'))
  40. # Excess length
  41. self.assertEqual('RF0912345678901234567894', compute('123456789012345678901234567890'))
  42. # Invalid
  43. with self.assertRaises(UserError):
  44. compute('QWERTY')