Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(inventory): read the default bin for the item the material row is for

Raulbd22921fe3f9
diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.ts
index 60c2b2c247..aa8dd129bc 100644
--- a/packages/database/supabase/functions/get-method/index.ts
+++ b/packages/database/supabase/functions/get-method/index.ts
@@ -1353,9 +1353,15 @@ serve(async (req: Request) => {
scrapQuantity: childScrapQuantity,
estimatedQuantity: childEstimatedQuantity,
storageUnitId: locationId
- ? // @ts-ignore
+ ? // The bin explicitly set on the BOM line stays keyed on the
+ // line, but the default bin belongs to the item this row is
+ // actually for — `itemId`, after any supersession or
+ // configuration swap. Keyed on child.data.itemId a swapped
+ // line took the predecessor's bin, or none when only the
+ // successor had one.
+ // @ts-ignore
(child.data.storageUnitIds?.[locationId] as string) ||
- defaultStorageUnitByItemId.get(child.data.itemId)
+ defaultStorageUnitByItemId.get(itemId)
: undefined,
requiresSerialTracking,
requiresBatchTracking,