From a6cb52e415f77bcfa1b3fc21be676932cb2cfd10 Mon Sep 17 00:00:00 2001 From: seb Date: Fri, 23 Oct 2026 01:56:11 +0200 Subject: [PATCH] u --- src/v1/routes/order.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/v1/routes/order.js b/src/v1/routes/order.js index 8c79d3f..e70757e 100644 --- a/src/v1/routes/order.js +++ b/src/v1/routes/order.js @@ -301,8 +301,21 @@ export async function handleOrder(req, res, next) { // 7. Deliver / Shipment const shouldDeliver = String(order.settings?.deliver ?? '').trim() === '1' || order.deliver === true || order.shipped === true; if (shouldDeliver) { - const warehouses = await store.warehouse.list(googleAuthId).catch(() => []); - const defaultWarehouseId = warehouses[0]?.id || 1; + let warehouses = await store.warehouse.list(googleAuthId).catch(() => []); + let defaultWarehouseId = warehouses[0]?.id; + if (!defaultWarehouseId) { + try { + const createdWh = await store.warehouse.create(googleAuthId, { name: 'Standardlager' }); + defaultWarehouseId = createdWh.id; + emit('warehouse', { companyId }); + } catch { + warehouses = await store.warehouse.list(googleAuthId).catch(() => []); + defaultWarehouseId = warehouses[0]?.id; + } + } + if (!defaultWarehouseId) { + throw new Error('Warehouse not found'); + } const shippableLines = (createdOrder.lines || lines) .filter((l) => l.shippable !== false)