Skip to content

Commit 057fbd5

Browse files
committed
[17.0][OU-ADD] account_edi: Migration to 17.0
1 parent 8b49987 commit 057fbd5

File tree

9 files changed

+551
-11
lines changed

9 files changed

+551
-11
lines changed

.github/workflows/test.yml

-1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,5 @@ jobs:
140140
--db_user=$DB_USERNAME \
141141
--load=base,web,openupgrade_framework \
142142
--log-handler odoo.models.unlink:WARNING \
143-
--test-enable \
144143
--stop-after-init \
145144
--update=$MODULES_NEW

docsource/modules160-170.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Module coverage 16.0 -> 17.0
7070
+---------------------------------------------------+----------------------+-------------------------------------------------+
7171
| barcodes_gs1_nomenclature | |No DB layout changes. |
7272
+---------------------------------------------------+----------------------+-------------------------------------------------+
73-
| base | | |
73+
| base | Done | |
7474
+---------------------------------------------------+----------------------+-------------------------------------------------+
7575
| base_address_extended | | |
7676
+---------------------------------------------------+----------------------+-------------------------------------------------+
@@ -864,7 +864,7 @@ Module coverage 16.0 -> 17.0
864864
+---------------------------------------------------+----------------------+-------------------------------------------------+
865865
| utm | | |
866866
+---------------------------------------------------+----------------------+-------------------------------------------------+
867-
| web | | |
867+
| web | Nothing to do | |
868868
+---------------------------------------------------+----------------------+-------------------------------------------------+
869869
| web_editor | | |
870870
+---------------------------------------------------+----------------------+-------------------------------------------------+

openupgrade_scripts/scripts/account_edi/17.0.1.0/pre-migration.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ def _remove_table_constraints(env):
1212
"account_edi_document_unique_edi_document_by_move_by_format",
1313
)
1414
openupgrade.delete_sql_constraint_safely(
15-
env,
16-
"account_edi",
17-
"account_edi_format",
18-
"account_edi_format_unique_code",
15+
env, "account_edi", "account_edi_format", "account_edi_format_unique_code"
1916
)
2017

2118

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
from openupgradelib import openupgrade
4+
5+
_deleted_xml_records = [
6+
"base.icp_mail_bounce_alias",
7+
"base.icp_mail_catchall_alias",
8+
"base.icp_mail_default_from",
9+
]
10+
11+
12+
@openupgrade.migrate()
13+
def migrate(env, version):
14+
"""Call disable_invalid_filters in every edition of openupgrade"""
15+
openupgrade.disable_invalid_filters(env)
16+
openupgrade.delete_records_safely_by_xml_id(
17+
env,
18+
_deleted_xml_records,
19+
)

openupgrade_scripts/scripts/base/17.0.1.3/noupdate_changes.xml

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@
1515
<record id="ec" model="res.country">
1616
<field name="zip_required">0</field>
1717
</record>
18-
<record id="es" model="res.country">
18+
<!-- <record id="es" model="res.country">
1919
<field eval="'%(street)s\n%(street2)s\n%(zip)s %(city)s\n%(state_name)s\n%(country_name)s'" name="address_format"/>
20-
</record>
20+
</record> -->
2121
<record id="europe" model="res.country.group">
2222
<field name="name">European Union</field>
2323
</record>
24-
<record id="main_company" model="res.company">
24+
<!-- <record id="main_company" model="res.company">
2525
<field name="currency_id" ref="base.USD"/>
26-
</record>
26+
</record> -->
2727
<record id="nz" model="res.country">
2828
<field name="vat_label">GST</field>
2929
</record>
30+
<record id="res_partner_rule" model="ir.rule">
31+
<field name="domain_force">['|', '|', ('partner_share', '=', False), ('company_id', 'parent_of', company_ids), ('company_id', '=', False)]</field>
32+
</record>
3033
<record id="sl" model="res.country">
3134
<field name="currency_id" ref="SLE"/>
3235
</record>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
2+
# Copyright 2024 Tecnativa - Pedro M. Baeza
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from openupgradelib import openupgrade
6+
7+
_deleted_xml_records = [
8+
"base.res_partner_rule_private_employee",
9+
"base.res_partner_rule_private_group",
10+
]
11+
12+
13+
@openupgrade.migrate()
14+
def migrate(env, version):
15+
openupgrade.load_data(env, "base", "17.0.1.3/noupdate_changes.xml")
16+
openupgrade.delete_records_safely_by_xml_id(
17+
env,
18+
_deleted_xml_records,
19+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
2+
# Copyright 2024 Tecnativa - Pedro M. Baeza
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
4+
import logging
5+
6+
from openupgradelib import openupgrade
7+
8+
from odoo import tools
9+
10+
from odoo.addons.openupgrade_scripts.apriori import merged_modules, renamed_modules
11+
12+
_logger = logging.getLogger(__name__)
13+
14+
_xmlids_renames = [
15+
(
16+
"mail.model_res_users_settings",
17+
"base.model_res_users_settings",
18+
),
19+
(
20+
"mail.access_res_users_settings_all",
21+
"base.access_res_users_settings_all",
22+
),
23+
(
24+
"mail.access_res_users_settings_user",
25+
"base.access_res_users_settings_user",
26+
),
27+
(
28+
"mail.res_users_settings_rule_admin",
29+
"base.res_users_settings_rule_admin",
30+
),
31+
(
32+
"mail.res_users_settings_rule_user",
33+
"base.res_users_settings_rule_user",
34+
),
35+
(
36+
"mail.constraint_res_users_settings_unique_user_id",
37+
"base.constraint_res_users_settings_unique_user_id",
38+
),
39+
]
40+
_column_renames = {
41+
"res_partner": [("display_name", "complete_name")],
42+
}
43+
44+
45+
def _fill_ir_server_object_lines_into_action_server(cr):
46+
openupgrade.logged_query(
47+
cr,
48+
"""
49+
ALTER TABLE ir_act_server
50+
ADD COLUMN IF NOT EXISTS old_ias_id VARCHAR,
51+
ADD COLUMN IF NOT EXISTS evaluation_type VARCHAR,
52+
ADD COLUMN IF NOT EXISTS resource_ref VARCHAR,
53+
ADD COLUMN IF NOT EXISTS selection_value INTEGER,
54+
ADD COLUMN IF NOT EXISTS update_boolean_value VARCHAR,
55+
ADD COLUMN IF NOT EXISTS update_field_id INTEGER,
56+
ADD COLUMN IF NOT EXISTS update_m2m_operation VARCHAR,
57+
ADD COLUMN IF NOT EXISTS update_path VARCHAR,
58+
ADD COLUMN IF NOT EXISTS update_related_model_id INTEGER,
59+
ADD COLUMN IF NOT EXISTS value TEXT;
60+
""",
61+
)
62+
# Update operations
63+
openupgrade.logged_query(
64+
cr,
65+
"""
66+
INSERT INTO ir_act_server
67+
(
68+
old_ias_id,
69+
evaluation_type,
70+
update_field_id,
71+
update_path,
72+
update_related_model_id,
73+
value,
74+
resource_ref,
75+
selection_value,
76+
update_boolean_value,
77+
update_m2m_operation,
78+
binding_type,
79+
state,
80+
type,
81+
usage,
82+
model_id,
83+
name
84+
)
85+
SELECT
86+
ias.id,
87+
CASE
88+
WHEN isol.evaluation_type = 'equation' then 'equation'
89+
ELSE 'value'
90+
END,
91+
imf.id,
92+
imf.name,
93+
im.id,
94+
CASE WHEN isol.evaluation_type = 'equation'
95+
THEN isol.value
96+
ELSE NULL
97+
END,
98+
CASE WHEN imf.ttype in ('many2one', 'many2many')
99+
THEN imf.relation || ',' || isol.value
100+
ELSE NULL
101+
END,
102+
imfs.id,
103+
CASE WHEN imf.ttype = 'boolean'
104+
THEN isol.value::bool
105+
ELSE NULL
106+
END,
107+
'add',
108+
'action',
109+
'object_write',
110+
'ir.actions.server',
111+
'ir_actions_server',
112+
ias.model_id,
113+
ias.name
114+
FROM ir_act_server ias
115+
JOIN ir_server_object_lines isol ON isol.server_id = ias.id
116+
JOIN ir_model_fields imf ON imf.id = isol.col1
117+
LEFT JOIN ir_model im ON im.model = imf.relation
118+
LEFT JOIN ir_model_fields_selection imfs
119+
ON imf.id = imfs.field_id AND imfs.value = isol.value
120+
WHERE ias.state = 'object_write'
121+
RETURNING id, old_ias_id
122+
""",
123+
)
124+
for row in cr.fetchall():
125+
cr.execute(
126+
"""
127+
INSERT INTO rel_server_actions
128+
(action_id, server_id)
129+
VALUES (%s, %s)
130+
""",
131+
(row[0], row[1]),
132+
)
133+
openupgrade.logged_query(
134+
cr,
135+
"""UPDATE ir_act_server ias
136+
SET state = 'multi'
137+
FROM ir_server_object_lines isol
138+
WHERE ias.state = 'object_write'
139+
AND isol.server_id = ias.id
140+
""",
141+
)
142+
# Create operations
143+
openupgrade.logged_query(
144+
cr,
145+
"""UPDATE ir_act_server ias
146+
SET value = isol.value
147+
FROM ir_server_object_lines isol
148+
JOIN ir_model_fields imf ON imf.id = isol.col1
149+
WHERE ias.state = 'object_create'
150+
AND isol.server_id = ias.id
151+
AND isol.evaluation_type = 'value'
152+
AND imf.name = 'name'
153+
""",
154+
)
155+
156+
157+
def _fill_empty_country_codes(cr):
158+
openupgrade.logged_query(
159+
cr,
160+
"""
161+
UPDATE res_country
162+
SET code = 'OU' || id::VARCHAR
163+
WHERE code IS NULL
164+
""",
165+
)
166+
167+
168+
def _handle_partner_private_type(cr):
169+
# Copy private records into a new table
170+
openupgrade.logged_query(
171+
cr,
172+
"""
173+
CREATE TABLE ou_res_partner_private AS
174+
SELECT * FROM res_partner
175+
WHERE type = 'private'
176+
""",
177+
)
178+
# Copy column for preserving the old type values
179+
_column_copies = {"res_partner": [("type", None, None)]}
180+
openupgrade.copy_columns(cr, _column_copies)
181+
# Change contact type and erase sensitive information
182+
query = "type = 'contact'"
183+
for field in [
184+
"street",
185+
"street2",
186+
"city",
187+
"zip",
188+
"vat",
189+
"function",
190+
"phone",
191+
"mobile",
192+
"email",
193+
"website",
194+
"comment",
195+
]:
196+
query += f", {field} = CASE WHEN {field} IS NULL THEN NULL ELSE '*****' END"
197+
openupgrade.logged_query(
198+
cr,
199+
f"""
200+
UPDATE res_partner
201+
SET {query},
202+
country_id = NULL,
203+
state_id = NULL
204+
WHERE type = 'private'
205+
""",
206+
)
207+
208+
209+
@openupgrade.migrate(use_env=False)
210+
def migrate(cr, version):
211+
"""
212+
Don't request an env for the base pre-migration as flushing the env in
213+
odoo/modules/registry.py will break on the 'base' module not yet having
214+
been instantiated.
215+
"""
216+
if "openupgrade_framework" not in tools.config["server_wide_modules"]:
217+
_logger.error(
218+
"openupgrade_framework is not preloaded. You are highly "
219+
"recommended to run the Odoo with --load=openupgrade_framework "
220+
"when migrating your database."
221+
)
222+
openupgrade.update_module_names(cr, renamed_modules.items())
223+
openupgrade.update_module_names(cr, merged_modules.items(), merge_modules=True)
224+
openupgrade.rename_xmlids(cr, _xmlids_renames)
225+
openupgrade.rename_columns(cr, _column_renames)
226+
_fill_ir_server_object_lines_into_action_server(cr)
227+
_fill_empty_country_codes(cr)
228+
_handle_partner_private_type(cr)

0 commit comments

Comments
 (0)