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.

50 lines
1.8 KiB

  1. # Copyright 2015 ACSONE SA/NV (<https://acsone.eu>).
  2. # Copyright 2016 Tecnativa - Vicent Cubells
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. import odoo.tests.common as common
  5. class TestBasePartnerSequence(common.TransactionCase):
  6. def setUp(self):
  7. super(TestBasePartnerSequence, self).setUp()
  8. self.res_partner = self.env["res.partner"]
  9. self.partner = self.res_partner.create(
  10. {"name": "test1", "email": "test@test.com"}
  11. )
  12. def test_ref_sequence_on_partner(self):
  13. # Test sequence on creating partner and copying it
  14. self.assertTrue(self.partner.ref, "A partner has always a ref.")
  15. copy = self.partner.copy()
  16. self.assertTrue(
  17. copy.ref, "A partner with ref created by copy has a ref by default."
  18. )
  19. def test_ref_sequence_on_contact(self):
  20. # Test if sequence doesn't increase on creating a contact child
  21. contact = self.res_partner.create(
  22. {
  23. "name": "contact1",
  24. "email": "contact@contact.com",
  25. "parent_id": self.partner.id,
  26. }
  27. )
  28. self.assertEqual(
  29. self.partner.ref, contact.ref, "All it's ok as sequence doesn't increase."
  30. )
  31. def test_unique_ref_on_write(self):
  32. """Assert that on create or on write, a different ref is assigned"""
  33. vals = [
  34. {"name": "test1", "email": "test@test.com"},
  35. {"name": "test2", "email": "test@test.com"},
  36. ]
  37. partners = self.env["res.partner"].create(vals)
  38. self.assertFalse(partners[0].ref == partners[1].ref)
  39. partners.write({"ref": False})
  40. self.assertFalse(partners[0].ref)
  41. partners.write({})
  42. self.assertFalse(partners[0].ref == partners[1].ref)