[FIX] database_cleanup: Check that the model is automatically managed by Odoo

pull/2936/head
Yann Papouin 2024-02-12 16:00:34 +01:00 committed by Andrea Stirpe
parent f8afaf2e28
commit ec344edf73
1 changed files with 10 additions and 9 deletions

View File

@ -50,16 +50,17 @@ class CleanupPurgeLineField(models.TransientModel):
for rec in to_unlink: for rec in to_unlink:
self.logger.info(' - %s.%s', rec.model_name, rec.field_id.name) self.logger.info(' - %s.%s', rec.model_name, rec.field_id.name)
field_id = rec.with_context(**context_flags).field_id field_id = rec.with_context(**context_flags).field_id
# If store field is not set, the SQL column will not be DROPPED model = self.env[rec.model_name]
# even if exists table_name = model._table
if not field_id.store: column_name = field_id.name
table_name = self.env[rec.model_name]._table force_drop = False
column_name = field_id.name # FIX: on unlink, odoo will not DROP the SQL column even if exists if the
else: # store attribute is set to False.
table_name = False if not field_id.store and model._auto:
column_name = False force_drop = True
# Odoo will internally drop the SQL column
field_id.unlink() field_id.unlink()
if table_name and column_name: if force_drop:
self._drop_column(table_name, column_name) self._drop_column(table_name, column_name)
rec.purged = True rec.purged = True
return True return True