Skip to content

Commit

Permalink
[IMP]convert_field_to_html: manage translated fields (#384)
Browse files Browse the repository at this point in the history
* [IMP]convert_field_to_html: manage translated fields

---------

Co-authored-by: clementthomas <[email protected]>
  • Loading branch information
clementelabore and clementthomas authored Oct 3, 2024
1 parent 6300043 commit 958300b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions openupgradelib/openupgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import inspect
import json
import logging as _logging_module
import os
import sys
Expand Down Expand Up @@ -2461,12 +2462,28 @@ def default_func(cr, pool, rec_id, vals):
)


def convert_field_to_html(cr, table, field_name, html_field_name, verbose=True):
def convert_field_to_html(
cr, table, field_name, html_field_name, verbose=True, translate=False
):
"""
Convert field value to HTML value.
.. versionadded:: 7.0
"""
# For translated fields
if translate:
if version_info[0] < 16:
do_raise("Translatable fields are only managed in version 16.0 or higher")
cr.execute(f"SELECT id, {field_name} FROM {table};") # pylint: disable=E8103
for row in cr.fetchall():
record_id, translations = row
for lang in translations:
translations[lang] = plaintext2html(translations[lang])
query = f"update {table} set {html_field_name} = %s::jsonb where id = %s"
if verbose:
logged_query(cr, query, (json.dumps(translations), record_id))
else:
cr.execute(query, (json.dumps(translations), record_id))
return
if version_info[0] < 7:
logger.error(
"You cannot use this method in an OpenUpgrade version prior to 7.0."
Expand Down

0 comments on commit 958300b

Please sign in to comment.