chore(utils): round to zero credit lines (#13200)

This commit is contained in:
Carlos R. L. Rodrigues
2025-08-15 11:43:52 -03:00
committed by GitHub
parent 3f53a63822
commit cbfe646ce1
3 changed files with 22 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/utils": patch
---
chore(utils): round to zero promotions and credit lines

View File

@@ -1,7 +1,7 @@
import { BigNumberInput } from "@medusajs/types"
import { isDefined } from "../../common"
import { BigNumber } from "../big-number"
import { MathBN } from "../math"
import { MathBN, MEDUSA_EPSILON } from "../math"
export function calculateCreditLinesTotal({
creditLines,
@@ -46,9 +46,10 @@ export function calculateCreditLinesTotal({
}
}
const isZero = MathBN.lte(creditLinesTotal, MEDUSA_EPSILON)
return {
creditLinesTotal,
creditLinesSubtotal,
creditLinesTaxTotal,
creditLinesTotal: isZero ? MathBN.convert(0) : creditLinesTotal,
creditLinesSubtotal: isZero ? MathBN.convert(0) : creditLinesSubtotal,
creditLinesTaxTotal: isZero ? MathBN.convert(0) : creditLinesTaxTotal,
}
}

View File

@@ -108,7 +108,12 @@ export function calculateAdjustmentAmountFromPromotion(
lineItemsAmount
)
return MathBN.min(promotionValue, applicableAmount)
const returnValue = MathBN.min(promotionValue, applicableAmount)
if (MathBN.lte(returnValue, MEDUSA_EPSILON)) {
return MathBN.convert(0)
}
return returnValue
}
/*
@@ -157,5 +162,10 @@ export function calculateAdjustmentAmountFromPromotion(
lineItemsAmount
)
return MathBN.min(promotionValue, applicableAmount)
const returnValue = MathBN.min(promotionValue, applicableAmount)
if (MathBN.lte(returnValue, MEDUSA_EPSILON)) {
return MathBN.convert(0)
}
return returnValue
}