diff --git a/docsource/modules160-170.rst b/docsource/modules160-170.rst index 1d26d544f2cb..3f20bc287d7c 100644 --- a/docsource/modules160-170.rst +++ b/docsource/modules160-170.rst @@ -74,7 +74,7 @@ Module coverage 16.0 -> 17.0 +---------------------------------------------------+----------------------+-------------------------------------------------+ | base_address_extended | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ -| base_automation | | | +| base_automation |Done | | +---------------------------------------------------+----------------------+-------------------------------------------------+ | base_geolocalize | | | +---------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/base_automation/17.0.1.0/post-migration.py b/openupgrade_scripts/scripts/base_automation/17.0.1.0/post-migration.py new file mode 100644 index 000000000000..3fc41345d815 --- /dev/null +++ b/openupgrade_scripts/scripts/base_automation/17.0.1.0/post-migration.py @@ -0,0 +1,79 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +def _ir_act_server_update_name_if_base_automation(env): + act_servers = ( + env["ir.actions.server"] + .with_context(active_test=False) + .search([("base_automation_id", "!=", False)]) + ) + if act_servers: + act_servers._compute_name() + + +def _base_automation_update_trigger_fields_ids_if_null(env): + """ + Need to update the trigger_fields_ids if Null for 'on_create_or_write' + or else we will get weird error + Also this is base on hint from + https://github.com/odoo/odoo/pull/114352#issuecomment-1836948745 + """ + base_automations = ( + env["base.automation"] + .with_context(active_test=False) + .search( + [ + ("trigger", "=", "on_create"), + ("trigger_field_ids", "=", False), + ] + ) + ) + if base_automations: + create_date_fields = env["ir.model.fields"].search( + [ + ("model_id", "in", tuple(base_automations.model_id.ids)), + ("name", "=", "create_date"), + ] + ) + for automation in base_automations: + create_date_field = create_date_fields.filtered( + lambda field, automation=automation: field.model_id + == automation.model_id + )[:1] + if create_date_field: + automation.trigger_field_ids = [(4, create_date_field.id)] + + +def _ir_ui_view_remove_inherit_id_from_automation_form(env): + """ + Somehow this inherit_id from ir.actions.server of 'view_base_automation_form' + won't disappear so we need to remove it from here + """ + view = env.ref( + "base_automation.view_base_automation_form", raise_if_not_found=False + ) + if view and view.inherit_id: + view.inherit_id = False + + +def _base_automation_update_deprecate_trigger(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE base_automation + SET trigger = 'on_create_or_write' + WHERE trigger IN ('on_create', 'on_write') + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.load_data(env, "base_automation", "17.0.1.0/noupdate_changes.xml") + _ir_act_server_update_name_if_base_automation(env) + _base_automation_update_trigger_fields_ids_if_null(env) + # Need to update deprecated trigger after add trigger field for 'on_create' trigger + _base_automation_update_deprecate_trigger(env) + _ir_ui_view_remove_inherit_id_from_automation_form(env) diff --git a/openupgrade_scripts/scripts/base_automation/17.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/base_automation/17.0.1.0/pre-migration.py new file mode 100644 index 000000000000..7ffee4807b1f --- /dev/null +++ b/openupgrade_scripts/scripts/base_automation/17.0.1.0/pre-migration.py @@ -0,0 +1,49 @@ +# Copyright 2024 Viindoo Technology Joint Stock Company (Viindoo) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from openupgradelib import openupgrade + + +def _ir_act_server_update_base_automation_id(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE ir_act_server + ADD COLUMN IF NOT EXISTS base_automation_id INTEGER; + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE ir_act_server ias + SET base_automation_id = ba.id + FROM base_automation ba + WHERE ba.action_server_id = ias.id + """, + ) + + +def _base_automation_sync_from_ir_act_server(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE base_automation + ADD COLUMN IF NOT EXISTS model_id INTEGER, + ADD COLUMN IF NOT EXISTS name JSONB; + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE base_automation ba + SET model_id = ias.model_id, + name = ias.name + FROM ir_act_server ias + WHERE ba.action_server_id = ias.id + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _ir_act_server_update_base_automation_id(env) + _base_automation_sync_from_ir_act_server(env) diff --git a/openupgrade_scripts/scripts/base_automation/17.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/base_automation/17.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..acb0682c8e0c --- /dev/null +++ b/openupgrade_scripts/scripts/base_automation/17.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,36 @@ +---Models in module 'base_automation'--- +---Fields in module 'base_automation'--- +base_automation / base.automation / _order : _order is now 'id' ('sequence') +base_automation / base.automation / description (html) : NEW +base_automation / base.automation / log_webhook_calls (boolean) : NEW hasdefault: default +base_automation / base.automation / record_getter (char) : NEW hasdefault: default +base_automation / base.automation / webhook_uuid (char) : NEW +# NOTHING TO DO + +base_automation / base.automation / _inherits : DEL _inherits: {'ir.actions.server': 'action_server_id'} +base_automation / base.automation / action_server_id (many2one) : DEL relation: ir.actions.server, required +base_automation / base.automation / action_server_ids (one2many) : NEW relation: ir.actions.server, hasdefault: compute +base_automation / ir.actions.server / base_automation_id (many2one) : NEW relation: base.automation +# DONE pre-migration: convert m2o to o2m by filling base_automation_id for ir.action.servers + + +base_automation / base.automation / model_id (many2one) : is now stored +base_automation / base.automation / model_id (many2one) : not related anymore +base_automation / base.automation / name (char) : is now stored +base_automation / base.automation / name (char) : not related anymore +# DONE pre-migration: create column and fill value + +base_automation / base.automation / trg_field_ref (many2one_reference): NEW relation: trg_field_ref_model_name, hasdefault: compute +base_automation / base.automation / trg_selection_field_id (many2one): NEW relation: ir.model.fields.selection, hasdefault: compute +# NOTHING TO DO: new feature + +base_automation / base.automation / trigger (selection) : selection_keys is now '['on_archive', 'on_change', 'on_create', 'on_create_or_write', 'on_message_received', 'on_message_sent', 'on_priority_set', 'on_stage_set', 'on_state_set', 'on_tag_set', 'on_time', 'on_time_created', 'on_time_updated', 'on_unarchive', 'on_unlink', 'on_user_set', 'on_webhook', 'on_write']' ('['on_change', 'on_create', 'on_create_or_write', 'on_time', 'on_unlink', 'on_write']') +# DONE post-migration: set 'on_create' and 'on_write' by 'on_create_or_write' + +base_automation / ir.actions.server / name (False) : NEW mode: modify, hasdefault: compute +# DONE post-migration: update name for action that is related to automation using ORM to support translation + +---XML records in module 'base_automation'--- +NEW ir.ui.view: base_automation.ir_actions_server_view_form_automation +NEW ir.ui.view: base_automation.view_base_automation_kanban +# NOTHING TO DO