[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:
self.logger.info(' - %s.%s', rec.model_name, rec.field_id.name)
field_id = rec.with_context(**context_flags).field_id
# If store field is not set, the SQL column will not be DROPPED
# even if exists
if not field_id.store:
table_name = self.env[rec.model_name]._table
model = self.env[rec.model_name]
table_name = model._table
column_name = field_id.name
else:
table_name = False
column_name = False
force_drop = False
# FIX: on unlink, odoo will not DROP the SQL column even if exists if the
# store attribute is set to False.
if not field_id.store and model._auto:
force_drop = True
# Odoo will internally drop the SQL column
field_id.unlink()
if table_name and column_name:
if force_drop:
self._drop_column(table_name, column_name)
rec.purged = True
return True