Skip to content
Closed
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
2 changes: 1 addition & 1 deletion 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
20 changes: 20 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,20 @@
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# Copyright 2022 ForgeFlow S.L. <https://www.forgeflow.com>
# 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,
)
25 changes: 25 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,25 @@
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# Copyright 2023 Hunki Enterprises BV (https://hunki-enterprises.com)
# 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",
]


def _partner_update_complete_name(env):
partners = env["res.partner"].with_context(active_test=False).search([])
partners._compute_complete_name()


@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,
)
_partner_update_complete_name(env)
151 changes: 151 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,151 @@
# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo)
# Copyright 2020 Odoo Community Association (OCA)
# Copyright 2020 Opener B.V. <[email protected]>
# 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.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",
),
]


def _fill_ir_server_object_lines_into_action_server(cr):
openupgrade.logged_query(
cr,
"""
ALTER TABLE ir_act_server
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;
""",
)
openupgrade.logged_query(
cr,
"""
WITH tmp AS (
SELECT t1.id, t1.state, t2.col1, t2.value, t2.evaluation_type,
t3.name AS update_field_name, t3.ttype,
t3.relation, t4.id AS selection_field_id
FROM ir_act_server t1
JOIN ir_server_object_lines t2 on t1.id = t2.server_id
JOIN ir_model_fields t3 on t2.col1 = t3.id
LEFT JOIN ir_model_fields_selection t4 on t3.id = t4.field_id
)
UPDATE ir_act_server ias
SET
update_field_id = CASE
WHEN tmp.state = 'object_create' THEN NULL
WHEN tmp.state = 'object_write' THEN tmp.col1
ELSE NULL
END,
update_path = CASE
WHEN tmp.state = 'object_create' THEN NULL
WHEN tmp.state = 'object_write' THEN tmp.update_field_name
ELSE NULL
END,
update_related_model_id = CASE
WHEN tmp.state = 'object_write' AND tmp.evaluation_type = 'value'
AND tmp.relation IS NOT NULL THEN
(SELECT id FROM ir_model WHERE model=tmp.relation LIMIT 1)
ELSE NULL
END,
update_m2m_operation = 'add',
evaluation_type = CASE
WHEN tmp.evaluation_type = 'value' then 'value'
WHEN tmp.evaluation_type = 'reference' then 'value'
WHEN tmp.evaluation_type = 'equation' then 'equation'
ELSE 'VALUE'
END,
value = tmp.value,
resource_ref = CASE
WHEN tmp.ttype in ('many2one', 'many2many')
THEN tmp.relation || ',' || tmp.value
ELSE NULL
END,
selection_value = CASE
WHEN tmp.ttype = 'selection' THEN tmp.selection_field_id
ELSE NULL
END,
update_boolean_value = CASE
WHEN tmp.ttype = 'boolean' then 'true'
ELSE NULL
END
FROM tmp
WHERE ias.id = tmp.id
""",
)
Comment on lines +55 to +109
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is tricky, since ir_act_server has been modified in v17 to update only 1 field per action (for 'object_create' / 'object_write' state).
The above script does not cover the case where you ir_act_server was updating multiple fields in v16.

I have been scratching my head to find proper way-forward for these cases, but I could not find a solution I am satisfied with.

As a matter of fact with default installation (even with demo), there are only cases for state = 'code' so I guess these other types are mostly linked to base automation module ?

I suppose that for 'object_write' state, we could create multiple actions and link them together in a new ir_act_server with state 'multi'.
For 'object_create' it is more tricky, since you can only define a value (static one) now for 1 field only, so previous action would probably need to be converted to 'code' to get it working in v17. There I am not sure what should be done ? Any idea @pedrobaeza @StefanRijnhart @legalsylvain @MiquelRForgeFlow ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well now look back, i don't understand why i wrote it lol @@@

Copy link
Member

Choose a reason for hiding this comment

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

Handled in #4582 creating always "multi" action server, and converting lines to children actions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, i really want to contribute more but my boss keep doing nonsense :)

Copy link
Member

Choose a reason for hiding this comment

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

No worries, it can be a collaborative work.



def _partner_create_column_complete_name(cr):
openupgrade.logged_query(
cr,
"""
ALTER TABLE res_partner
ADD COLUMN IF NOT EXISTS complete_name VARCHAR;
""",
)


def _update_partner_private_type(cr):
openupgrade.logged_query(
cr,
"""
UPDATE res_partner
SET type = 'contact'
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)
_fill_ir_server_object_lines_into_action_server(cr)
_update_partner_private_type(cr)
_partner_create_column_complete_name(cr)
Loading