[IMP] models: remove orphan translations
Same logic as for the mail.message or ir.attachment, when a record is deleted, drop the ir.translations linked to it as well. Fixes odoo/odoo#25105 Co-authored-by: Raphael Collet <rco@odoo.com> closes odoo/odoo#30721
This commit is contained in:
co-authored by
Raphael Collet
parent
2e57f90bd1
commit
ba58888ced
@@ -3114,6 +3114,7 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
|||||||
Data = self.env['ir.model.data'].sudo().with_context({})
|
Data = self.env['ir.model.data'].sudo().with_context({})
|
||||||
Defaults = self.env['ir.default'].sudo()
|
Defaults = self.env['ir.default'].sudo()
|
||||||
Attachment = self.env['ir.attachment']
|
Attachment = self.env['ir.attachment']
|
||||||
|
Translation = self.env['ir.translation'].sudo()
|
||||||
|
|
||||||
for sub_ids in cr.split_for_in_conditions(self.ids):
|
for sub_ids in cr.split_for_in_conditions(self.ids):
|
||||||
query = "DELETE FROM %s WHERE id IN %%s" % self._table
|
query = "DELETE FROM %s WHERE id IN %%s" % self._table
|
||||||
@@ -3144,6 +3145,15 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
|||||||
if attachments:
|
if attachments:
|
||||||
attachments.unlink()
|
attachments.unlink()
|
||||||
|
|
||||||
|
if any(field.translate for field in self._fields.values()):
|
||||||
|
# For the same reason, remove the relevant records in ir_translation
|
||||||
|
translations = Translation.search([
|
||||||
|
('type', 'in', ['model', 'model_terms']),
|
||||||
|
('name', '=like', self._name+',%'),
|
||||||
|
('res_id', 'in', sub_ids)])
|
||||||
|
if translations:
|
||||||
|
translations.unlink()
|
||||||
|
|
||||||
# invalidate the *whole* cache, since the orm does not handle all
|
# invalidate the *whole* cache, since the orm does not handle all
|
||||||
# changes made in the database, like cascading delete!
|
# changes made in the database, like cascading delete!
|
||||||
self.invalidate_cache()
|
self.invalidate_cache()
|
||||||
|
|||||||
Reference in New Issue
Block a user