diff --git a/models/__pycache__/__init__.cpython-312.pyc b/models/__pycache__/__init__.cpython-312.pyc index 41cb478..6af4b34 100644 Binary files a/models/__pycache__/__init__.cpython-312.pyc and b/models/__pycache__/__init__.cpython-312.pyc differ diff --git a/models/__pycache__/pos_order.cpython-312.pyc b/models/__pycache__/pos_order.cpython-312.pyc index 48892d5..52e0236 100644 Binary files a/models/__pycache__/pos_order.cpython-312.pyc and b/models/__pycache__/pos_order.cpython-312.pyc differ 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]), }); }, }); +