Переглянути джерело

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

William Rijksen 6 місяців тому
батько
коміт
430dcb80b0
1 змінених файлів з 4 додано та 3 видалено
  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();
             .getMany();
 
 
         for (const inputLine of input.lines) {
         for (const inputLine of input.lines) {
-            const existingFulfillmentLine = existingFulfillmentLines.find(l =>
+            const fulfillmentLinesForOrderLine = existingFulfillmentLines.filter(l =>
                 idsAreEqual(l.orderLineId, inputLine.orderLineId),
                 idsAreEqual(l.orderLineId, inputLine.orderLineId),
             );
             );
-            if (existingFulfillmentLine) {
+            if (fulfillmentLinesForOrderLine.length) {
+                const fulfilledQuantity = summate(fulfillmentLinesForOrderLine, 'quantity');
                 const unfulfilledQuantity =
                 const unfulfilledQuantity =
-                    existingFulfillmentLine.orderLine.quantity - existingFulfillmentLine.quantity;
+                    fulfillmentLinesForOrderLine[0].orderLine.quantity - fulfilledQuantity;
                 if (unfulfilledQuantity < inputLine.quantity) {
                 if (unfulfilledQuantity < inputLine.quantity) {
                     return true;
                     return true;
                 }
                 }