From 69b1521e2f324ff6a0e846a98bac5836da6ebd91 Mon Sep 17 00:00:00 2001 From: Nam Dao Date: Mon, 23 May 2022 10:32:09 +0700 Subject: [PATCH] [MIG] hr_expense: add migration for 15.0 --- docsource/modules140-150.rst | 2 +- .../hr_expense/15.0.2.0/pre-migration.py | 51 +++++++++++++++++++ .../15.0.2.0/upgrade_analysis_work.txt | 33 ++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 openupgrade_scripts/scripts/hr_expense/15.0.2.0/pre-migration.py create mode 100644 openupgrade_scripts/scripts/hr_expense/15.0.2.0/upgrade_analysis_work.txt diff --git a/docsource/modules140-150.rst b/docsource/modules140-150.rst index 87175d4bc685..706b2ba0144a 100644 --- a/docsource/modules140-150.rst +++ b/docsource/modules140-150.rst @@ -164,7 +164,7 @@ Module coverage 14.0 -> 15.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_contract | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| hr_expense | | | +| hr_expense |Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_fleet | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr_expense/15.0.2.0/pre-migration.py b/openupgrade_scripts/scripts/hr_expense/15.0.2.0/pre-migration.py new file mode 100644 index 000000000000..027b80b4c69f --- /dev/null +++ b/openupgrade_scripts/scripts/hr_expense/15.0.2.0/pre-migration.py @@ -0,0 +1,51 @@ +from openupgradelib import openupgrade + + +def _compute_payment_state(env): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE hr_expense_sheet + ADD COLUMN IF NOT EXISTS payment_state varchar + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense_sheet + SET payment_state = 'not_paid' + WHERE account_move_id IS NULL + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense_sheet expense_sheet + SET payment_state = CASE + WHEN am.payment_state IS NOT NULL THEN am.payment_state + ELSE 'not_paid' + END + FROM account_move am + WHERE + expense_sheet.account_move_id IS NOT NULL + AND am.id = expense_sheet.account_move_id + """, + ) + + +def _compute_currency_id_has_not_value(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense e + SET currency_id = c.currency_id + FROM res_company c + WHERE e.currency_id IS NULL AND c.id = e.company_id + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _compute_currency_id_has_not_value(env) + _compute_payment_state(env) diff --git a/openupgrade_scripts/scripts/hr_expense/15.0.2.0/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr_expense/15.0.2.0/upgrade_analysis_work.txt new file mode 100644 index 000000000000..57c9919b14d2 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_expense/15.0.2.0/upgrade_analysis_work.txt @@ -0,0 +1,33 @@ +---Models in module 'hr_expense'--- +new model hr.expense.approve.duplicate [transient] +---Fields in module 'hr_expense'--- +hr_expense / hr.expense / company_currency_id (many2one): not stored anymore +# NOTHING TO DO + +hr_expense / hr.expense / currency_id (many2one) : now a function +hr_expense / hr.expense / currency_id (many2one) : now required, req_default: function +# DONE: pre-migration: find currency_id has value = False then compute value + +hr_expense / hr.expense.sheet / amount_residual (float) : not a function anymore +hr_expense / hr.expense.sheet / amount_residual (float) : now related +hr_expense / hr.expense.sheet / approval_date (datetime) : NEW +# NOTHING TO DO + +hr_expense / hr.expense.sheet / payment_state (selection) : NEW selection_keys: ['in_payment', 'invoicing_legacy', 'not_paid', 'paid', 'partial', 'reversed'], isfunction: function, stored +# DONE: pre-migration: compute value of payment_state + +---XML records in module 'hr_expense'--- +NEW ir.actions.act_window: hr_expense.hr_expense_approve_duplicate_action +DEL ir.actions.server: hr_expense.action_expense_sheet_register_payment +DEL ir.actions.server: hr_expense.hr_expense_sheet_approve_action_server +DEL ir.actions.server: hr_expense.hr_expense_sheet_post_action_server +DEL ir.actions.server: hr_expense.hr_expense_submit_action_server +NEW ir.model.access: hr_expense.access_hr_expense_approve_duplicate +DEL ir.model.constraint: hr_expense.constraint_hr_expense_sheet_journal_id_required_posted +NEW ir.ui.view: hr_expense.hr_expense_approve_duplicate_view_form +NEW ir.ui.view: hr_expense.product_template_search_view_inherit_hr_expense +DEL ir.ui.view: hr_expense.assets_backend +DEL ir.ui.view: hr_expense.assets_tests +DEL ir.ui.view: hr_expense.view_product_hr_expense_form +NEW product.product: hr_expense.product_product_zero_cost +# NOTHING TO DO: noupdate="0" records