You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Creu Blanca <https://creublanca.es/>
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from odoo.tests import common
  5. from odoo.exceptions import ValidationError
  6. import logging
  7. _logger = logging.getLogger(__name__)
  8. try:
  9. from stdnum.iso7064 import mod_97_10
  10. from stdnum.iso7064 import mod_37_2, mod_37_36
  11. from stdnum.iso7064 import mod_11_2, mod_11_10
  12. from stdnum import luhn, damm, verhoeff
  13. except(ImportError, IOError) as err:
  14. _logger.debug(err)
  15. class TestSequenceCheckDigit(common.TransactionCase):
  16. def get_sequence(self, method):
  17. return self.env['ir.sequence'].create({
  18. 'name': 'Test sequence',
  19. 'implementation': 'standard',
  20. 'check_digit_formula': method,
  21. 'padding': '5'
  22. })
  23. def test_none(self):
  24. sequence = self.get_sequence('none')
  25. self.assertEqual('00001', sequence.next_by_id())
  26. def test_null(self):
  27. sequence = self.get_sequence(None)
  28. self.assertEqual('00001', sequence.next_by_id())
  29. def test_luhn(self):
  30. sequence = self.get_sequence('luhn')
  31. self.assertTrue(luhn.validate(sequence.next_by_id()))
  32. def test_damm(self):
  33. sequence = self.get_sequence('damm')
  34. self.assertTrue(damm.validate(sequence.next_by_id()))
  35. def test_verhoeff(self):
  36. sequence = self.get_sequence('verhoeff')
  37. self.assertTrue(verhoeff.validate(sequence.next_by_id()))
  38. def test_mod_11_2(self):
  39. sequence = self.get_sequence('ISO7064_11_2')
  40. self.assertTrue(mod_11_2.validate(sequence.next_by_id()))
  41. def test_mod11_10(self):
  42. sequence = self.get_sequence('ISO7064_11_10')
  43. self.assertTrue(mod_11_10.validate(sequence.next_by_id()))
  44. def test_validation(self):
  45. sequence = self.get_sequence('ISO7064_11_10')
  46. with self.assertRaises(ValidationError):
  47. sequence.prefix = 'A'
  48. sequence.prefix = ''
  49. def test_mod37_2(self):
  50. sequence = self.get_sequence('ISO7064_37_2')
  51. sequence.prefix = 'A'
  52. self.assertTrue(mod_37_2.validate(sequence.next_by_id()))
  53. def test_mod37_36(self):
  54. sequence = self.get_sequence('ISO7064_37_36')
  55. self.assertTrue(mod_37_36.validate(sequence.next_by_id()))
  56. def test_mod97_10(self):
  57. sequence = self.get_sequence('ISO7064_97_10')
  58. self.assertTrue(mod_97_10.validate(sequence.next_by_id()))