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.

48 lines
1.8 KiB

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