forked from tvtma/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c44562
commit 947d912
Showing
5 changed files
with
143 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
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
73 changes: 73 additions & 0 deletions
73
openupgrade_scripts/scripts/analytic/17.0.1.1/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,73 @@ | ||
# 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: | ||
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) |
35 changes: 35 additions & 0 deletions
35
openupgrade_scripts/scripts/analytic/17.0.1.1/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,35 @@ | ||
# 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 _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): | ||
_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 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 |