From 34f17dd13b1ec6ab02d841f66236bb1041c8856f Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 15 Jun 2026 16:48:09 +0700 Subject: [PATCH] fix: update Ojol discount calculation to use priceIncl and correctly handle tax inclusion in POS order lines --- models/__pycache__/__init__.cpython-312.pyc | Bin 339 -> 307 bytes models/__pycache__/pos_order.cpython-312.pyc | Bin 1160 -> 1128 bytes static/src/overrides/models/orderline.js | 2 +- static/src/overrides/models/pos_order.js | 24 +++++++++++++++++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc index 41cb478527fcd846ae56a3317bda666ed6b4fecc..6af4b34fdc3d26cbd5e6be83cac30b350c0f5ac4 100644 GIT binary patch delta 11 Scmcc2w3%tb8AgkVZ_@xB8wCUa delta 43 ycmdnYbeUM$)S{G1{ea4njQqUh{FGGv{FMBBLreXMXVU<6Xb|)O diff --git a/models/__pycache__/pos_order.cpython-312.pyc b/models/__pycache__/pos_order.cpython-312.pyc index 48892d5e1bc16bf3cf869af6a6830823d57c3163..52e0236baa3bfe64f4d8db761cfdc15f57f2e4e5 100644 GIT binary patch delta 14 VcmeC+e8I7yg^AH}^HQeAi~uM61uy^r delta 46 zcmaFC(ZRW)g-J0|KO;XkRlm42Bef`{Qa_-wBqKjBIX@*;KR+cu-_TNjb1TzhMgWs% B5g-5n diff --git a/static/src/overrides/models/orderline.js b/static/src/overrides/models/orderline.js index 4c3ab2f..20620ca 100644 --- a/static/src/overrides/models/orderline.js +++ b/static/src/overrides/models/orderline.js @@ -28,7 +28,7 @@ patch(PosOrder.prototype, { const base = super.getTotalDiscount(); const ojolLine = this.lines.find((l) => l.is_ojol_discount); if (ojolLine) { - return base + Math.abs(ojolLine.price_unit * ojolLine.qty); + return base + Math.abs(ojolLine.priceIncl); } return base; }, diff --git a/static/src/overrides/models/pos_order.js b/static/src/overrides/models/pos_order.js index ee872e4..fc876c4 100644 --- a/static/src/overrides/models/pos_order.js +++ b/static/src/overrides/models/pos_order.js @@ -2,6 +2,7 @@ import { PosOrder } from "@point_of_sale/app/models/pos_order"; import { patch } from "@web/core/utils/patch"; +import { accountTaxHelpers } from "@account/helpers/account_tax"; patch(PosOrder.prototype, { /** @@ -16,7 +17,7 @@ patch(PosOrder.prototype, { */ getOjolDiscount() { 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; } + 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 this.models["pos.order.line"].create({ order_id: this, product_id: productVariant, product_tmpl_id: productTmpl, - price_unit: -Math.abs(amount), + price_unit: finalPriceUnit, qty: 1, discount: 0, price_type: "manual", full_product_name: "Diskon Ojol", is_ojol_discount: true, + tax_ids: (productTmpl.taxes_id || []).map((tax) => ["link", tax]), }); }, }); +