Skip to content

Commit

Permalink
Remove discount decimal repeated computations (#155)
Browse files Browse the repository at this point in the history
Co-authored-by: José Carneiro <[email protected]>
  • Loading branch information
josecarneiro and José Carneiro authored Jan 2, 2025
1 parent a8d4e75 commit 5e7b4ed
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
16 changes: 1 addition & 15 deletions src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,10 @@ export const computePriceItem = (
before_discount_unit_amount: itemValues.before_discount_unit_amount,
}),
...(Number.isInteger(itemValues.unit_discount_amount) && { unit_discount_amount: itemValues.unit_discount_amount }),
...(itemValues.unit_discount_amount_decimal && {
unit_discount_amount_decimal: itemValues.unit_discount_amount_decimal,
}),
...(Number.isInteger(itemValues.unit_amount_net) && { unit_amount_net: itemValues.unit_amount_net }),
...(Number.isInteger(itemValues.unit_discount_amount_net) && {
unit_discount_amount_net: itemValues.unit_discount_amount_net,
}),
...(itemValues.unit_discount_amount_net_decimal && {
unit_discount_amount_net_decimal: itemValues.unit_discount_amount_net_decimal,
}),
...(Number.isInteger(itemValues.unit_amount_gross) && { unit_amount_gross: itemValues.unit_amount_gross }),
...(price?.pricing_model === PricingModel.perUnit &&
unitAmountDecimal && { unit_amount_decimal: unitAmountDecimal }),
Expand All @@ -860,18 +854,10 @@ export const computePriceItem = (
before_discount_amount_total: itemValues.before_discount_amount_total,
}),
amount_tax: itemValues.amount_tax,
...(Number.isInteger(itemValues.tax_discount_amount) && {
tax_discount_amount: itemValues.tax_discount_amount,
}),
...(itemValues.tax_discount_amount_decimal && {
tax_discount_amount_decimal: itemValues.tax_discount_amount_decimal,
}),
...(Number.isInteger(itemValues.tax_discount_amount) && { tax_discount_amount: itemValues.tax_discount_amount }),
...(Number.isInteger(itemValues.before_discount_tax_amount) && {
before_discount_tax_amount: itemValues.before_discount_tax_amount,
}),
...(itemValues.before_discount_tax_amount_decimal && {
before_discount_tax_amount_decimal: itemValues.before_discount_tax_amount_decimal,
}),
...(itemValues.tiers_details && {
tiers_details: itemValues.tiers_details.map((tier) => ({
quantity: tier.quantity,
Expand Down
4 changes: 0 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,10 @@ export const applyDiscounts = (
amount_total: afterDiscountUnitAmountGross.multiply(unitAmountMultiplier).getAmount(),
amount_tax: afterDiscountTaxAmount.getAmount(),
unit_discount_amount: unitDiscountAmount.getAmount(),
unit_discount_amount_decimal: unitDiscountAmount.toUnit().toString(),
before_discount_unit_amount: isTaxInclusive ? unitAmountGross.getAmount() : unitAmountNet.getAmount(),
unit_discount_amount_net: unitDiscountAmountNet.getAmount(),
unit_discount_amount_net_decimal: unitDiscountAmountNet.toUnit().toString(),
tax_discount_amount: taxDiscountAmount.getAmount(),
tax_discount_amount_decimal: taxDiscountAmount.toUnit().toString(),
before_discount_tax_amount: beforeDiscountTaxAmount.multiply(unitAmountMultiplier).getAmount(),
before_discount_tax_amount_decimal: beforeDiscountTaxAmount.toUnit().toString(),
discount_amount: unitDiscountAmount.multiply(unitAmountMultiplier).getAmount(),
discount_percentage: discountPercentage,
before_discount_amount_total: unitAmountGross.multiply(unitAmountMultiplier).getAmount(),
Expand Down

0 comments on commit 5e7b4ed

Please sign in to comment.