-
-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[17.0][OU-ADD] base_automation: migration to 17.0 #4459
Open
duong77476-viindoo
wants to merge
1
commit into
OCA:17.0
Choose a base branch
from
duong77476-viindoo:v17_ou_add_base_automation
base: 17.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible that certain models are not yet loaded in the migration and that an error occurs when executing this point.
Maybe move this part to an
end-migrate.py
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be move to end-migrate.
Unfortunately i'm no longer doing migration anymore, at least until next year. Feel free to cherry-pick my commit and create you own if you have to