Skip to content
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
26 changes: 26 additions & 0 deletions openupgrade_scripts/scripts/base/16.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Copyright 2020 Odoo Community Association (OCA)
# Copyright 2020 Opener B.V. <stefan@opener.am>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import csv
import logging

from openupgradelib import openupgrade

from odoo import tools
from odoo.modules.module import get_resource_path

from odoo.addons.openupgrade_scripts.apriori import merged_modules, renamed_modules

Expand Down Expand Up @@ -113,6 +115,29 @@ def update_translatable_fields(cr):
)


def _review_states_xmlids(cr):
data_file = open(get_resource_path("base", "data", "res.country.state.csv"), "r")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add docstring to explain the purpose of this.

data_file.seek(0)
reader = csv.DictReader(data_file)
for row in reader:
cr.execute(
"""
SELECT rcs.id
FROM res_country_state rcs
JOIN res_country rc ON rc.id = rcs.country_id
JOIN
ir_model_data imd ON imd.res_id = rc.id
AND imd.model = 'res.country'
AND imd.module = 'base'
WHERE rcs.code = %s AND imd.name = %s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is imd.name the best option?

""",
(row["code"], row["country_id:id"]),
)
result = cr.fetchone()
if result:
openupgrade.add_xmlid(cr, "base", row["id"], "res.country.state", result[0])


@openupgrade.migrate(use_env=False)
def migrate(cr, version):
"""
Expand All @@ -139,3 +164,4 @@ def migrate(cr, version):
)
# update all translatable fields
update_translatable_fields(cr)
_review_states_xmlids(cr)