From cdc0ea1e95526df9a1c92b37bd6ac159c0c021ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Vi=E1=BB=87t=20L=C3=A2m?= Date: Fri, 21 Jul 2023 11:55:15 +0700 Subject: [PATCH] [OU-ADD] hr_timesheet (#414) * [MIG] hr_timesheet: migrate 15 to 16 * Update openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/upgrade_analysis_work.txt --------- Co-authored-by: Roy Le <43790414+royleviindoo@users.noreply.github.com> --- docsource/modules150-160.rst | 2 +- .../hr_timesheet/16.0.1.0/pre-migration.py | 76 +++++++++++++++++++ .../16.0.1.0/upgrade_analysis_work.txt | 76 +++++++++++++++++++ 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/pre-migration.py create mode 100644 openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/upgrade_analysis_work.txt diff --git a/docsource/modules150-160.rst b/docsource/modules150-160.rst index cba52b2ff349..b6e2568c82db 100644 --- a/docsource/modules150-160.rst +++ b/docsource/modules150-160.rst @@ -200,7 +200,7 @@ Module coverage 15.0 -> 16.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_skills_survey |Nothing to do |No DB layout changes. | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| hr_timesheet | | | +| hr_timesheet | Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_timesheet_attendance |Nothing to do | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/pre-migration.py b/openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/pre-migration.py new file mode 100644 index 000000000000..d8ae54a14452 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/pre-migration.py @@ -0,0 +1,76 @@ +from openupgradelib import openupgrade + + +def update_rename_field(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE hr_employee + ADD COLUMN IF NOT EXISTS hourly_cost numeric + """, + ) + + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_employee + SET hourly_cost = timesheet_cost + """, + ) + + +def create_ancestor_task_id(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_analytic_line + ADD COLUMN IF NOT EXISTS ancestor_task_id integer + """, + ) + + openupgrade.logged_query( + env.cr, + """ + UPDATE account_analytic_line AS aal + SET ancestor_task_id = pt.ancestor_id + FROM project_task AS pt + WHERE pt.id = aal.task_id + """, + ) + + +def create_manager_id(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE account_analytic_line + ADD COLUMN IF NOT EXISTS manager_id integer + """, + ) + + openupgrade.logged_query( + env.cr, + """ + UPDATE account_analytic_line AS aal + SET manager_id = he.parent_id + FROM hr_employee AS he + WHERE he.id = aal.employee_id + """, + ) + + +def delete_constraint_project_task_create_timesheet_time_positive(env): + openupgrade.delete_sql_constraint_safely( + env, + "hr_timesheet", + "project_task", + "create_timesheet_time_positive", + ) + + +@openupgrade.migrate() +def migrate(env, version): + update_rename_field(env) + create_ancestor_task_id(env) + create_manager_id(env) + delete_constraint_project_task_create_timesheet_time_positive(env) diff --git a/openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..1571b0dadec6 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_timesheet/16.0.1.0/upgrade_analysis_work.txt @@ -0,0 +1,76 @@ +---Models in module 'hr_timesheet'--- +obsolete model project.task.create.timesheet [transient] +new model timesheets.analysis.report [sql_view] + +# NOTHING TO DO + +---Fields in module 'hr_timesheet'--- +hr_timesheet / account.analytic.line / ancestor_task_id (many2one) : NEW relation: project.task, isrelated: related, stored +hr_timesheet / account.analytic.line / manager_id (many2one) : NEW relation: hr.employee, isrelated: related, stored + +# DONE: create column and load data in pre-migration + +hr_timesheet / account.analytic.line / partner_id (False) : module is now 'account' ('hr_timesheet') +hr_timesheet / hr.employee / currency_id (many2one) : module is now 'hr_hourly_cost' ('hr_timesheet') + +# NOTHING TO DO + +hr_timesheet / hr.employee / timesheet_cost (float) : DEL + +# DONE: changed to hourly_cost field in pre-migration + +hr_timesheet / project.project / allocated_hours (float) : NEW + +# NOTHING TO DO: remove in master + +hr_timesheet / project.project / timesheet_count (boolean) : type is now 'integer' ('boolean') + +# NOTHING TO DO: field store = False + +---XML records in module 'hr_timesheet'--- +NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_line_by_project_view_form +NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_line_by_project_view_graph +NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_line_by_project_view_kanban +NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_line_by_project_view_pivot +NEW ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_line_by_project_view_tree +DEL ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_report_form +DEL ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_report_kanban +DEL ir.actions.act_window.view: hr_timesheet.act_hr_timesheet_report_tree +DEL ir.actions.act_window.view: hr_timesheet.timesheet_action_view_report_by_project_form +DEL ir.actions.act_window.view: hr_timesheet.timesheet_action_view_report_by_project_kanban +DEL ir.actions.act_window.view: hr_timesheet.timesheet_action_view_report_by_project_tree +DEL ir.actions.act_window.view: hr_timesheet.timesheet_action_view_report_by_task_form +DEL ir.actions.act_window.view: hr_timesheet.timesheet_action_view_report_by_task_kanban +DEL ir.actions.act_window.view: hr_timesheet.timesheet_action_view_report_by_task_tree +NEW ir.actions.report: hr_timesheet.timesheet_report_task_timesheets +NEW ir.model.access: hr_timesheet.access_timesheets_analysis_report_manager +NEW ir.model.access: hr_timesheet.access_timesheets_analysis_report_user +DEL ir.model.access: hr_timesheet.access_project_task_create_timesheet + +# NOTHING TO DO + +DEL ir.model.constraint: hr_timesheet.constraint_project_task_create_timesheet_time_positive + +# DONE : delete safely in pre-migration + +NEW ir.rule: hr_timesheet.timesheets_analysis_report_comp_rule (noupdate) +NEW ir.ui.view: hr_timesheet.hr_timesheet_report_search +NEW ir.ui.view: hr_timesheet.project_project_view_tree_inherit_sale_project +NEW ir.ui.view: hr_timesheet.project_sharing_project_task_view_search_inherit_timesheet +NEW ir.ui.view: hr_timesheet.project_update_view_search_inherit +NEW ir.ui.view: hr_timesheet.rating_rating_view_search_project_inherited +NEW ir.ui.view: hr_timesheet.report_timesheet_task +NEW ir.ui.view: hr_timesheet.timesheet_project_task_page +NEW ir.ui.view: hr_timesheet.timesheets_analysis_report_graph_employee +NEW ir.ui.view: hr_timesheet.timesheets_analysis_report_graph_project +NEW ir.ui.view: hr_timesheet.timesheets_analysis_report_graph_task +NEW ir.ui.view: hr_timesheet.timesheets_analysis_report_pivot_employee +NEW ir.ui.view: hr_timesheet.timesheets_analysis_report_pivot_project +NEW ir.ui.view: hr_timesheet.timesheets_analysis_report_pivot_task +NEW ir.ui.view: hr_timesheet.view_hr_timesheet_line_graph_by_employee +NEW ir.ui.view: hr_timesheet.view_project_project_filter_inherit_timesheet +NEW ir.ui.view: hr_timesheet.view_task_search_form_hr_extended +DEL ir.ui.view: hr_timesheet.project_sharing_inherit_project_task_view_search +DEL ir.ui.view: hr_timesheet.project_task_create_timesheet_view_form + +# NOTHING TO DO