summaryrefslogtreecommitdiff
path: root/odoo/addons/test_new_api/tests/test_new_fields.py
diff options
context:
space:
mode:
authorAdrian Torres <adt@odoo.com>2021-03-04 07:42:07 +0000
committerAdrian Torres <adt@odoo.com>2021-03-10 13:12:18 +0000
commitf5c7e861ee3ca0cdeb6c2f06d227ada07f923ed0 (patch)
tree2b8eee4e4f16821b040fd67d03e6115d17ba87d6 /odoo/addons/test_new_api/tests/test_new_fields.py
parent2e238f1e0202d65a98177939dac166dd659bb39c (diff)
[FIX] base: properly execute Selection field ondelete actions
With this commit, 2 changes are made to the way that the fields.Selection.ondelete cleanup action works: 1) We manually delete ir.model.fields.selection **before** the deletion of ir.model.fields purposefully to **avoid** SQL CASCADE deletes, as we do not know which selections are deleted in cascade and thus we cannot perform the corresponding ondelete cleanup action (which is implemented within the ORM). 2) In some actions, namely 'set default' and 'set null', we write a "safe" value to the records containing the Selection being deleted, before this commit this would go through the ORM (records.write()) but this is problematic if there's a write override for the record's model that raises an error for the field being written to. With this commit, we first try to go through the ORM but if there's a failure (because of the raise in a write override) then we will bypass the ORM and set it with SQL. opw-2451126 closes odoo/odoo#67253 Signed-off-by: Adrian Torres (adt) <adt@odoo.com>
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_new_fields.py')
-rw-r--r--odoo/addons/test_new_api/tests/test_new_fields.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py
index ed3478af1dd..b3a83605d19 100644
--- a/odoo/addons/test_new_api/tests/test_new_fields.py
+++ b/odoo/addons/test_new_api/tests/test_new_fields.py
@@ -2925,6 +2925,7 @@ class TestSelectionOndelete(common.TransactionCase):
MODEL_BASE = 'test_new_api.model_selection_base'
MODEL_REQUIRED = 'test_new_api.model_selection_required'
MODEL_NONSTORED = 'test_new_api.model_selection_non_stored'
+ MODEL_WRITE_OVERRIDE = 'test_new_api.model_selection_required_for_write_override'
def setUp(self):
super().setUp()
@@ -3063,6 +3064,16 @@ class TestSelectionOndelete(common.TransactionCase):
self._unlink_option(self.MODEL_REQUIRED, 'foo')
self.assertEqual(rec.my_selection, 'foo')
+ @mute_logger('odoo.addons.base.models.ir_model')
+ def test_write_override_selection(self):
+ # test that on override to write that raises an error does not prevent the ondelete
+ # policy from executing and cleaning up what needs to be cleaned up
+ rec = self.env[self.MODEL_WRITE_OVERRIDE].create({'my_selection': 'divinity'})
+ self.assertEqual(rec.my_selection, 'divinity')
+
+ self._unlink_option(self.MODEL_WRITE_OVERRIDE, 'divinity')
+ self.assertEqual(rec.my_selection, 'foo')
+
@common.tagged('selection_ondelete_advanced')
class TestSelectionOndeleteAdvanced(common.TransactionCase):