-
-
Notifications
You must be signed in to change notification settings - Fork 785
[17.0][OU-ADD] analytic: migration to 17.0 #4458
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
Closed
daiduongnguyen-odoo
wants to merge
1
commit into
OCA:17.0
from
daiduongnguyen-odoo:v17_ou_add_analytic
Closed
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 hidden or 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
75 changes: 75 additions & 0 deletions
75
openupgrade_scripts/scripts/analytic/17.0.1.1/post-migration.py
This file contains hidden or 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,75 @@ | ||
| # 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 = ["analytic.analytic_plan_comp_rule"] | ||
|
|
||
|
|
||
| def _analytic_line_create_x_plan_column(env): | ||
| """ | ||
| This method set system parameter for project analytic plan | ||
| and create dynamic field on analytic items using | ||
| '_sync_plan_column' method | ||
| """ | ||
| project_plan = ( | ||
| env.ref("analytic.analytic_plan_projects", raise_if_not_found=False) | ||
| or env["account.analytic.plan"] | ||
| ) | ||
| if project_plan: | ||
| env["ir.config_parameter"].set_param( | ||
| "analytic.project_plan", str(project_plan.id) | ||
| ) | ||
| plans_to_create_fields = env["account.analytic.plan"].search([]) | ||
| (plans_to_create_fields - project_plan)._sync_plan_column() | ||
| for plan in plans_to_create_fields - project_plan: | ||
| if plan.parent_id: | ||
| continue | ||
| column = plan._strict_column_name() | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| f""" | ||
| UPDATE account_analytic_line | ||
| SET {column} = account_id, | ||
| account_id = NULL | ||
| WHERE plan_id = {plan.id}; | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| def _analytic_plan_update_applicability_into_property(env): | ||
| """ | ||
| Manually create ir.property for default_applicability of account.analytic.plan | ||
| """ | ||
| vals_list = [] | ||
| field_id = ( | ||
| env["ir.model.fields"]._get("account.analytic.plan", "default_applicability").id | ||
| ) | ||
| env.cr.execute( | ||
| """ | ||
| SELECT id, default_applicability, company_id FROM account_analytic_plan | ||
| WHERE default_applicability != 'optional' | ||
| """ | ||
| ) | ||
| for plan_id, default_applicability, company_id in env.cr.fetchall(): | ||
| vals_list.append( | ||
| { | ||
| "fields_id": field_id, | ||
| "company_id": company_id, | ||
| "res_id": "account.analytic.plan,%s" % plan_id, | ||
| "name": "default_applicability", | ||
| "value": default_applicability, | ||
| "type": "selection", | ||
| } | ||
| ) | ||
| if vals_list: | ||
| env["ir.property"].create(vals_list) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.delete_records_safely_by_xml_id( | ||
| env, | ||
| _deleted_xml_records, | ||
| ) | ||
| _analytic_line_create_x_plan_column(env) | ||
| _analytic_plan_update_applicability_into_property(env) | ||
40 changes: 40 additions & 0 deletions
40
openupgrade_scripts/scripts/analytic/17.0.1.1/pre-migration.py
This file contains hidden or 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,40 @@ | ||
| # 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 _fill_config_parameter_analytic_project_plan(env): | ||
| env["ir.config_parameter"].set_param("analytic.project_plan", "1") | ||
|
|
||
|
|
||
| def _analytic_applicability_fill_company_id(env): | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| ALTER TABLE account_analytic_applicability | ||
| ADD COLUMN IF NOT EXISTS company_id INTEGER; | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE account_analytic_applicability t1 | ||
| SET company_id = t2.company_id | ||
| FROM account_analytic_plan t2 | ||
| WHERE t1.analytic_plan_id = t2.id | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| _fill_config_parameter_analytic_project_plan(env) | ||
| _analytic_applicability_fill_company_id(env) | ||
| # Drop triagram index on name column of account.analytic.account | ||
| # to avoid error when loading registry, it will be recreated | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| DROP INDEX IF EXISTS account_analytic_account_name_index; | ||
| """, | ||
| ) |
26 changes: 26 additions & 0 deletions
26
openupgrade_scripts/scripts/analytic/17.0.1.1/upgrade_analysis_work.txt
This file contains hidden or 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,26 @@ | ||
| ---Models in module 'analytic'--- | ||
| ---Fields in module 'analytic'--- | ||
| analytic / account.analytic.account / message_main_attachment_id (many2one): DEL relation: ir.attachment | ||
| analytic / account.analytic.account / root_plan_id (many2one) : not a function anymore | ||
| analytic / account.analytic.account / root_plan_id (many2one) : now related | ||
| analytic / account.analytic.plan / _order : _order is now 'sequence asc, id' ('complete_name asc') | ||
| analytic / account.analytic.plan / sequence (integer) : NEW hasdefault: default | ||
| # NOTHING TO DO | ||
|
|
||
| analytic / account.analytic.applicability / company_id (many2one) : NEW relation: res.company, hasdefault: default | ||
| analytic / account.analytic.plan / company_id (many2one) : DEL relation: res.company | ||
| # DONE pre-migration: create column and fill value using company in plan_id | ||
|
|
||
| analytic / account.analytic.line / plan_id (many2one) : DEL relation: account.analytic.plan | ||
| # DONE post-migration: create dynamic x_plan_id column using '_sync_plan_column' method in analytic.plan, pr: https://github.com/odoo/odoo/pull/139225 | ||
|
|
||
| analytic / account.analytic.plan / default_applicability (selection): not stored anymore | ||
| # DONE post-migration: create ir.property if default_applicability != 'optional' | ||
|
|
||
| ---XML records in module 'analytic'--- | ||
| NEW account.analytic.plan: analytic.analytic_plan_projects (noupdate) | ||
| NEW ir.rule: analytic.analytic_applicability_comp_rule (noupdate) | ||
| # NOTHING TO DO | ||
|
|
||
| DEL ir.rule: analytic.analytic_plan_comp_rule (noupdate) | ||
| # DONE post-migration: delete xml-id |
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.
I suggest to use
ir.property#_set_multihere, this also takes care of @acpMicrocom's problemThere 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.
Yeah indeed hehe