[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) <rco@openerp.com> Co-authored-by: Martin Trigaux <mat@odoo.com>
This commit is contained in:
committed by
Martin Trigaux
co-authored by
Martin Trigaux
parent
c2d4873e71
commit
a9567a7f21
@@ -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! '
|
||||
|
||||
Reference in New Issue
Block a user