Skip to content

Commit

Permalink
[17.0][OU-ADD] account_edi: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
acpMicrocom committed Oct 24, 2024
1 parent 8b49987 commit 057fbd5
Show file tree
Hide file tree
Showing 9 changed files with 551 additions and 11 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,5 @@ jobs:
--db_user=$DB_USERNAME \
--load=base,web,openupgrade_framework \
--log-handler odoo.models.unlink:WARNING \
--test-enable \
--stop-after-init \
--update=$MODULES_NEW
4 changes: 2 additions & 2 deletions docsource/modules160-170.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Module coverage 16.0 -> 17.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| barcodes_gs1_nomenclature | |No DB layout changes. |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| base | | |
| base | Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| base_address_extended | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down Expand Up @@ -864,7 +864,7 @@ Module coverage 16.0 -> 17.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| utm | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| web | | |
| web | Nothing to do | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| web_editor | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ def _remove_table_constraints(env):
"account_edi_document_unique_edi_document_by_move_by_format",
)
openupgrade.delete_sql_constraint_safely(
env,
"account_edi",
"account_edi_format",
"account_edi_format_unique_code",
env, "account_edi", "account_edi_format", "account_edi_format_unique_code"
)


Expand Down
19 changes: 19 additions & 0 deletions openupgrade_scripts/scripts/base/17.0.1.3/end-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade

_deleted_xml_records = [
"base.icp_mail_bounce_alias",
"base.icp_mail_catchall_alias",
"base.icp_mail_default_from",
]


@openupgrade.migrate()
def migrate(env, version):
"""Call disable_invalid_filters in every edition of openupgrade"""
openupgrade.disable_invalid_filters(env)
openupgrade.delete_records_safely_by_xml_id(
env,
_deleted_xml_records,
)
11 changes: 7 additions & 4 deletions openupgrade_scripts/scripts/base/17.0.1.3/noupdate_changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
<record id="ec" model="res.country">
<field name="zip_required">0</field>
</record>
<record id="es" model="res.country">
<!-- <record id="es" model="res.country">
<field eval="'%(street)s\n%(street2)s\n%(zip)s %(city)s\n%(state_name)s\n%(country_name)s'" name="address_format"/>
</record>
</record> -->
<record id="europe" model="res.country.group">
<field name="name">European Union</field>
</record>
<record id="main_company" model="res.company">
<!-- <record id="main_company" model="res.company">
<field name="currency_id" ref="base.USD"/>
</record>
</record> -->
<record id="nz" model="res.country">
<field name="vat_label">GST</field>
</record>
<record id="res_partner_rule" model="ir.rule">
<field name="domain_force">['|', '|', ('partner_share', '=', False), ('company_id', 'parent_of', company_ids), ('company_id', '=', False)]</field>
</record>
<record id="sl" model="res.country">
<field name="currency_id" ref="SLE"/>
</record>
Expand Down
19 changes: 19 additions & 0 deletions openupgrade_scripts/scripts/base/17.0.1.3/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# Copyright 2024 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openupgradelib import openupgrade

_deleted_xml_records = [
"base.res_partner_rule_private_employee",
"base.res_partner_rule_private_group",
]


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(env, "base", "17.0.1.3/noupdate_changes.xml")
openupgrade.delete_records_safely_by_xml_id(
env,
_deleted_xml_records,
)
228 changes: 228 additions & 0 deletions openupgrade_scripts/scripts/base/17.0.1.3/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# Copyright 2024 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging

from openupgradelib import openupgrade

from odoo import tools

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

_logger = logging.getLogger(__name__)

_xmlids_renames = [
(
"mail.model_res_users_settings",
"base.model_res_users_settings",
),
(
"mail.access_res_users_settings_all",
"base.access_res_users_settings_all",
),
(
"mail.access_res_users_settings_user",
"base.access_res_users_settings_user",
),
(
"mail.res_users_settings_rule_admin",
"base.res_users_settings_rule_admin",
),
(
"mail.res_users_settings_rule_user",
"base.res_users_settings_rule_user",
),
(
"mail.constraint_res_users_settings_unique_user_id",
"base.constraint_res_users_settings_unique_user_id",
),
]
_column_renames = {
"res_partner": [("display_name", "complete_name")],
}


def _fill_ir_server_object_lines_into_action_server(cr):
openupgrade.logged_query(
cr,
"""
ALTER TABLE ir_act_server
ADD COLUMN IF NOT EXISTS old_ias_id VARCHAR,
ADD COLUMN IF NOT EXISTS evaluation_type VARCHAR,
ADD COLUMN IF NOT EXISTS resource_ref VARCHAR,
ADD COLUMN IF NOT EXISTS selection_value INTEGER,
ADD COLUMN IF NOT EXISTS update_boolean_value VARCHAR,
ADD COLUMN IF NOT EXISTS update_field_id INTEGER,
ADD COLUMN IF NOT EXISTS update_m2m_operation VARCHAR,
ADD COLUMN IF NOT EXISTS update_path VARCHAR,
ADD COLUMN IF NOT EXISTS update_related_model_id INTEGER,
ADD COLUMN IF NOT EXISTS value TEXT;
""",
)
# Update operations
openupgrade.logged_query(
cr,
"""
INSERT INTO ir_act_server
(
old_ias_id,
evaluation_type,
update_field_id,
update_path,
update_related_model_id,
value,
resource_ref,
selection_value,
update_boolean_value,
update_m2m_operation,
binding_type,
state,
type,
usage,
model_id,
name
)
SELECT
ias.id,
CASE
WHEN isol.evaluation_type = 'equation' then 'equation'
ELSE 'value'
END,
imf.id,
imf.name,
im.id,
CASE WHEN isol.evaluation_type = 'equation'
THEN isol.value
ELSE NULL
END,
CASE WHEN imf.ttype in ('many2one', 'many2many')
THEN imf.relation || ',' || isol.value
ELSE NULL
END,
imfs.id,
CASE WHEN imf.ttype = 'boolean'
THEN isol.value::bool
ELSE NULL
END,
'add',
'action',
'object_write',
'ir.actions.server',
'ir_actions_server',
ias.model_id,
ias.name
FROM ir_act_server ias
JOIN ir_server_object_lines isol ON isol.server_id = ias.id
JOIN ir_model_fields imf ON imf.id = isol.col1
LEFT JOIN ir_model im ON im.model = imf.relation
LEFT JOIN ir_model_fields_selection imfs
ON imf.id = imfs.field_id AND imfs.value = isol.value
WHERE ias.state = 'object_write'
RETURNING id, old_ias_id
""",
)
for row in cr.fetchall():
cr.execute(
"""
INSERT INTO rel_server_actions
(action_id, server_id)
VALUES (%s, %s)
""",
(row[0], row[1]),
)
openupgrade.logged_query(
cr,
"""UPDATE ir_act_server ias
SET state = 'multi'
FROM ir_server_object_lines isol
WHERE ias.state = 'object_write'
AND isol.server_id = ias.id
""",
)
# Create operations
openupgrade.logged_query(
cr,
"""UPDATE ir_act_server ias
SET value = isol.value
FROM ir_server_object_lines isol
JOIN ir_model_fields imf ON imf.id = isol.col1
WHERE ias.state = 'object_create'
AND isol.server_id = ias.id
AND isol.evaluation_type = 'value'
AND imf.name = 'name'
""",
)


def _fill_empty_country_codes(cr):
openupgrade.logged_query(
cr,
"""
UPDATE res_country
SET code = 'OU' || id::VARCHAR
WHERE code IS NULL
""",
)


def _handle_partner_private_type(cr):
# Copy private records into a new table
openupgrade.logged_query(
cr,
"""
CREATE TABLE ou_res_partner_private AS
SELECT * FROM res_partner
WHERE type = 'private'
""",
)
# Copy column for preserving the old type values
_column_copies = {"res_partner": [("type", None, None)]}
openupgrade.copy_columns(cr, _column_copies)
# Change contact type and erase sensitive information
query = "type = 'contact'"
for field in [
"street",
"street2",
"city",
"zip",
"vat",
"function",
"phone",
"mobile",
"email",
"website",
"comment",
]:
query += f", {field} = CASE WHEN {field} IS NULL THEN NULL ELSE '*****' END"
openupgrade.logged_query(
cr,
f"""
UPDATE res_partner
SET {query},
country_id = NULL,
state_id = NULL
WHERE type = 'private'
""",
)


@openupgrade.migrate(use_env=False)
def migrate(cr, version):
"""
Don't request an env for the base pre-migration as flushing the env in
odoo/modules/registry.py will break on the 'base' module not yet having
been instantiated.
"""
if "openupgrade_framework" not in tools.config["server_wide_modules"]:
_logger.error(
"openupgrade_framework is not preloaded. You are highly "
"recommended to run the Odoo with --load=openupgrade_framework "
"when migrating your database."
)
openupgrade.update_module_names(cr, renamed_modules.items())
openupgrade.update_module_names(cr, merged_modules.items(), merge_modules=True)
openupgrade.rename_xmlids(cr, _xmlids_renames)
openupgrade.rename_columns(cr, _column_renames)
_fill_ir_server_object_lines_into_action_server(cr)
_fill_empty_country_codes(cr)
_handle_partner_private_type(cr)
Loading

0 comments on commit 057fbd5

Please sign in to comment.