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.

43 lines
1.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Tecnativa - Vicent Cubells
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests import common
  5. from openerp.exceptions import ValidationError
  6. class TestResPartnerRefUnique(common.SavepointCase):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestResPartnerRefUnique, cls).setUpClass()
  10. cls.company = cls.env.ref('base.main_company')
  11. partner_obj = cls.env['res.partner']
  12. cls.partner1 = partner_obj.create({
  13. 'name': 'Partner1',
  14. })
  15. cls.partner2 = partner_obj.create({
  16. 'name': 'Partner2',
  17. })
  18. def test_check_ref(self):
  19. # Test can create/modify partners with same ref
  20. self.company.partner_ref_unique = 'none'
  21. self.partner1.ref = 'same_ref'
  22. self.partner2.ref = 'same_ref'
  23. self.assertEqual(self.partner1.ref, self.partner2.ref)
  24. self.partner2.ref = False
  25. # Test can't create/modify partner with same ref
  26. self.company.partner_ref_unique = 'all'
  27. with self.assertRaises(ValidationError):
  28. self.partner2.ref = 'same_ref'
  29. # Test can't create/modify companies with same ref
  30. self.company.partner_ref_unique = 'companies'
  31. self.partner2.ref = 'same_ref'
  32. self.assertEqual(self.partner1.ref, self.partner2.ref)
  33. self.partner2.ref = False
  34. self.partner1.is_company = True
  35. self.partner2.is_company = True
  36. with self.assertRaises(ValidationError):
  37. self.partner2.ref = 'same_ref'