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.

80 lines
2.7 KiB

  1. # Copyright 2016 Acsone S.A.
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.exceptions import ValidationError
  4. from odoo.tests.common import SavepointCase
  5. class TestGLN(SavepointCase):
  6. def setUp(cls):
  7. super(TestGLN, cls).setUp()
  8. cls.partner = cls.env['res.partner'].create({'name': 'TestGLN'})
  9. cls.partner2 = cls.env['res.partner'].create({'name': 'TestGLN2'})
  10. pc = cls.env.ref('partner_identification_gln.'
  11. 'partner_identification_gln_number_category')
  12. cls.partner_id_category = pc
  13. pc_gcp = cls.env.ref('partner_identification_gln.'
  14. 'partner_identification_gcp_number_category')
  15. cls.partner_id_gcp_category = pc_gcp
  16. def test_gln(self):
  17. # Good GLN
  18. vals = {'name': '5450534005852',
  19. 'category_id': self.partner_id_category.id
  20. }
  21. self.partner.write({'id_numbers': [(0, 0, vals)]})
  22. id_number = self.partner.id_numbers[0]
  23. self.assertEqual(id_number.name, '5450534005852')
  24. # Duplicate GLN
  25. vals = {'name': '5450534005852',
  26. 'category_id': self.partner_id_category.id
  27. }
  28. with self.assertRaises(ValidationError):
  29. self.partner2.write({'id_numbers': [(0, 0, vals)]})
  30. # Bad GLN
  31. vals = {'name': '5450534001716',
  32. 'category_id': self.partner_id_category.id
  33. }
  34. with self.assertRaises(ValidationError):
  35. self.partner.write({'id_numbers': [(0, 0, vals)]})
  36. def test_gln_with_no_number(self):
  37. self.assertFalse(
  38. self.partner_id_category.validate_res_partner_gln(id_number=None))
  39. def test_gcp(self):
  40. # Good GLN
  41. vals = {'name': '545053',
  42. 'category_id': self.partner_id_gcp_category.id
  43. }
  44. self.partner.write({'id_numbers': [(0, 0, vals)]})
  45. id_number = self.partner.id_numbers[0]
  46. self.assertEqual(id_number.name, '545053')
  47. # Duplicate GLN
  48. vals = {'name': '545053',
  49. 'category_id': self.partner_id_gcp_category.id
  50. }
  51. with self.assertRaises(ValidationError):
  52. self.partner2.write({'id_numbers': [(0, 0, vals)]})
  53. # Bad GLN
  54. vals = {'name': '5450534001716',
  55. 'category_id': self.partner_id_gcp_category.id
  56. }
  57. with self.assertRaises(ValidationError):
  58. self.partner.write({'id_numbers': [(0, 0, vals)]})
  59. def test_gcp_with_no_number(self):
  60. self.assertFalse(
  61. self.partner_id_gcp_category.validate_res_partner_gln(
  62. id_number=None))