fix the discount calculation factor, because the factor is rounded down

This commit is contained in:
admin.suherdy 2025-11-07 22:49:12 +07:00
parent 9ae5b96956
commit f05f7fd47b
2 changed files with 4 additions and 4 deletions

Binary file not shown.

View File

@ -174,9 +174,8 @@ patch(Order.prototype, {
for (const [, amount] of Object.entries(discountablePerTax)) {
totalDiscountableWithoutTax += amount;
}
// Calculate discount factor based on the total discountable amount without tax
const discountFactor = totalDiscountableWithoutTax ? roundPrecision(Math.min(1, maxDiscount / totalDiscountableWithoutTax), this.pos.currency.rounding) : 1;
const discountFactor = totalDiscountableWithoutTax ? Math.min(1, maxDiscount / totalDiscountableWithoutTax) : 1;
const result = Object.entries(discountablePerTax).reduce((lst, entry) => {
if (!entry[1]) {
@ -184,7 +183,8 @@ patch(Order.prototype, {
}
const taxIds = entry[0] === "" ? [] : entry[0].split(",").map((str) => parseInt(str));
// Calculate tax-exclusive discount value for display
const discountAmount = roundPrecision(entry[1] * discountFactor, this.pos.currency.rounding);
const preliminaryAmount = entry[1] * discountFactor;
const discountAmount = roundPrecision(preliminaryAmount, this.pos.currency.rounding);
lst.push({
product: reward.discount_line_product_id,
price: -discountAmount,