chore(utils): round to zero credit lines (#13200)
This commit is contained in:
committed by
GitHub
parent
3f53a63822
commit
cbfe646ce1
5
.changeset/lovely-tips-know.md
Normal file
5
.changeset/lovely-tips-know.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/utils": patch
|
||||
---
|
||||
|
||||
chore(utils): round to zero promotions and credit lines
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user