From a9567a7f2140b59333ea56664b3b9d31ffaa0e14 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 20 Aug 2019 14:11:04 +0000 Subject: [PATCH] [FIX] base: allow to remove fields when the registry is not ready When the registry is not ready, allow modifications of the selections The following use case must reset the values: - removing a selection on a custom field via studio - changing the static selection definition and updating the module The value must NOT be reset when: - trying to remove manually a base field - updating a module without all override being computed yet (i.e. install) Fully replacing the selections in an override should not happen Instead of relying on the context, check if the registry is ready before marking the selections as to remove. If a static selection is removed and the module updated, it will be removed correctly during the _process_end method as the selections will not be present in pool.loaded_xmlids Before this commit, updating a module A was doing a SET NULL for selection values added by a module B via a selection_add closes odoo/odoo#35871 Signed-off-by: Raphael Collet (rco) Co-authored-by: Martin Trigaux --- odoo/addons/base/models/ir_model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index f12d0aaa453..0a1e1c7864d 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -1042,11 +1042,11 @@ class IrModelSelection(models.Model): for value in new_rows.keys() | cur_rows.keys(): new_row, cur_row = new_rows.get(value), cur_rows.get(value) if new_row is None: - if not self._context.get(MODULE_UNINSTALL_FLAG) and not self._context.get('module'): + if self.pool.ready: # removing a selection in the new list, at your own risks _logger.warning("Removing selection value %s on %s.%s", cur_row['value'], model_name, field_name) - rows_to_remove.append(cur_row['id']) + rows_to_remove.append(cur_row['id']) elif cur_row is None: rows_to_insert.append(dict(new_row, field_id=field_id)) elif any(new_row[key] != cur_row[key] for key in new_row): @@ -1125,7 +1125,7 @@ class IrModelSelection(models.Model): def unlink(self): # Prevent manual deletion of module columns if ( - not self._context.get(MODULE_UNINSTALL_FLAG) and not self._context.get('module') + self.pool.ready and any(selection.field_id.state != 'manual' for selection in self) ): raise UserError(_('Properties of base fields cannot be altered in this manner! '