fix: update Ojol discount calculation to use priceIncl and correctly handle tax inclusion in POS order lines
This commit is contained in:
parent
5e80a2669e
commit
34f17dd13b
Binary file not shown.
Binary file not shown.
@ -28,7 +28,7 @@ patch(PosOrder.prototype, {
|
|||||||
const base = super.getTotalDiscount();
|
const base = super.getTotalDiscount();
|
||||||
const ojolLine = this.lines.find((l) => l.is_ojol_discount);
|
const ojolLine = this.lines.find((l) => l.is_ojol_discount);
|
||||||
if (ojolLine) {
|
if (ojolLine) {
|
||||||
return base + Math.abs(ojolLine.price_unit * ojolLine.qty);
|
return base + Math.abs(ojolLine.priceIncl);
|
||||||
}
|
}
|
||||||
return base;
|
return base;
|
||||||
},
|
},
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import { PosOrder } from "@point_of_sale/app/models/pos_order";
|
import { PosOrder } from "@point_of_sale/app/models/pos_order";
|
||||||
import { patch } from "@web/core/utils/patch";
|
import { patch } from "@web/core/utils/patch";
|
||||||
|
import { accountTaxHelpers } from "@account/helpers/account_tax";
|
||||||
|
|
||||||
patch(PosOrder.prototype, {
|
patch(PosOrder.prototype, {
|
||||||
/**
|
/**
|
||||||
@ -16,7 +17,7 @@ patch(PosOrder.prototype, {
|
|||||||
*/
|
*/
|
||||||
getOjolDiscount() {
|
getOjolDiscount() {
|
||||||
const line = this.getOjolDiscountLine();
|
const line = this.getOjolDiscountLine();
|
||||||
return line ? Math.abs(line.price_unit * line.qty) : 0;
|
return line ? Math.abs(line.priceIncl) : 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,17 +53,36 @@ patch(PosOrder.prototype, {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const taxes = productTmpl.taxes_id || [];
|
||||||
|
const desiredTotal = Math.abs(amount);
|
||||||
|
const company = this.company || this.config.company_id;
|
||||||
|
const taxDetails = accountTaxHelpers.get_tax_details(taxes, desiredTotal, 1.0, {
|
||||||
|
precision_rounding: this.currency.rounding,
|
||||||
|
rounding_method: company?.tax_calculation_rounding_method || "round_per_line",
|
||||||
|
product: productVariant,
|
||||||
|
});
|
||||||
|
|
||||||
|
let sumPriceIncludedTaxes = 0.0;
|
||||||
|
for (const taxData of taxDetails.taxes_data) {
|
||||||
|
if (taxData.tax.price_include) {
|
||||||
|
sumPriceIncludedTaxes += taxData.tax_amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const finalPriceUnit = -(taxDetails.total_excluded + sumPriceIncludedTaxes);
|
||||||
|
|
||||||
// Create negative-price discount line
|
// Create negative-price discount line
|
||||||
this.models["pos.order.line"].create({
|
this.models["pos.order.line"].create({
|
||||||
order_id: this,
|
order_id: this,
|
||||||
product_id: productVariant,
|
product_id: productVariant,
|
||||||
product_tmpl_id: productTmpl,
|
product_tmpl_id: productTmpl,
|
||||||
price_unit: -Math.abs(amount),
|
price_unit: finalPriceUnit,
|
||||||
qty: 1,
|
qty: 1,
|
||||||
discount: 0,
|
discount: 0,
|
||||||
price_type: "manual",
|
price_type: "manual",
|
||||||
full_product_name: "Diskon Ojol",
|
full_product_name: "Diskon Ojol",
|
||||||
is_ojol_discount: true,
|
is_ojol_discount: true,
|
||||||
|
tax_ids: (productTmpl.taxes_id || []).map((tax) => ["link", tax]),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user