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.

70 lines
2.5 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(self):
  7. super(TestGLN, self).setUp()
  8. self.partner = self.env["res.partner"].create({"name": "TestGLN"})
  9. self.partner2 = self.env["res.partner"].create({"name": "TestGLN2"})
  10. pc = self.env.ref(
  11. "partner_identification_gln." "partner_identification_gln_number_category"
  12. )
  13. self.partner_id_category = pc
  14. pc_gcp = self.env.ref(
  15. "partner_identification_gln." "partner_identification_gcp_number_category"
  16. )
  17. self.partner_id_gcp_category = pc_gcp
  18. def test_gln(self):
  19. # Good GLN
  20. vals = {"name": "5450534005852", "category_id": self.partner_id_category.id}
  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", "category_id": self.partner_id_category.id}
  26. with self.assertRaises(ValidationError):
  27. self.partner2.write({"id_numbers": [(0, 0, vals)]})
  28. # Bad GLN
  29. vals = {"name": "5450534001716", "category_id": self.partner_id_category.id}
  30. with self.assertRaises(ValidationError):
  31. self.partner.write({"id_numbers": [(0, 0, vals)]})
  32. def test_gln_with_no_number(self):
  33. self.assertFalse(
  34. self.partner_id_category.validate_res_partner_gln(id_number=None)
  35. )
  36. def test_gcp(self):
  37. # Good GLN
  38. vals = {"name": "545053", "category_id": self.partner_id_gcp_category.id}
  39. self.partner.write({"id_numbers": [(0, 0, vals)]})
  40. id_number = self.partner.id_numbers[0]
  41. self.assertEqual(id_number.name, "545053")
  42. # Duplicate GLN
  43. vals = {"name": "545053", "category_id": self.partner_id_gcp_category.id}
  44. with self.assertRaises(ValidationError):
  45. self.partner2.write({"id_numbers": [(0, 0, vals)]})
  46. # Bad GLN
  47. vals = {"name": "5450534001716", "category_id": self.partner_id_gcp_category.id}
  48. with self.assertRaises(ValidationError):
  49. self.partner.write({"id_numbers": [(0, 0, vals)]})
  50. def test_gcp_with_no_number(self):
  51. self.assertFalse(
  52. self.partner_id_gcp_category.validate_res_partner_gln(id_number=None)
  53. )