Browse Source

fix(core): Correct unfulfilled quantity calc for multiple fulfillment lines per orderline (#3647)

William Rijksen 6 months ago
parent
commit
430dcb80b0
1 changed files with 4 additions and 3 deletions
  1. 4 3
      packages/core/src/service/services/order.service.ts

+ 4 - 3
packages/core/src/service/services/order.service.ts

@@ -1555,12 +1555,13 @@ export class OrderService {
             .getMany();
 
         for (const inputLine of input.lines) {
-            const existingFulfillmentLine = existingFulfillmentLines.find(l =>
+            const fulfillmentLinesForOrderLine = existingFulfillmentLines.filter(l =>
                 idsAreEqual(l.orderLineId, inputLine.orderLineId),
             );
-            if (existingFulfillmentLine) {
+            if (fulfillmentLinesForOrderLine.length) {
+                const fulfilledQuantity = summate(fulfillmentLinesForOrderLine, 'quantity');
                 const unfulfilledQuantity =
-                    existingFulfillmentLine.orderLine.quantity - existingFulfillmentLine.quantity;
+                    fulfillmentLinesForOrderLine[0].orderLine.quantity - fulfilledQuantity;
                 if (unfulfilledQuantity < inputLine.quantity) {
                     return true;
                 }