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.

62 lines
2.2 KiB

  1. # Copyright 2017 Tecnativa - Vicent Cubells
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo.tests import common
  4. from odoo.exceptions import ValidationError
  5. class TestResPartnerRefUnique(common.SavepointCase):
  6. @classmethod
  7. def setUpClass(cls):
  8. super(TestResPartnerRefUnique, cls).setUpClass()
  9. cls.company = cls.env.ref('base.main_company')
  10. cls.partner_obj = cls.env['res.partner']
  11. cls.partner1 = cls.partner_obj.create({
  12. 'name': 'Partner1',
  13. })
  14. cls.partner2 = cls.partner_obj.create({
  15. 'name': 'Partner2',
  16. })
  17. def test_check_ref(self):
  18. # Test can create/modify partners with same ref
  19. self.company.partner_ref_unique = 'none'
  20. self.partner1.ref = 'same_ref'
  21. self.partner2.ref = 'same_ref'
  22. self.assertEqual(self.partner1.ref, self.partner2.ref)
  23. # Here there shouldn't be any problem
  24. self.partner_obj.create({
  25. 'name': 'other',
  26. 'ref': 'same_ref',
  27. })
  28. self.partner2.ref = False
  29. # Test can't create/modify partner with same ref
  30. self.company.partner_ref_unique = 'all'
  31. with self.assertRaises(ValidationError):
  32. self.partner2.ref = 'same_ref'
  33. with self.assertRaises(ValidationError):
  34. self.partner_obj.create({
  35. 'name': 'other',
  36. 'ref': 'same_ref',
  37. })
  38. # Test can't create/modify companies with same ref
  39. self.company.partner_ref_unique = 'companies'
  40. self.partner2.ref = 'same_ref'
  41. self.assertEqual(self.partner1.ref, self.partner2.ref)
  42. self.partner2.ref = False
  43. self.partner1.is_company = True
  44. self.partner2.is_company = True
  45. with self.assertRaises(ValidationError):
  46. self.partner2.ref = 'same_ref'
  47. with self.assertRaises(ValidationError):
  48. self.partner_obj.create({
  49. 'is_company': True,
  50. 'name': 'other',
  51. 'ref': 'same_ref',
  52. })
  53. # Here there shouldn't be any problem
  54. self.partner_obj.create({
  55. 'is_company': False,
  56. 'name': 'other',
  57. 'ref': 'same_ref',
  58. })