From af937506017a61bfa125b1b1f8fd0038aec5056c Mon Sep 17 00:00:00 2001
From: Cybrosys Technologies
Date: Wed, 30 Apr 2025 11:42:39 +0530
Subject: [PATCH] APR 30: [FIX] Bug fixed 'sale_discount_total'
---
sale_discount_total/__manifest__.py | 2 +-
sale_discount_total/doc/RELEASE_NOTES.md | 6 +++-
sale_discount_total/models/sale_order.py | 34 ++++++++++---------
.../static/description/index.html | 15 ++++++++
4 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/sale_discount_total/__manifest__.py b/sale_discount_total/__manifest__.py
index c508e4bf6..c67a9dd9f 100644
--- a/sale_discount_total/__manifest__.py
+++ b/sale_discount_total/__manifest__.py
@@ -21,7 +21,7 @@
#############################################################################
{
'name': 'Sale Discount on Total Amount',
- 'version': '17.0.1.1.0',
+ 'version': '17.0.1.1.1',
'category': 'Sales Management',
'summary': "Discount on Total in Sale and Invoice With Discount Limit "
"and Approval",
diff --git a/sale_discount_total/doc/RELEASE_NOTES.md b/sale_discount_total/doc/RELEASE_NOTES.md
index d64707bf3..b007fcfdc 100644
--- a/sale_discount_total/doc/RELEASE_NOTES.md
+++ b/sale_discount_total/doc/RELEASE_NOTES.md
@@ -5,8 +5,12 @@
#### ADD
- Initial commit for Sale Discount On Total Amount
-
#### 14.03.2024
#### Version 17.0.1.1.0
#### ADD
- Added margin in sale orders
+
+#### 24.04.2025
+#### Version 17.0.1.0.1
+#### BUGFIX
+- Prevented overwriting of line-level discounts
diff --git a/sale_discount_total/models/sale_order.py b/sale_discount_total/models/sale_order.py
index 2db3caf6d..6fbcef2ba 100644
--- a/sale_discount_total/models/sale_order.py
+++ b/sale_discount_total/models/sale_order.py
@@ -110,24 +110,26 @@ class SaleOrder(models.Model):
@api.onchange('discount_type', 'discount_rate', 'order_line')
def supply_rate(self):
"""This function calculates supply rates based on change of
- discount_type, discount_rate and invoice_line_ids"""
+ discount_type, discount_rate and invoice_line_ids"""
for order in self:
- if order.discount_type == 'percent':
- for line in order.order_line:
- line.discount = order.discount_rate
- else:
- total = 0.0
- for line in order.order_line:
- total += round((line.product_uom_qty * line.price_unit))
- if order.discount_rate != 0:
- discount = (
- order.discount_rate / total) * 100 if total > 0 else 0
+ if order.discount_rate > 0:
+ if order.discount_type == 'percent':
+ for line in order.order_line:
+ line.discount = order.discount_rate
else:
- discount = order.discount_rate
- for line in order.order_line:
- line.discount = discount
- new_sub_price = (line.price_unit * (discount / 100))
- line.total_discount = line.price_unit - new_sub_price
+ total = 0.0
+ for line in order.order_line:
+ total += round((line.product_uom_qty * line.price_unit))
+ if total > 0:
+ discount = (order.discount_rate / total) * 100
+ else:
+ discount = 0.0
+ for line in order.order_line:
+ line.discount = discount
+ new_sub_price = (line.price_unit * (discount / 100))
+ line.total_discount = line.price_unit - new_sub_price
+ else:
+ pass
def _prepare_invoice(self, ):
"""Super sale order class and update with fields"""
diff --git a/sale_discount_total/static/description/index.html b/sale_discount_total/static/description/index.html
index 43a51a133..1b4eac997 100644
--- a/sale_discount_total/static/description/index.html
+++ b/sale_discount_total/static/description/index.html
@@ -285,6 +285,21 @@
+
+
+
Version
+ 17.0.1.1.1|Released on:24th Apr 2025
+
+
+ Prevented overwriting of line-level discounts
+
+
+