[FIX] base: backport of 1703a2f80 on noupdate translations

When a record is in no update, it is not modified after module upgrade.
It should be the same with translations.
This commit is contained in:
Martin Trigaux
2017-06-21 15:46:25 +02:00
parent de403dc1ab
commit 2662739187
3 changed files with 26 additions and 4 deletions
+8 -3
View File
@@ -51,7 +51,8 @@ class ir_translation_import_cursor(object):
# of ir_translation, so this copy will be much faster.
cr.execute('''CREATE TEMP TABLE %s(
imd_model VARCHAR(64),
imd_name VARCHAR(128)
imd_name VARCHAR(128),
noupdate BOOLEAN
) INHERITS (%s) ''' % (self._table_name, self._parent_table))
def push(self, trans_dict):
@@ -109,7 +110,8 @@ class ir_translation_import_cursor(object):
# Step 1: resolve ir.model.data references to res_ids
cr.execute("""UPDATE %s AS ti
SET res_id = imd.res_id
SET res_id = imd.res_id,
noupdate = imd.noupdate
FROM ir_model_data AS imd
WHERE ti.res_id IS NULL
AND ti.module IS NOT NULL AND ti.imd_name IS NOT NULL
@@ -155,7 +157,10 @@ class ir_translation_import_cursor(object):
src = ti.src,
state = 'translated'
FROM %s AS ti
WHERE %s AND ti.value IS NOT NULL AND ti.value != ''
WHERE %s
AND ti.value IS NOT NULL
AND ti.value != ''
AND noupdate IS NOT TRUE
""" % (self._parent_table, self._table_name, find_expr),
(tuple(src_relevant_fields), tuple(src_relevant_fields)))
@@ -13,3 +13,20 @@ class TestTermCount(common.TransactionCase):
ids = self.registry('ir.translation').search(self.cr, self.uid,
[('src', '=', '1XBUO5PUYH2RYZSA1FTLRYS8SPCNU1UYXMEYMM25ASV7JC2KTJZQESZYRV9L8CGB')])
self.assertEqual(len(ids), 2)
def test_noupdate(self):
"""
Make sure no update do not overwrite translations
"""
menu = self.env.ref('test_translation_import.menu_test_translation_import')
menu.name = "New Name"
# install french and change translation content
odoo.tools.trans_load(self.cr, 'test_translation_import/i18n/fr.po', 'fr_FR', verbose=False)
menu.with_context(lang='fr_FR').name = "Nouveau nom"
# reload with overwrite
odoo.tools.trans_load(self.cr, 'test_translation_import/i18n/fr.po', 'fr_FR', verbose=False, context={'overwrite': True})
# trans_load invalidates ormcache but not record cache
menu.refresh()
self.assertEqual(menu.name, "New Name")
self.assertEqual(menu.with_context(lang='fr_FR').name, "Nouveau nom")
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<data noupdate="1">
<record id="action_test_translation_import" model="ir.actions.act_window">
<field name="name">Test translation import</field>