diff --git a/docsource/modules140-150.rst b/docsource/modules140-150.rst index 718c61829e94..369cefde35cc 100644 --- a/docsource/modules140-150.rst +++ b/docsource/modules140-150.rst @@ -176,7 +176,7 @@ Module coverage 14.0 -> 15.0 +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_contract | | | +-------------------------------------------------+----------------------+-------------------------------------------------+ -| hr_expense |Done | | +| hr_expense | Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ | hr_fleet |Done | | +-------------------------------------------------+----------------------+-------------------------------------------------+ diff --git a/openupgrade_scripts/scripts/hr_expense/15.0.2.0/post-migration.py b/openupgrade_scripts/scripts/hr_expense/15.0.2.0/post-migration.py new file mode 100644 index 000000000000..8532a9d53470 --- /dev/null +++ b/openupgrade_scripts/scripts/hr_expense/15.0.2.0/post-migration.py @@ -0,0 +1,36 @@ +from openupgradelib import openupgrade + + +def _fill_payment_state(env): + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense_sheet + SET payment_state = 'not_paid' + WHERE account_move_id IS NULL + """, + ) + # Recompute payment_state for the moves associated to the expenses, as on + # v14 these ones were not computed being of type `entry`, which changes now + # on v15 if the method `_payment_state_matters` returns True, which is the + # case for the expense moves + env["hr.expense.sheet"].search([]).account_move_id._compute_amount() + # Now perform the SQL to transfer the payment_state + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense_sheet hes + SET payment_state = am.payment_state + FROM account_move am + WHERE am.id = hes.account_move_id + """, + ) + + +@openupgrade.migrate() +def migrate(env, version): + _fill_payment_state(env) + openupgrade.load_data(env.cr, "hr_expense", "15.0.2.0/noupdate_changes.xml") + openupgrade.delete_record_translations( + env.cr, "hr_expense", ["hr_expense_template_register"] + ) 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 index 027b80b4c69f..d4db42c1c721 100644 --- 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 @@ -1,38 +1,6 @@ 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, @@ -48,4 +16,7 @@ def _compute_currency_id_has_not_value(env): @openupgrade.migrate() def migrate(env, version): _compute_currency_id_has_not_value(env) - _compute_payment_state(env) + openupgrade.logged_query( + env.cr, + "ALTER TABLE hr_expense_sheet ADD COLUMN IF NOT EXISTS payment_state varchar", + ) 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 index 57c9919b14d2..ffefb619afef 100644 --- 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 @@ -6,7 +6,7 @@ hr_expense / hr.expense / company_currency_id (many2one): not st 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 +# DONE: pre-migration: fill currency_id from the company for empty ones hr_expense / hr.expense.sheet / amount_residual (float) : not a function anymore hr_expense / hr.expense.sheet / amount_residual (float) : now related @@ -14,7 +14,8 @@ 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 +# DONE: pre-migration: Pre-create the column for avoiding the computation +# DONE: post-migration: fill value of payment_state ---XML records in module 'hr_expense'--- NEW ir.actions.act_window: hr_expense.hr_expense_approve_duplicate_action