diff --git a/addons/hr_timesheet/migrations/10.0.1.0/openupgrade_analysis_work.txt b/addons/hr_timesheet/migrations/10.0.1.0/openupgrade_analysis_work.txt new file mode 100644 index 000000000000..99014fe802bd --- /dev/null +++ b/addons/hr_timesheet/migrations/10.0.1.0/openupgrade_analysis_work.txt @@ -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 diff --git a/addons/hr_timesheet/migrations/10.0.1.0/post-migration.py b/addons/hr_timesheet/migrations/10.0.1.0/post-migration.py new file mode 100644 index 000000000000..89b5eb59e7e2 --- /dev/null +++ b/addons/hr_timesheet/migrations/10.0.1.0/post-migration.py @@ -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) diff --git a/addons/hr_timesheet/migrations/10.0.1.0/pre-migration.py b/addons/hr_timesheet/migrations/10.0.1.0/pre-migration.py new file mode 100644 index 000000000000..d76a8ec70d84 --- /dev/null +++ b/addons/hr_timesheet/migrations/10.0.1.0/pre-migration.py @@ -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) diff --git a/odoo/openupgrade/doc/source/modules90-100.rst b/odoo/openupgrade/doc/source/modules90-100.rst index 4e9b2859ebf7..f4756e7d0afb 100644 --- a/odoo/openupgrade/doc/source/modules90-100.rst +++ b/odoo/openupgrade/doc/source/modules90-100.rst @@ -157,7 +157,7 @@ missing in the new release are marked with |del|. +-----------------------------------+-----------------------------------+ | |new| hr_recruitment_survey | | +-----------------------------------+-----------------------------------+ -|hr_timesheet | | +|hr_timesheet | Done | +-----------------------------------+-----------------------------------+ | |new| hr_timesheet_attendance | | +-----------------------------------+-----------------------------------+