From ffa53982d7108e1cd2f8411ceb2dcffef981418f Mon Sep 17 00:00:00 2001 From: Samy Mostafa Shaawat Date: Mon, 19 Oct 2026 15:00:42 +0300 Subject: [PATCH] [FIX] repair: orders on a location without warehouse kept the temporary records Repair orders whose location_id has no warehouse (e.g. a customer location) were not matched by the picking type update, so they still pointed to the temporary location when it was deleted, which fails on the NOT NULL location_dest_id. Fall back to the first warehouse of the company. --- .../scripts/repair/17.0.1.0/post-migration.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/openupgrade_scripts/scripts/repair/17.0.1.0/post-migration.py b/openupgrade_scripts/scripts/repair/17.0.1.0/post-migration.py index ed490b75b4c1..7764baf55d36 100644 --- a/openupgrade_scripts/scripts/repair/17.0.1.0/post-migration.py +++ b/openupgrade_scripts/scripts/repair/17.0.1.0/post-migration.py @@ -207,6 +207,29 @@ def fill_repair_picking_type(env): WHERE ro.location_id = sl.id """, ) + # Repair orders whose location doesn't belong to any warehouse + # (e.g. a customer location) still point to the temporary records, + # so fall back to the first warehouse of their company + openupgrade.logged_query( + env.cr, + """ + UPDATE repair_order ro + SET picking_type_id = sw.repair_type_id, + location_dest_id = spt.default_location_dest_id, + parts_location_id = spt.default_remove_location_dest_id, + recycle_location_id = spt.default_recycle_location_dest_id + FROM stock_picking_type tmp, ( + SELECT DISTINCT ON (company_id) company_id, repair_type_id + FROM stock_warehouse + WHERE repair_type_id IS NOT NULL + ORDER BY company_id, id + ) sw + JOIN stock_picking_type spt ON spt.id = sw.repair_type_id + WHERE tmp.name->>'en_US' = 'SPT Repair OpenUpgrade' + AND ro.picking_type_id = tmp.id + AND ro.company_id = sw.company_id + """, + ) # Remove the temporary location and picking type # created during the migration env["stock.location"].search(