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.4 KiB

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