Skip to content

Commit

Permalink
[FIX] sale_triple_discount: Fixed tax amount on report
Browse files Browse the repository at this point in the history
  • Loading branch information
toita86 committed Oct 1, 2024
1 parent 25ead28 commit 5093d3d
Showing 1 changed file with 55 additions and 20 deletions.
75 changes: 55 additions & 20 deletions sale_triple_discount/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# Copyright 2017 - 2019 Alex Comba - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from functools import partial

from odoo import api, models
from odoo.tools import formatLang


class SaleOrder(models.Model):
Expand All @@ -17,24 +20,56 @@ def _amount_all(self):
super()._amount_all()
self.env["sale.order.line"].triple_discount_postprocess(prev_values)

def _get_tax_amount_by_group(self):
def _amount_by_group(self):
super()._amount_by_group()

# Copy/paste from standard method in sale
self.ensure_one()
res = {}
for line in self.order_line:
price_reduce = line.price_reduce # changed
taxes = line.tax_id.compute_all(
price_reduce,
quantity=line.product_uom_qty,
product=line.product_id,
partner=self.partner_shipping_id,
)["taxes"]
for tax in line.tax_id:
group = tax.tax_group_id
res.setdefault(group, 0.0)
for t in taxes:
if t["id"] == tax.id or t["id"] in tax.children_tax_ids.ids:
res[group] += t["amount"]
res = sorted(list(res.items()), key=lambda l: l[0].sequence)
res = [(line[0].name, line[1]) for line in res]
return res
for order in self:
currency = order.currency_id or order.company_id.currency_id
fmt = partial(
formatLang,
self.with_context(lang=order.partner_id.lang).env,
currency_obj=currency,
)
res = {}

for line in order.order_line:
# Use price_reduce for tax computation
line._get_price_reduce()
price_reduce = line.price_reduce # This line is adapted

# Calculate taxes based on price_reduce
taxes = line.tax_id.compute_all(
price_reduce,
quantity=line.product_uom_qty,
product=line.product_id,
partner=order.partner_shipping_id,
)["taxes"]

for tax in line.tax_id:
group = tax.tax_group_id
res.setdefault(group, {"amount": 0.0, "base": 0.0})

for t in taxes:
if t["id"] == tax.id or t["id"] in tax.children_tax_ids.ids:
res[group]["amount"] += t["amount"]
res[group]["base"] += t["base"]

res = sorted(res.items(), key=lambda l: l[0].sequence)

# Round amount and prevent -0.00
for group_data in res:
group_data[1]["amount"] = currency.round(group_data[1]["amount"]) + 0.0
group_data[1]["base"] = currency.round(group_data[1]["base"]) + 0.0

order.amount_by_group = [
(
line[0].name,
line[1]["amount"],
line[1]["base"],
fmt(line[1]["amount"]),
fmt(line[1]["base"]),
len(res),
)
for line in res
]

0 comments on commit 5093d3d

Please sign in to comment.