This commit is contained in:
seb
2026-10-13 01:30:09 +02:00
parent 97540fb745
commit 8acca998bc
5 changed files with 61 additions and 10 deletions

View File

@@ -62,14 +62,15 @@ async function enrichSingleOrder(store, googleAuthId, order) {
const orderedQuantity = calculateOrderedQuantity(orderLines);
const shippedQuantity = calculateShippedQuantity(shipmentsList);
const allShippings = shippingsList.length > 0 ? shippingsList : shipmentsList.flatMap((s) => s.shippings || []);
const isPaid = orderTotal > 0 && Math.abs(paidTotal - orderTotal) < 0.01;
const isShipped = orderedQuantity > 0 && Math.abs(shippedQuantity - orderedQuantity) < 0.001;
const isDelivered = isShipped || shippingsList.some((s) => s.state === 'shipped' || s.state === 'delivered');
const isDelivered = isShipped || allShippings.some((s) => s.state === 'shipped' || s.state === 'delivered');
return {
...order,
shipping: shippingsList[0] ?? (shipmentsList[0]?.shippings?.[0] ?? null),
shippings: shippingsList.length > 0 ? shippingsList : shipmentsList.flatMap((s) => s.shippings || []),
shippings: allShippings,
payment: paymentsList[0] ?? null,
payments: paymentsList,
shipments: shipmentsList,