u
This commit is contained in:
@@ -379,6 +379,29 @@ export async function importOrders({
|
||||
const isSelbstabholer = (shippingType || '').trim().toLowerCase() === 'selbstabholer';
|
||||
const deliveryState = isShipped ? 'delivered' : 'new';
|
||||
|
||||
// Historic orders ship stock that was never booked in; add the shortfall implicitly.
|
||||
const neededBySku = new Map();
|
||||
for (const l of shippableLines) {
|
||||
if (l.sku && l.amount > 0) {
|
||||
neededBySku.set(l.sku, (neededBySku.get(l.sku) || 0) + Number(l.amount));
|
||||
}
|
||||
}
|
||||
for (const [sku, needed] of neededBySku) {
|
||||
const detail = await store.article.getBySku(googleAuthId, sku);
|
||||
const art = detail?.article;
|
||||
if (!art?.track_stock) continue;
|
||||
const available = art.warehouses.find((w) => w.id === defaultWarehouseId)?.stock ?? 0;
|
||||
const shortfall = needed - available;
|
||||
if (shortfall > 0) {
|
||||
await store.stock.adjust(googleAuthId, {
|
||||
sku,
|
||||
warehouseId: defaultWarehouseId,
|
||||
amount: shortfall,
|
||||
text: `Import ${orderNumber}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const trackingCode = isSelbstabholer
|
||||
? ''
|
||||
: cleanValue(m.trackingCode ?? m.tracking_code ?? m.cTracking);
|
||||
|
||||
Reference in New Issue
Block a user