This commit is contained in:
seb
2026-10-23 01:56:11 +02:00
parent 36a135011f
commit a6cb52e415

View File

@@ -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)