From 39d17c258057ba8ec05b0a2a350c3fb1a1219d3d Mon Sep 17 00:00:00 2001 From: Raf Ven Date: Fri, 9 Jan 2015 15:12:38 +0100 Subject: [PATCH] [FIX] base: avoid deleting translations When updating a translation, the previous one is deleted and a new one is recreated (with no module and state). When the source module is updated, the previous term is inserted again to the lsit of terms. Instead of dropping and recreating terms during update, simply update the existing term and create one only if there were no previous translation. Fixes #4617 --- openerp/addons/base/ir/ir_translation.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/ir/ir_translation.py b/openerp/addons/base/ir/ir_translation.py index d2e5ce7a98e..8ec81e94bd0 100644 --- a/openerp/addons/base/ir/ir_translation.py +++ b/openerp/addons/base/ir/ir_translation.py @@ -286,21 +286,31 @@ class ir_translation(osv.osv): def _set_ids(self, cr, uid, name, tt, lang, ids, value, src=None): self._get_ids.clear_cache(self) self.__get_source.clear_cache(self) - - cr.execute('delete from ir_translation ' + original_module = self.pool[name.split(',')[0]]._original_module + cr.execute('update ir_translation ' + 'set value=%s ' + ' , src=%s ' + ' , state=%s ' 'where lang=%s ' 'and type=%s ' 'and name=%s ' - 'and res_id IN %s', - (lang,tt,name,tuple(ids),)) - for id in ids: + 'and module=%s ' + 'and res_id IN %s ' + 'returning res_id', + (value,src,'translated',lang,tt,name,original_module,tuple(ids),)) + + existing_ids = [x[0] for x in cr.fetchall()] + + for id in list(set(ids) - set(existing_ids)): self.create(cr, uid, { 'lang':lang, 'type':tt, 'name':name, 'res_id':id, + 'module':original_module, 'value':value, 'src':src, + 'state':'translated' }) return len(ids)