From 1efde9f759f323edbb01041b1ddd6d7e2102cb4e Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 26 May 2026 17:40:15 +0200 Subject: [PATCH] [FIX] hr_expense: don't update product uom when product is invoiced --- .../hr_expense/19.0.2.1/post-migration.py | 34 ++++++++++++++++++- .../tests/data_hr_expense_migration.py | 3 ++ .../tests/test_hr_expense_migration.py | 15 ++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) 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 ad0d5b04320..70b5996243b 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 @@ -3,6 +3,8 @@ from openupgradelib import openupgrade +from odoo.exceptions import ValidationError + def hr_expense_account_move_id(env): """ @@ -55,6 +57,20 @@ def hr_expense_state(env): records._compute_state() +def update_product_uoms(env): + """ + Set updated product uoms if possible + """ + uom = env.ref("uom.product_uom_unit") + for xmlid in ("expense_product_communication", "expense_product_gift"): + product = env.ref(f"hr_expense.{xmlid}") + org_uom = product.uom_id + try: + product.uom_id = uom + except ValidationError: + product.uom_id = org_uom + + deleted_xmlids = [ "hr_expense.hr_expense_report_comp_rule", "hr_expense.ir_rule_hr_expense_sheet_approver", @@ -66,8 +82,24 @@ def hr_expense_state(env): @openupgrade.migrate() def migrate(env, version): - openupgrade.load_data(env, "hr_expense", "19.0.2.1/noupdate_changes.xml") + openupgrade.load_data( + env, + "hr_expense", + "19.0.2.1/noupdate_changes.xml", + xml_transformation=""" + + + """, + ) hr_expense_account_move_id(env) hr_expense_approval_fields(env) hr_expense_state(env) + update_product_uoms(env) openupgrade.delete_records_safely_by_xml_id(env, deleted_xmlids) diff --git a/openupgrade_scripts/scripts/hr_expense/tests/data_hr_expense_migration.py b/openupgrade_scripts/scripts/hr_expense/tests/data_hr_expense_migration.py index 27f918a7dbd..93eddfad75c 100644 --- a/openupgrade_scripts/scripts/hr_expense/tests/data_hr_expense_migration.py +++ b/openupgrade_scripts/scripts/hr_expense/tests/data_hr_expense_migration.py @@ -2,6 +2,9 @@ env.ref("hr_expense.team_building_sheet").action_submit_sheet() env.ref("hr_expense.office_furniture_sheet").action_submit_sheet() env.ref("hr_expense.office_furniture_sheet").action_approve_expense_sheets() +env.ref("hr_expense.lunch_demo_customer_bill_expense").product_id = env.ref( + "hr_expense.expense_product_gift" +) env.ref("hr_expense.customer_meeting_sheet").action_submit_sheet() env.ref("hr_expense.customer_meeting_sheet").action_approve_expense_sheets() env.ref("hr_expense.customer_meeting_sheet").action_sheet_move_post() diff --git a/openupgrade_scripts/scripts/hr_expense/tests/test_hr_expense_migration.py b/openupgrade_scripts/scripts/hr_expense/tests/test_hr_expense_migration.py index 6677e91cd44..d0bfbde7793 100644 --- a/openupgrade_scripts/scripts/hr_expense/tests/test_hr_expense_migration.py +++ b/openupgrade_scripts/scripts/hr_expense/tests/test_hr_expense_migration.py @@ -25,3 +25,18 @@ def test_hr_expense_state(self): self.env.ref("hr_expense.travel_demo_by_car_expense").state, "paid", ) + + def test_product_uoms(self): + """ + Test that expense products' UOMs where updated where possible + """ + self.assertEqual( + self.env.ref("hr_expense.expense_product_gift").uom_id, + self.env.ref("uom.product_uom_km"), + "Gift UOM should not have been changed because it's used in posted move", + ) + self.assertEqual( + self.env.ref("hr_expense.expense_product_communication").uom_id, + self.env.ref("uom.product_uom_unit"), + "Communication UOM should have been updated to unit", + )