diff --git a/openupgrade_scripts/scripts/hr_expense/19.0.2.1/post-migration.py b/openupgrade_scripts/scripts/hr_expense/19.0.2.1/post-migration.py index 3ed6bbc3c2b..3d46417e425 100644 --- a/openupgrade_scripts/scripts/hr_expense/19.0.2.1/post-migration.py +++ b/openupgrade_scripts/scripts/hr_expense/19.0.2.1/post-migration.py @@ -47,6 +47,60 @@ def hr_expense_approval_fields(env): ) +def hr_expense_sheet_compatibility(env): + """ + We update the statuses of the hr.expense.sheet records to match those of + hr_expense_sheet (to ensure consistency with the statuses of hr.expense) + """ + openupgrade.map_values( + env.cr, + openupgrade.get_legacy_name("state"), + "state", + [ + ("submit", "submitted"), + ("approve", "approved"), + ("cancel", "refused"), + ], + table="hr_expense_sheet", + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense_sheet + SET state = 'posted' + WHERE state = 'post' AND payment_state = 'not_paid' + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense_sheet + SET state = 'in_payment' + WHERE state = 'post' AND payment_state = 'partial' + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE hr_expense_sheet + SET state = 'paid' + WHERE state = 'post' AND payment_state IN ('paid', 'reversed') + """, + ) + openupgrade.map_values( + env.cr, + openupgrade.get_legacy_name("approval_state"), + "approval_state", + [ + ("submit", "submitted"), + ("approve", "approved"), + ("post", "posted"), + ("cancel", "refused"), + ], + table="hr_expense_sheet", + ) + + def update_product_uoms(env): """ Set updated product uoms if possible @@ -80,5 +134,6 @@ def migrate(env, version): ) hr_expense_account_move_id(env) hr_expense_approval_fields(env) + hr_expense_sheet_compatibility(env) update_product_uoms(env) openupgrade.delete_records_safely_by_xml_id(env, deleted_xmlids) diff --git a/openupgrade_scripts/scripts/hr_expense/19.0.2.1/pre-migration.py b/openupgrade_scripts/scripts/hr_expense/19.0.2.1/pre-migration.py index a0b98ffb47c..52a9704b2c4 100644 --- a/openupgrade_scripts/scripts/hr_expense/19.0.2.1/pre-migration.py +++ b/openupgrade_scripts/scripts/hr_expense/19.0.2.1/pre-migration.py @@ -8,12 +8,21 @@ ("department_id", "hr.expense", "hr_expense", "many2one", None, "hr_expense"), ] -renamed_fields = [ - ("hr.expense", "hr_expense", "sheet_id", "former_sheet_id"), -] +renamed_fields = [] copied_columns = { - "hr_expense": [("state", None, None)], + "hr_expense": [ + ("state", None, None), + # It is important NOT to rename the sheet_id field because the hr_expense_sheet + # module will continue to use that field + ("sheet_id", "former_sheet_id", None), + ], + "hr_expense_sheet": [ + ("state", None, None), + ("approval_state", None, None), + ("user_id", "manager_id", None), + ("total_tax_amount", "tax_amount", None), + ], } diff --git a/openupgrade_scripts/scripts/hr_expense/19.0.2.1/upgrade_analysis_work.txt b/openupgrade_scripts/scripts/hr_expense/19.0.2.1/upgrade_analysis_work.txt index 32148f99f1c..d43c2361c33 100644 --- a/openupgrade_scripts/scripts/hr_expense/19.0.2.1/upgrade_analysis_work.txt +++ b/openupgrade_scripts/scripts/hr_expense/19.0.2.1/upgrade_analysis_work.txt @@ -46,6 +46,8 @@ hr_expense / hr.expense / state (selection) : select # DONE: recompute state for records in states 'done', 'reported' hr_expense / hr.expense / untaxed_amount (float) : NEW isfunction: function, stored + +# DONE: hr_expense_sheet compatibility hr_expense / hr.expense.sheet / account_move_ids (one2many) : DEL relation: account.move hr_expense / hr.expense.sheet / accounting_date (date) : DEL hr_expense / hr.expense.sheet / activity_ids (one2many) : DEL relation: mail.activity