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.

63 lines
2.4 KiB

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