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.

67 lines
2.4 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_company(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. with self.assertRaises(ValidationError):
  30. self.company.partner_ref_unique = 'all'
  31. def test_check_ref(self):
  32. self.partner1.ref = 'same_ref'
  33. # Test can't create/modify partner with same ref
  34. self.company.partner_ref_unique = 'all'
  35. with self.assertRaises(ValidationError):
  36. self.partner2.ref = 'same_ref'
  37. with self.assertRaises(ValidationError):
  38. self.partner_obj.create({
  39. 'name': 'other',
  40. 'ref': 'same_ref',
  41. })
  42. # Test can't create/modify companies with same ref
  43. self.company.partner_ref_unique = 'companies'
  44. self.partner2.ref = 'same_ref'
  45. self.assertEqual(self.partner1.ref, self.partner2.ref)
  46. self.partner2.ref = False
  47. self.partner1.is_company = True
  48. self.partner2.is_company = True
  49. with self.assertRaises(ValidationError):
  50. self.partner2.ref = 'same_ref'
  51. with self.assertRaises(ValidationError):
  52. self.partner_obj.create({
  53. 'is_company': True,
  54. 'name': 'other',
  55. 'ref': 'same_ref',
  56. })
  57. # Here there shouldn't be any problem
  58. self.partner_obj.create({
  59. 'is_company': False,
  60. 'name': 'other',
  61. 'ref': 'same_ref',
  62. })