-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OU-ADD] base_automation: migration to 17.0
- Loading branch information
1 parent
9279df1
commit 2451dd0
Showing
4 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
openupgrade_scripts/scripts/base_automation/17.0.1.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
49 changes: 49 additions & 0 deletions
49
openupgrade_scripts/scripts/base_automation/17.0.1.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
36 changes: 36 additions & 0 deletions
36
openupgrade_scripts/scripts/base_automation/17.0.1.0/upgrade_analysis_work.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |