From 112bd835d80619a0337dca10b21aa6ca68e3303d Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Mon, 1 Apr 2019 09:25:09 +0000 Subject: [PATCH] [FIX] base: drop translations when dropping a column or table Better than if ba58888ced as the records may be removed via ondelete='cascade' (where the unlink is not called on the record). Will be faster too. A solution to opw-1955062 and opw-1950117 with uninstallation of website. Closes odoo/odoo#32056 --- odoo/addons/base/models/ir_model.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/odoo/addons/base/models/ir_model.py b/odoo/addons/base/models/ir_model.py index da31a2ae8b8..a1692e20cec 100644 --- a/odoo/addons/base/models/ir_model.py +++ b/odoo/addons/base/models/ir_model.py @@ -185,6 +185,11 @@ class IrModel(models.Model): self._cr.execute('DROP VIEW "%s"' % table) elif kind == 'r': self._cr.execute('DROP TABLE "%s" CASCADE' % table) + # discard all translations for this model + self._cr.execute(""" + DELETE FROM ir_translation + WHERE type IN ('model', 'model_terms') AND name LIKE %s + """, [model.model + ',%']) else: _logger.warning('The model %s could not be dropped because it did not exist in the registry.', model.model) return True @@ -574,6 +579,12 @@ class IrModelFields(models.Model): tables_to_drop.add(rel_name) if field.state == 'manual' and is_model: model._pop_field(field.name) + if field.translate: + # discard all translations for this field + self._cr.execute(""" + DELETE FROM ir_translation + WHERE type IN ('model', 'model_terms') AND name=%s + """, ['%s,%s' % (field.model, field.name)]) if tables_to_drop: # drop the relation tables that are not used by other fields