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
1 change: 1 addition & 0 deletions openupgrade_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from odoo.tools import config

from . import odoo_patch
from . import openupgradelib_patch

if not config.get("upgrade_path"):
path = get_module_path("openupgrade_scripts", display_warning=False)
Expand Down
56 changes: 56 additions & 0 deletions openupgrade_framework/openupgradelib_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright Odoo Community Association (OCA)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openupgradelib import openupgrade


def _jsonb_translated_columns(cr, model, table):
cr.execute(
"""
SELECT isc.column_name
FROM information_schema.columns isc
JOIN ir_model_fields imf ON imf.name = isc.column_name AND imf.model = %s
WHERE isc.table_name = %s AND imf.translate AND isc.data_type = 'jsonb'
""",
(model, table),
)
return [name for (name,) in cr.fetchall()]


def delete_record_translations(cr, module, xml_ids, field_list=None):
"""Only touch the translated columns that are jsonb already.

openupgradelib picks every field flagged translate in ir_model_fields and
applies the jsonb operator ? to its column. The translated columns of a
module that has not been loaded yet are still text at that point (e.g. the
website SEO fields of ir.ui.view while digest migrates), and the query dies
on "operator does not exist: text ? unknown". Those columns get their
translations converted when their own module loads.
"""
if not isinstance(xml_ids, (list, tuple)) or not xml_ids:
return delete_record_translations._original_method(
cr, module, xml_ids, field_list=field_list
)
cr.execute(
"""SELECT model, array_agg(name) FROM ir_model_data
WHERE module = %s AND name IN %s GROUP BY model""",
(module, tuple(xml_ids)),
)
for model, names in cr.fetchall():
table = openupgrade.get_model2table(model)
if not openupgrade.table_exists(cr, table):
continue
columns = _jsonb_translated_columns(cr, model, table)
if field_list:
columns = [c for c in columns if c in field_list]
if not columns:
continue
delete_record_translations._original_method(
cr, module, names, field_list=columns
)


if openupgrade.version_info[0] >= 16:
delete_record_translations._original_method = (
openupgrade.delete_record_translations
)
openupgrade.delete_record_translations = delete_record_translations
22 changes: 22 additions & 0 deletions openupgrade_scripts/scripts/base/17.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ def _handle_partner_private_type(cr):
)


def _fix_address_format_placeholders(cr):
"""A placeholder without its conversion type breaks the display of every
address of the country: after '%(street2)' the line break that follows
becomes the conversion type, and formatting raises "unsupported format
character".
Odoo shipped that format for Japan in 11.0 (13ee5596c6dd, fixed by
087bebf87a64) and the countries are noupdate data, so databases that loaded it
back then still have it. The end-migration of account_edi_ubl_cii writes on
every partner with a country, which computes their address and dies on it.
"""
pattern = r"(%\(\w+\))(?![a-zA-Z])"
openupgrade.logged_query(
cr,
"""
UPDATE res_country
SET address_format = regexp_replace(address_format, %s, %s, 'g')
WHERE address_format ~ %s""",
(pattern, r"\1s", pattern),
)


@openupgrade.migrate(use_env=False)
def migrate(cr, version):
"""
Expand All @@ -278,3 +299,4 @@ def migrate(cr, version):
_fill_ir_server_object_lines_into_action_server(cr)
_fill_empty_country_codes(cr)
_handle_partner_private_type(cr)
_fix_address_format_placeholders(cr)
Loading