From bb474f4f42aa6c5385a63df31c9d9af14238fad8 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Sat, 31 May 2025 20:52:14 +0530 Subject: [PATCH] fix: calculate discount percentage if discount amount is specified (#47806) --- erpnext/controllers/taxes_and_totals.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 239e47b15ac..bbf4ae36b61 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -12,6 +12,7 @@ from frappe.utils import cint, flt, round_based_on_smallest_currency_fraction import erpnext from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_rate from erpnext.accounts.doctype.pricing_rule.utils import get_applied_pricing_rules +from erpnext.accounts.utils import get_currency_precision from erpnext.controllers.accounts_controller import ( validate_conversion_rate, validate_inclusive_tax, @@ -707,7 +708,16 @@ class calculate_taxes_and_totals: tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail) def set_discount_amount(self): - if self.doc.additional_discount_percentage: + if self.doc.discount_amount: + self.doc.additional_discount_percentage = flt( + flt( + self.doc.discount_amount / flt(self.doc.get(scrub(self.doc.apply_discount_on))), + get_currency_precision(), + ) + * 100, + self.doc.precision("additional_discount_percentage"), + ) + elif self.doc.additional_discount_percentage: self.doc.discount_amount = flt( flt(self.doc.get(scrub(self.doc.apply_discount_on))) * self.doc.additional_discount_percentage