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.

47 lines
1.8 KiB

  1. # Copyright 2015 ACSONE SA/NV (<http://acsone.eu>).
  2. # Copyright 2016 Tecnativa - Vicent Cubells
  3. # License AGPL-3.0 or later (http://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",
  11. 'email': "test@test.com"})
  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(copy.ref, "A partner with ref created by copy "
  17. "has a ref by default.")
  18. def test_ref_sequence_on_contact(self):
  19. # Test if sequence doesn't increase on creating a contact child
  20. contact = self.res_partner.create({
  21. 'name': "contact1",
  22. 'email': "contact@contact.com",
  23. 'parent_id': self.partner.id})
  24. self.assertEqual(
  25. self.partner.ref, contact.ref, "All it's ok as sequence doesn't "
  26. "increase.")
  27. def test_unique_ref_on_write(self):
  28. """Assert that create and write gives a different refs if we """
  29. vals = [
  30. {'name': "test1", 'email': "test@test.com"},
  31. {'name': "test2", 'email': "test@test.com"},
  32. ]
  33. partners = self.env['res.partner'].create(vals)
  34. self.assertFalse(partners[0].ref == partners[1].ref)
  35. partners.write({'ref': False})
  36. self.assertFalse(partners[0].ref)
  37. partners.write({})
  38. self.assertFalse(partners[0].ref == partners[1].ref)