-
-
Notifications
You must be signed in to change notification settings - Fork 820
[MIG] hr_timesheet: Migration scripts #944
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
62 changes: 62 additions & 0 deletions
62
addons/hr_timesheet/migrations/10.0.1.0/openupgrade_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,62 @@ | ||
| ---Fields in module 'hr_timesheet'--- | ||
| hr_timesheet / account.analytic.account / use_timesheets (boolean) : DEL | ||
| hr_timesheet / project.project / allow_timesheets (boolean) : NEW | ||
| # Done: Mark projects that have the linked analytic account with the flag | ||
|
|
||
| hr_timesheet / account.analytic.line / is_timesheet (boolean) : DEL | ||
| # Nothing to do | ||
|
|
||
| hr_timesheet / account.analytic.line / project_id (many2one) : NEW relation: project.project | ||
| # Done: Fill this field with the associated project if there's a task or an issue linked to the line | ||
|
|
||
| hr_timesheet / account.analytic.line / task_id (many2one) : previously in module project_timesheet | ||
| # Nothing to do: Already integrated in base | ||
|
|
||
| hr_timesheet / project.project / subtask_project_id (many2one) : NEW relation: project.project | ||
| hr_timesheet / project.task / parent_id (many2one) : NEW relation: project.task | ||
| # Nothing to do: New feature | ||
|
|
||
| hr_timesheet / project.task / timesheet_ids (one2many) : NEW relation: account.analytic.line | ||
| # Nothing to do: One2many field | ||
|
|
||
| ---XML records in module 'hr_timesheet'--- | ||
| NEW ir.actions.act_window: hr_timesheet.act_hr_timesheet_line | ||
| NEW ir.actions.act_window: hr_timesheet.act_hr_timesheet_line_by_project | ||
| NEW ir.actions.act_window: hr_timesheet.act_hr_timesheet_report | ||
| NEW ir.actions.act_window: hr_timesheet.act_project_task_sub_task | ||
| NEW ir.actions.act_window: hr_timesheet.project_task_action_view_timesheet | ||
| DEL ir.actions.act_window: hr_timesheet.act_hr_timesheet_accounts_form | ||
| DEL ir.actions.act_window: hr_timesheet.act_hr_timesheet_line_evry1_all_form | ||
| DEL ir.actions.act_window: hr_timesheet.action_hr_timesheet_report_stat_all | ||
| DEL ir.actions.act_window: hr_timesheet.action_hr_timesheet_report_stat_filtered | ||
| NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_line_view_form | ||
| NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_line_view_tree | ||
| NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_report_form | ||
| NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_report_pivot | ||
| NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_report_tree | ||
| DEL ir.actions.act_window.view: hr_timesheet.action_open_timesheet_tree | ||
| NEW ir.actions.report.xml: hr_timesheet.timesheet_report | ||
| DEL ir.model.access: hr_timesheet.access_hr_timesheet_report | ||
| NEW ir.ui.menu: hr_timesheet.menu_hr_activity_analysis | ||
| NEW ir.ui.menu: hr_timesheet.menu_hr_time_tracking | ||
| NEW ir.ui.menu: hr_timesheet.timesheet_menu_root | ||
| DEL ir.ui.menu: hr_timesheet.menu_hr_timesheet_config | ||
| DEL ir.ui.menu: hr_timesheet.menu_hr_timesheet_report_all | ||
| NEW ir.ui.view: hr_timesheet.project_invoice_form | ||
| NEW ir.ui.view: hr_timesheet.project_project_view_form_simplified_inherit_timesheet | ||
| NEW ir.ui.view: hr_timesheet.report_timesheet | ||
| NEW ir.ui.view: hr_timesheet.view_hr_timesheet_line_pivot | ||
| NEW ir.ui.view: hr_timesheet.view_project_kanban_inherited | ||
| NEW ir.ui.view: hr_timesheet.view_task_form2_inherited | ||
| NEW ir.ui.view: hr_timesheet.view_task_kanban_inherited_progress | ||
| NEW ir.ui.view: hr_timesheet.view_task_tree2_inherited | ||
| DEL ir.ui.view: hr_timesheet.view_hr_timesheet_report_graph | ||
| DEL ir.ui.view: hr_timesheet.view_hr_timesheet_report_pivot | ||
| DEL ir.ui.view: hr_timesheet.view_hr_timesheet_report_search | ||
| # Nothing to do: noupdate=0 records | ||
|
|
||
| NEW res.groups: hr_timesheet.group_hr_timesheet_user | ||
| # Nothing to do: There's no way to know which users will need this new group | ||
|
|
||
| NEW res.users: base.default_user | ||
| # Nothing to do: It's not really a new group |
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 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2017 Tecnativa - Pedro M. Baeza | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
|
|
||
| def migrate_allow_timesheets(env): | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE project_project pp | ||
| SET allow_timesheets = True | ||
| FROM account_analytic_account aaa | ||
| WHERE aaa.id = pp.analytic_account_id | ||
| AND aaa.%s = True | ||
| """ % openupgrade.get_legacy_name('use_timesheets'), | ||
| ) | ||
|
|
||
|
|
||
| def migrate_missing_projects(env): | ||
| """Create a project and link it to the orphaned analytic accounts""" | ||
| env.cr.execute( | ||
| """ | ||
| SELECT aaa.id, aaa.company_id, aaa.name | ||
| FROM account_analytic_account aaa | ||
| LEFT JOIN project_project pp ON pp.analytic_account_id = aaa.id | ||
| WHERE %s = True | ||
| AND pp.id IS NULL | ||
| """ % | ||
| openupgrade.get_legacy_name('use_timesheets') | ||
| ) | ||
| aaa_rows = env.cr.fetchall() | ||
| project_obj = env['project.project'] | ||
| for aaa_row in aaa_rows: | ||
| # It's easier to create the project via ORM | ||
| project_obj.create({ | ||
| 'analytic_account_id': aaa_row[0], | ||
| 'company_id': aaa_row[1], | ||
| 'name': aaa_row[2], | ||
| 'allow_timesheets': True, | ||
| }) | ||
|
|
||
|
|
||
| def fill_analytic_line_project(env): | ||
| """Fill project with the linked one in the related task or issue.""" | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE account_analytic_line aal | ||
| SET project_id = pt.project_id | ||
| FROM project_task pt | ||
| WHERE pt.id = aal.task_id | ||
| AND pt.project_id IS NOT NULL | ||
| AND aal.project_id IS NULL | ||
| """, | ||
| ) | ||
| openupgrade.logged_query( | ||
| env.cr, | ||
| """ | ||
| UPDATE account_analytic_line aal | ||
| SET project_id = pi.project_id | ||
| FROM project_issue pi | ||
| WHERE pi.id = aal.issue_id | ||
| AND pi.project_id IS NOT NULL | ||
| AND aal.project_id IS NULL | ||
| """, | ||
| ) | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| migrate_allow_timesheets(env) | ||
| migrate_missing_projects(env) | ||
| fill_analytic_line_project(env) | ||
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,16 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2017 Tecnativa - Pedro M. Baeza | ||
| # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
|
||
| from openupgradelib import openupgrade | ||
|
|
||
| COLUMN_RENAMES = { | ||
| 'account_analytic_account': [ | ||
| ('use_timesheets', None), | ||
| ] | ||
| } | ||
|
|
||
|
|
||
| @openupgrade.migrate() | ||
| def migrate(env, version): | ||
| openupgrade.rename_columns(env.cr, COLUMN_RENAMES) |
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
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.
the
migrate_missing_projectsmethod is missing