This commit is contained in:
seb
2026-10-21 11:59:41 +02:00
parent eb1e9e2eb9
commit bb880e3c84
2 changed files with 20 additions and 4 deletions

View File

@@ -253,10 +253,25 @@ async function run() {
shipping: { carrierId: carrier.id, type: 'parcel', state: 'shipped' },
});
const directShipped = shipment2.shippings[0];
// 9b. Import-style: delivered shipment with shipped shipping created atomically
const order3 = await store.order.create(googleAuthId, {
number: 'O-2026-003',
date: new Date().toISOString(),
entityId: customer.id,
lines: [{ sku: trackedArt.sku, name: 'Tracked Article', pu: 1, amount: 1, net: 50, taxrate: 19 }],
});
const shipment3 = await store.shipment.create(googleAuthId, {
orderId: order3.id,
state: 'delivered',
lines: [{ sku: trackedArt.sku, amount: 1 }],
shipping: { carrierId: carrier.id, type: 'parcel', state: 'shipped' },
});
assert.equal(shipment3.shippings[0].state, 'shipped');
assert.equal(directShipped.state, 'shipped');
const artFinal = await store.article.getBySku(googleAuthId, trackedArt.sku);
assert.equal(artFinal.article.warehouses.reduce((sum, w) => sum + w.stock, 0), 5, 'Stock should now be 5 (7 - 2)');
assert.equal(artFinal.article.warehouses.reduce((sum, w) => sum + w.stock, 0), 4, 'Stock should now be 4 (7 - 2 - 1)');
console.log('✓ All order shipping ledger tests passed successfully!');
} finally {

View File

@@ -289,6 +289,10 @@ export default function create(provider) {
ensureTax,
});
// 8b. Create the shipping (carrier) atomically with the shipment. Must run before the
// summary state ('delivered'/'returned') is written, as that would block shipping creation.
await createShipping(googleAuthId, { ...input.shipping, manifestId }, innerTx);
// 9. Synchronize order summary row and shipment summary row
await syncOrderSummary(runner, { companyId, manifestId: orderId });
const validState = input.state && ['new', 'delivered', 'returned'].includes(String(input.state).trim().toLowerCase())
@@ -303,9 +307,6 @@ export default function create(provider) {
state: validState,
});
// 10. Create the shipping (carrier) atomically with the shipment
await createShipping(googleAuthId, { ...input.shipping, manifestId }, innerTx);
return loadShipment(runner, q, companyId, manifestId);
};