From ba8a316b06a58aabd3f4f86191c8caaeedfeadd1 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) (cherry picked from commit bb474f4f42aa6c5385a63df31c9d9af14238fad8) --- 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 5543129d323..c47f04b71f1 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -13,6 +13,7 @@ from frappe.utils.deprecations import deprecated 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, @@ -674,7 +675,16 @@ class calculate_taxes_and_totals: tax.item_wise_tax_detail = json.dumps(tax.item_wise_tax_detail, separators=(",", ":")) 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