From d74fa661fad2d83483d23e935836165359c0a1d2 Mon Sep 17 00:00:00 2001 From: HafidBuroiroh Date: Tue, 27 Jan 2026 09:47:05 +0700 Subject: cashback brand done --- indoteknik_custom/models/sale_order_line.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 7b97bd85..c9e75fc7 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -213,12 +213,13 @@ class SaleOrderLine(models.Model): sales_price -= line.delivery_amt_line # if line.order_id.fee_third_party > 0: # sales_price -= line.fee_third_party_line - if line.amount_cashback > 0: - sales_price += line.amount_cashback purchase_price = line.purchase_price if line.purchase_tax_id.price_include: - purchase_price = line.purchase_price / 1.11 + purchase_price = line.purchase_price / (1 + (line.purchase_tax_id.amount / 100)) + + if line.amount_cashback > 0: + purchase_price = purchase_price - line.amount_cashback purchase_price = purchase_price * line.product_uom_qty margin_per_item = sales_price - purchase_price @@ -252,7 +253,7 @@ class SaleOrderLine(models.Model): def _compute_cashback_brand(self): for line in self: - line.amount_cashback = 0 + line.amount_cashback = 0 if not line.product_id: continue @@ -261,8 +262,18 @@ class SaleOrderLine(models.Model): if cashback_percent <= 0: continue - price, taxes, vendor_id = self._get_purchase_price(line.product_id) - line.amount_cashback = price * cashback_percent + price, taxes, vendor = self._get_purchase_price(line.product_id) + + price_tax_excl = price + + if taxes: + tax = self.env['account.tax'].browse(taxes) + if tax.price_include: + price_tax_excl = price / (1 + (tax.amount / 100)) + else: + price_tax_excl = price + + line.amount_cashback = price_tax_excl * cashback_percent # @api.onchange('vendor_id') # def onchange_vendor_id(self): -- cgit v1.2.3