From a70287d42cd838f58c7f1a16bee4731528fe9b69 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 27 Nov 2015 14:03:20 +0100 Subject: [PATCH 1/2] [FIX] base: set module when creating translation When creating missing translations on an object (e.g. using blue flag icon on a field), the value of the module was not set. This was problematic as could create a duplicated translation when the module was updated or the translation reloaded (as the module is used in find_expr). opw 654036 --- openerp/addons/base/ir/ir_translation.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/ir/ir_translation.py b/openerp/addons/base/ir/ir_translation.py index 534e41ea171..1c3d7c039cd 100644 --- a/openerp/addons/base/ir/ir_translation.py +++ b/openerp/addons/base/ir/ir_translation.py @@ -431,17 +431,19 @@ class ir_translation(osv.osv): if len(langs): fields = [f.get('name') for f in translatable_fields] record = trans_model.read(cr, uid, [id], fields, context={ 'lang': main_lang })[0] + external_id = trans_model.get_external_id(cr, uid, [id])[id] + module = external_id.split('.')[0] # if no xml_id, empty string for lg in langs: for f in translatable_fields: # Check if record exists, else create it (at once) - sql = """INSERT INTO ir_translation (lang, src, name, type, res_id, value) - SELECT %s, %s, %s, 'model', %s, %s WHERE NOT EXISTS - (SELECT 1 FROM ir_translation WHERE lang=%s AND name=%s AND res_id=%s AND type='model'); - UPDATE ir_translation SET src = %s WHERE lang=%s AND name=%s AND res_id=%s AND type='model'; + sql = """INSERT INTO ir_translation (lang, src, name, type, res_id, value, module) + SELECT %s, %s, %s, 'model', %s, %s, %s WHERE NOT EXISTS + (SELECT 1 FROM ir_translation WHERE lang=%s AND name=%s AND res_id=%s AND type='model' AND module=%s); + UPDATE ir_translation SET src = %s WHERE lang=%s AND name=%s AND res_id=%s AND type='model' AND module=%s; """ src = record[f['name']] or None name = "%s,%s" % (f['model'], f['name']) - cr.execute(sql, (lg, src , name, f['id'], src, lg, name, f['id'], src, lg, name, id)) + cr.execute(sql, (lg, src, name, f['id'], src, module, lg, name, f['id'], module, src, lg, name, id, module)) action = { 'name': 'Translate', From 1f07b9429cc3de7fc65df6942191e1014b6296f2 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 18 Nov 2015 16:56:52 +0100 Subject: [PATCH 2/2] [FIX] base: update translations should not duplicate the terms When a translated term is modified (e.g. content of an email.template), reloading the translations of the module (e.g. when updating the module) used to recreate a new, duplicare translation for the modified term (instead of ignoring the existing one). This was due to the fact the matching expression (find_expr), when loading translations, used the field 'src' (source term) as criteria for (almost) all ir.translation records. While this is true for type 'code' or 'selection', this is not true for 'model' where the source content may have been changed. In case of translation of type 'model', matching on the name and res_id should be enough for the matching expression and then, avoid creating duplicated translations. Note: this patch must NOT be present in 9.0 due to the xml_translate attribute that splits an xml content into small parts. opw 654031 --- openerp/addons/base/ir/ir_translation.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/openerp/addons/base/ir/ir_translation.py b/openerp/addons/base/ir/ir_translation.py index 1c3d7c039cd..bc84437fddb 100644 --- a/openerp/addons/base/ir/ir_translation.py +++ b/openerp/addons/base/ir/ir_translation.py @@ -125,11 +125,13 @@ class ir_translation_import_cursor(object): AND irt.type = ti.type AND irt.module = ti.module AND irt.name = ti.name - AND (ti.type IN ('field', 'help') OR irt.src = ti.src) - AND ( ti.type NOT IN ('model', 'view') - OR (ti.type = 'model' AND ti.res_id = irt.res_id) - OR (ti.type = 'view' AND (irt.res_id IS NULL OR ti.res_id = irt.res_id)) - ) + AND ( -- 8.0 only where unicity is assured on translations of 'model' + (ti.type = 'model' AND ti.res_id = irt.res_id) + OR (ti.type = 'view' AND (irt.res_id IS NULL OR ti.res_id = irt.res_id) AND irt.src = ti.src) + OR (ti.type = 'field') + OR (ti.type = 'help') + OR (ti.type NOT IN ('model', 'view', 'field', 'help') AND irt.src = ti.src) + ) """ # Step 2: update existing (matching) translations