Skip to content

Commit 3a035df

Browse files
yajoaj-fuentes
andauthored
Apply suggestions from code review
Co-authored-by: Alvaro Fuentes <[email protected]>
1 parent 182fe32 commit 3a035df

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/util/specific.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,19 @@ def translation2jsonb_all_missing(cr):
156156
157157
:return: Converted fields.
158158
"""
159+
if not util.version_gte("16.0"):
160+
raise UpgradeError("JSONB translations are only available from Odoo 16")
159161
_env = env(cr)
160162
fields = []
161163
cr.execute(
162164
"""
163-
SELECT STRING_TO_ARRAY(name, ','), ARRAY_AGG(DISTINCT lang)
164-
FROM _ir_translation
165-
WHERE
166-
type IN ('model', 'model_terms')
167-
AND name LIKE '%,%'
168-
AND lang != 'en_US'
169-
GROUP BY name
165+
SELECT STRING_TO_ARRAY(name, ','),
166+
ARRAY_AGG(DISTINCT lang)
167+
FROM _ir_translation
168+
WHERE type IN ('model', 'model_terms')
169+
AND name LIKE '%,%'
170+
AND lang != 'en_US'
171+
GROUP BY name
170172
"""
171173
)
172174
for (mname, fname), langs in cr.fetchall():
@@ -186,10 +188,8 @@ def translation2jsonb_all_missing(cr):
186188
continue
187189
# Check if the field is already converted
188190
cr.execute(
189-
sql.SQL("SELECT 1 FROM {} WHERE {} ?| %s LIMIT 1").format(
190-
sql.Identifier(model._table), sql.Identifier(fname)
191-
),
192-
(langs,),
191+
format_query(cr, "SELECT 1 FROM {} WHERE {} ?| %s LIMIT 1", model._table, fname),
192+
[langs],
193193
)
194194
if not cr.rowcount:
195195
fields.append(field)
@@ -205,6 +205,8 @@ def translation2jsonb(cr, *fields):
205205
:param odoo.fields.Field fields: Fields to convert.
206206
:return: Converted fields.
207207
"""
208+
if not util.version_gte("16.0"):
209+
...
208210
all_cleanup_queries = []
209211
for field in fields:
210212
_logger.info("Migrating translations for field %s in model %s", field.name, field.model_name)

0 commit comments

Comments
 (0)