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.

55 lines
2.1 KiB

  1. # Copyright 2018 Akretion - Benoît Guillot
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. import hashlib
  4. from collections import OrderedDict
  5. from odoo.exceptions import UserError
  6. from odoo.tests import SavepointCase
  7. class TestAddressVersion(SavepointCase):
  8. @classmethod
  9. def setUpClass(cls):
  10. super(TestAddressVersion, cls).setUpClass()
  11. cls.partner_vals = OrderedDict(
  12. [
  13. ("name", "Name"),
  14. ("street", "Street"),
  15. ("street2", "Street2"),
  16. ("zip", "Zip"),
  17. ("city", "City"),
  18. ("country_id", cls.env.ref("base.fr")),
  19. ]
  20. )
  21. create_vals = cls.partner_vals.copy()
  22. create_vals["country_id"] = cls.env.ref("base.fr").id
  23. create_vals_2 = create_vals.copy()
  24. cls.partner = cls.env["res.partner"].create(create_vals)
  25. cls.partner_2 = cls.env["res.partner"].create(create_vals_2)
  26. cls.partner_vals.update({"parent_id": cls.partner.id})
  27. def test_hash(self):
  28. test_hash = hashlib.md5(str(self.partner_vals).encode("utf-8")).hexdigest()
  29. self.assertEqual(test_hash, self.partner._version_hash())
  30. def test_create_version_partner(self):
  31. new_partner = self.partner._version_create()
  32. self.assertEqual(new_partner.active, False)
  33. self.assertNotEqual(new_partner.id, self.partner.id)
  34. self.assertEqual(new_partner.parent_id.id, self.partner.id)
  35. def test_write_versioned_partner(self):
  36. new_partner = self.partner._version_create()
  37. with self.assertRaises(UserError):
  38. new_partner.street = "New street"
  39. def test_same_address_different_parent(self):
  40. new_partner = self.partner._version_create()
  41. new_partner_2 = self.partner_2._version_create()
  42. for field in self.partner._version_fields():
  43. if field == "parent_id":
  44. continue
  45. self.assertEqual(new_partner[field], new_partner_2[field])
  46. self.assertNotEqual(new_partner.id, new_partner_2.id)
  47. self.assertNotEqual(new_partner.version_hash, new_partner_2.version_hash)