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.

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