Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions odoo/addons/base/ir/ir_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def finish(self):
cr.execute(""" INSERT INTO %s(name, lang, res_id, src, type, value, module, state, comments)
SELECT name, lang, res_id, src, type, value, module, state, comments
FROM %s AS ti
WHERE NOT EXISTS(SELECT 1 FROM ONLY %s AS irt WHERE %s);
WHERE NOT EXISTS(SELECT 1 FROM ONLY %s AS irt WHERE %s)
ON CONFLICT DO NOTHING;
""" % (self._model_table, self._table, self._model_table, find_expr),
(tuple(src_relevant_fields), tuple(src_relevant_fields)))

Expand Down Expand Up @@ -281,8 +282,8 @@ def _auto_init(self):
cr.execute('CREATE INDEX ir_translation_src_md5 ON ir_translation (md5(src))')
cr.commit()

if 'ir_translation_ltn' not in indexes:
cr.execute('CREATE INDEX ir_translation_ltn ON ir_translation (name, lang, type)')
if 'ir_translation_unique' not in indexes:
cr.execute('CREATE INDEX ir_translation_unique ON ir_translation (type, name, lang, res_id, md5(src))')
cr.commit()
return res

Expand Down
8 changes: 3 additions & 5 deletions odoo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4113,16 +4113,14 @@ def _generate_translated_field(self, table_alias, field, query):
# The parenthesis surrounding the select are important, as this is a sub-select.
# The quotes surrounding `ir_translation` are important as well.
unique_translation_subselect = """
(SELECT DISTINCT ON (res_id) res_id, value
FROM "ir_translation"
WHERE name=%s AND lang=%s AND value!=%s
ORDER BY res_id, id DESC)
(SELECT res_id, value FROM "ir_translation"
WHERE name=%s AND lang=%s AND value!='')
"""
alias, alias_statement = query.add_join(
(table_alias, unique_translation_subselect, 'id', 'res_id', field),
implicit=False,
outer=True,
extra_params=["%s,%s" % (self._name, field), self.env.lang, ""],
extra_params=["%s,%s" % (self._name, field), self.env.lang],
)
return 'COALESCE("%s"."%s", "%s"."%s")' % (alias, 'value', table_alias, field)
else:
Expand Down