fix(medusa): Discount allocation precision issues (#3244)
This commit is contained in:
@@ -172,8 +172,7 @@ export default class NewTotalsService extends TransactionBaseService {
|
||||
subtotal = 0 // in that case we need to know the tax rate to compute it later
|
||||
}
|
||||
|
||||
const discount_total =
|
||||
(lineItemAllocation.discount?.unit_amount || 0) * item.quantity
|
||||
const discount_total = lineItemAllocation.discount?.amount ?? 0
|
||||
|
||||
const totals: LineItemTotals = {
|
||||
unit_price: item.unit_price,
|
||||
@@ -275,8 +274,7 @@ export default class NewTotalsService extends TransactionBaseService {
|
||||
subtotal = 0 // in that case we need to know the tax rate to compute it later
|
||||
}
|
||||
|
||||
const discount_total =
|
||||
(lineItemAllocation.discount?.unit_amount || 0) * item.quantity
|
||||
const discount_total = lineItemAllocation.discount?.amount ?? 0
|
||||
|
||||
const totals: LineItemTotals = {
|
||||
unit_price: item.unit_price,
|
||||
@@ -428,8 +426,7 @@ export default class NewTotalsService extends TransactionBaseService {
|
||||
)
|
||||
|
||||
const discountAmount =
|
||||
(calculationContext.allocation_map[lineItem.id]?.discount?.unit_amount ||
|
||||
0) * lineItem.quantity
|
||||
calculationContext.allocation_map[lineItem.id]?.discount?.amount ?? 0
|
||||
|
||||
const lineSubtotal =
|
||||
(lineItem.unit_price - taxAmountIncludedInPrice) * lineItem.quantity -
|
||||
|
||||
@@ -462,12 +462,18 @@ class TotalsService extends TransactionBaseService {
|
||||
if (allocationMap[ld.item.id]) {
|
||||
allocationMap[ld.item.id].discount = {
|
||||
amount: adjustmentAmount,
|
||||
/**
|
||||
* Used for the refund computation
|
||||
*/
|
||||
unit_amount: Math.round(adjustmentAmount / ld.item.quantity),
|
||||
}
|
||||
} else {
|
||||
allocationMap[ld.item.id] = {
|
||||
discount: {
|
||||
amount: adjustmentAmount,
|
||||
/**
|
||||
* Used for the refund computation
|
||||
*/
|
||||
unit_amount: Math.round(adjustmentAmount / ld.item.quantity),
|
||||
},
|
||||
}
|
||||
@@ -794,8 +800,7 @@ class TotalsService extends TransactionBaseService {
|
||||
subtotal = 0 // in that case we need to know the tax rate to compute it later
|
||||
}
|
||||
|
||||
const discount_total =
|
||||
(lineItemAllocation.discount?.unit_amount || 0) * lineItem.quantity
|
||||
const discount_total = lineItemAllocation.discount?.amount ?? 0
|
||||
|
||||
const lineItemTotals: LineItemTotals = {
|
||||
unit_price: lineItem.unit_price,
|
||||
|
||||
@@ -73,9 +73,7 @@ class TaxCalculationStrategy implements ITaxCalculationStrategy {
|
||||
taxableAmount = item.unit_price * item.quantity
|
||||
}
|
||||
|
||||
taxableAmount -=
|
||||
((allocations.discount && allocations.discount.unit_amount) || 0) *
|
||||
item.quantity
|
||||
taxableAmount -= allocations.discount?.amount ?? 0
|
||||
|
||||
for (const filteredTaxLine of filteredTaxLines) {
|
||||
taxTotal += Math.round(
|
||||
|
||||
Reference in New Issue
Block a user