diff --git a/odoo/addons/base/models/ir_translation.py b/odoo/addons/base/models/ir_translation.py index 9e9baa3a0e8..fa882102bd4 100644 --- a/odoo/addons/base/models/ir_translation.py +++ b/odoo/addons/base/models/ir_translation.py @@ -445,7 +445,14 @@ class IrTranslation(models.Model): # process outdated and discarded translations outdated.write({'state': 'to_translate'}) - discarded.unlink() + + if discarded: + # delete in SQL to avoid invalidating the whole cache + discarded._modified() + discarded.modified(self._fields) + self.flush(self._fields, discarded) + self.invalidate_cache(ids=discarded._ids) + self.env.cr.execute("DELETE FROM ir_translation WHERE id IN %s", [discarded._ids]) @api.model @tools.ormcache_context('model_name', keys=('lang',)) diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py index 14e5786a937..a72fe32f2ad 100644 --- a/odoo/addons/base/tests/test_views.py +++ b/odoo/addons/base/tests/test_views.py @@ -236,6 +236,32 @@ class TestViewInheritance(ViewCase): 'arch': self.arch_for('itself', parent=True), }) + def test_write_arch(self): + self.env['res.lang']._activate_lang('fr_FR') + + v = self.makeView("T", arch='
Bar
') + self.env['ir.translation']._upsert_translations([{ + 'type': 'model_terms', + 'name': 'ir.ui.view,arch_db', + 'lang': 'fr_FR', + 'res_id': v.id, + 'src': 'Foo', + 'value': 'Fou', + }, { + 'type': 'model_terms', + 'name': 'ir.ui.view,arch_db', + 'lang': 'fr_FR', + 'res_id': v.id, + 'src': 'Bar', + 'value': 'Barre', + }]) + self.assertEqual(v.arch, '
Bar
') + + # modify v to discard translations; this should not invalidate 'arch'! + v.arch = '
' + self.assertEqual(v.arch, '
') + + class TestApplyInheritanceSpecs(ViewCase): """ Applies a sequence of inheritance specification nodes to a base architecture. IO state parameters (cr, uid, model, context) are used for