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.

110 lines
4.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Camptocamp SA
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp.tests import common
  5. from .common import ChangesetMixin
  6. class TestChangesetOrigin(ChangesetMixin, common.TransactionCase):
  7. """ Check that origin - old fields are stored as expected.
  8. 'origin' fields dynamically read fields from the partner when the state
  9. of the change is 'draft'. Once a change becomes 'done' or 'cancel', the
  10. 'old' field copies the value from the partner and then the 'origin' field
  11. displays the 'old' value.
  12. """
  13. def _setup_rules(self):
  14. ChangesetFieldRule = self.env['changeset.field.rule']
  15. ChangesetFieldRule.search([]).unlink()
  16. self.field_name = self.env.ref('base.field_res_partner_name')
  17. ChangesetFieldRule.create({
  18. 'field_id': self.field_name.id,
  19. 'action': 'validate',
  20. })
  21. def setUp(self):
  22. super(TestChangesetOrigin, self).setUp()
  23. self._setup_rules()
  24. self.partner = self.env['res.partner'].create({
  25. 'name': 'X',
  26. })
  27. def test_origin_value_of_change_with_apply(self):
  28. """ Origin field is read from the parter or 'old' - with apply
  29. According to the state of the change.
  30. """
  31. self.partner.write({
  32. 'name': 'Y',
  33. })
  34. changeset = self.partner.changeset_ids
  35. change = changeset.change_ids
  36. self.assertEqual(self.partner.name, 'X')
  37. self.assertEqual(change.origin_value_char, 'X')
  38. self.assertEqual(change.origin_value_display, 'X')
  39. self.partner.with_context(__no_changeset=True).write({'name': 'A'})
  40. self.assertEqual(change.origin_value_char, 'A')
  41. self.assertEqual(change.origin_value_display, 'A')
  42. change.apply()
  43. self.assertEqual(change.origin_value_char, 'A')
  44. self.assertEqual(change.origin_value_display, 'A')
  45. self.partner.with_context(__no_changeset=True).write({'name': 'B'})
  46. self.assertEqual(change.origin_value_char, 'A')
  47. self.assertEqual(change.origin_value_display, 'A')
  48. def test_origin_value_of_change_with_cancel(self):
  49. """ Origin field is read from the parter or 'old' - with cancel
  50. According to the state of the change.
  51. """
  52. self.partner.write({
  53. 'name': 'Y',
  54. })
  55. changeset = self.partner.changeset_ids
  56. change = changeset.change_ids
  57. self.assertEqual(self.partner.name, 'X')
  58. self.assertEqual(change.origin_value_char, 'X')
  59. self.assertEqual(change.origin_value_display, 'X')
  60. self.partner.with_context(__no_changeset=True).write({'name': 'A'})
  61. self.assertEqual(change.origin_value_char, 'A')
  62. self.assertEqual(change.origin_value_display, 'A')
  63. change.cancel()
  64. self.assertEqual(change.origin_value_char, 'A')
  65. self.assertEqual(change.origin_value_display, 'A')
  66. self.partner.with_context(__no_changeset=True).write({'name': 'B'})
  67. self.assertEqual(change.origin_value_char, 'A')
  68. self.assertEqual(change.origin_value_display, 'A')
  69. def test_old_field_of_change_with_apply(self):
  70. """ Old field is stored when the change is applied """
  71. self.partner.write({
  72. 'name': 'Y',
  73. })
  74. changeset = self.partner.changeset_ids
  75. change = changeset.change_ids
  76. self.assertEqual(self.partner.name, 'X')
  77. self.assertFalse(change.old_value_char)
  78. self.partner.with_context(__no_changeset=True).write({'name': 'A'})
  79. self.assertFalse(change.old_value_char)
  80. change.apply()
  81. self.assertEqual(change.old_value_char, 'A')
  82. self.partner.with_context(__no_changeset=True).write({'name': 'B'})
  83. self.assertEqual(change.old_value_char, 'A')
  84. def test_old_field_of_change_with_cancel(self):
  85. """ Old field is stored when the change is canceled """
  86. self.partner.write({
  87. 'name': 'Y',
  88. })
  89. changeset = self.partner.changeset_ids
  90. change = changeset.change_ids
  91. self.assertEqual(self.partner.name, 'X')
  92. self.assertFalse(change.old_value_char)
  93. self.partner.with_context(__no_changeset=True).write({'name': 'A'})
  94. self.assertFalse(change.old_value_char)
  95. change.cancel()
  96. self.assertEqual(change.old_value_char, 'A')
  97. self.partner.with_context(__no_changeset=True).write({'name': 'B'})
  98. self.assertEqual(change.old_value_char, 'A')