Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] convert_translatable_field_to_html method #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions openupgradelib/openupgrade_160.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from psycopg2 import sql
from psycopg2.extras import Json

from odoo.tools.mail import plaintext2html
from odoo.tools.translate import _get_translation_upgrade_queries

from .openupgrade import logged_query, table_exists, update_field_multilang
Expand Down Expand Up @@ -415,6 +416,28 @@ def _convert_field_bootstrap_4to5_sql(cr, table, field, ids=None):
)


def convert_translatable_field_to_html(cr, table, field_name, html_field_name, verbose=True):
"""
Convert translate=True field value to HTML value.
"""
cr.execute( # pylint: disable=E8103
"SELECT id, %(field)s FROM %(table)s WHERE %(field)s IS NOT NULL"
% {
"field": field_name,
"table": table,
}
)
for row in cr.fetchall():
query = "UPDATE %(table)s SET %(field)s = jsonb_build_object('en_US', %%s) WHERE id = %%s" % {
"field": html_field_name,
"table": table,
}
if verbose:
logged_query(cr, query, (str(plaintext2html(row[1]['en_US'])), row[0]))
else:
cr.execute(query, (str(plaintext2html(row[1]['en_US'])), row[0]))


def fill_analytic_distribution(
env,
table,
Expand Down
Loading