From d0d2ea4f201e94ae876639a6b25fdcac5779c8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frane=20Poli=C4=87?= <16856471+fPolic@users.noreply.github.com> Date: Tue, 25 Mar 2025 19:14:44 +0100 Subject: [PATCH] fix(order): caculate received total for pending difference (#11919) **What** - use the return received total to compute pending difference with return requested total **Why** - this would show incorrect outstanding amount when receiving a return and also, the outstanding amount after the return is received would be incorrect --- .../order/src/utils/calculate-order-change.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/modules/order/src/utils/calculate-order-change.ts b/packages/modules/order/src/utils/calculate-order-change.ts index 5fe01168cf..7c7876bd60 100644 --- a/packages/modules/order/src/utils/calculate-order-change.ts +++ b/packages/modules/order/src/utils/calculate-order-change.ts @@ -246,16 +246,25 @@ export class OrderChangeProcessing { orderSummary.transaction_total ) - // return requested becomes pending difference + // return total becomes pending difference for (const item of order.items ?? []) { const item_ = item as any - if (MathBN.gt(item_.return_requested_total, 0)) { - orderSummary.pending_difference = MathBN.sub( - orderSummary.pending_difference, - item_.return_requested_total - ) - } + ;[ + "return_requested_total", + "return_received_total", + // TODO: revisit this when we settle on which dismissed items need to be refunded + // "return_dismissed_total", + ].forEach((returnTotalKey) => { + const returnTotal = item_[returnTotalKey] + + if (MathBN.gt(returnTotal, 0)) { + orderSummary.pending_difference = MathBN.sub( + orderSummary.pending_difference, + returnTotal + ) + } + }) } orderSummary.pending_difference = new BigNumber( orderSummary.pending_difference