[FIX] tools: Avoid to delete translation for website

- If default language of website is not en_US then it's
  translation will be lose after upgrade as till now we are
  considering en_US as a default language for all the records.

- In this commit, we have added translation for website which
  is having different default language.

Opw: 3186741, 3418725
X-original-commit: 2575dff9362ba6dd2a97db8911ac8b867b126e08
Part-of: odoo/odoo#135218
This commit is contained in:
Jinal Patel
2023-09-13 04:37:06 +00:00
parent 761320ae45
commit 6cb30f599e
+19 -6
View File
@@ -1592,6 +1592,21 @@ def _get_translation_upgrade_queries(cr, field):
# upgrade model_terms translation: one update per field per record
if callable(field.translate):
query = f"""
SELECT t.res_id, m."{field.name}", t.value, t.noupdate
FROM t
JOIN "{Model._table}" m ON t.res_id = m.id
"""
if translation_name == 'ir.ui.view,arch_db':
cr.execute("SELECT id from ir_module_module WHERE name = 'website' AND state='installed'")
if cr.fetchone():
query = f"""
SELECT t.res_id, m."{field.name}", t.value, t.noupdate, l.code
FROM t
JOIN "{Model._table}" m ON t.res_id = m.id
JOIN website w ON m.website_id = w.id
JOIN res_lang l ON w.default_lang_id = l.id
"""
cr.execute(f"""
WITH t0 AS (
-- aggregate translations by source term --
@@ -1607,12 +1622,8 @@ def _get_translation_upgrade_queries(cr, field):
LEFT JOIN ir_model_data imd
ON imd.model = %s AND imd.res_id = t0.res_id
GROUP BY t0.res_id
)
SELECT t.res_id, m."{field.name}", t.value, t.noupdate
FROM t
JOIN "{Model._table}" m ON t.res_id = m.id
""", [translation_name, Model._name])
for id_, new_translations, translations, noupdate in cr.fetchall():
)""" + query, [translation_name, Model._name])
for id_, new_translations, translations, noupdate, *extra in cr.fetchall():
if not new_translations:
continue
# new_translations contains translations updated from the latest po files
@@ -1632,6 +1643,8 @@ def _get_translation_upgrade_queries(cr, field):
}
if "en_US" not in new_values:
new_values["en_US"] = field.translate(lambda v: None, src_value)
if extra and extra[0] not in new_values:
new_values[extra[0]] = new_values["en_US"]
query = f'UPDATE "{Model._table}" SET "{field.name}" = %s WHERE id = %s'
migrate_queries.append(cr.mogrify(query, [Json(new_values), id_]).decode())