From 262fbc52d887c9efd06973ef6d86f714e5848e77 Mon Sep 17 00:00:00 2001 From: pandiyan Date: Sun, 9 Aug 2026 11:25:12 +0530 Subject: [PATCH] fix: tolerate floating-point drift in sales team allocated percentage the total of allocated_percentage was compared to 100 with exact float equality, so a correct allocation could be rejected when the sum drifts in binary floating point (10.0 + 58.02 + 31.98 -> 100.00000000000001). round the total to the field precision before comparing, in both SellingController.calculate_contribution and Customer.validate. (cherry picked from commit f7b277582940cbb5f7a427ef8250b18db773004b) --- erpnext/controllers/selling_controller.py | 2 +- erpnext/selling/doctype/customer/customer.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 5655fea9915..f1e3baebc51 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -236,7 +236,7 @@ class SellingController(StockController): total += sales_person.allocated_percentage - if sales_team and total != 100.0: + if sales_team and flt(total, self.precision("allocated_percentage", "sales_team")) != 100.0: throw(_("Total allocated percentage for sales team should be 100")) def validate_sales_team(self, sales_team): diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 4d21ff94d3e..4df15cac65e 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -165,7 +165,8 @@ class Customer(TransactionBase): self.loyalty_program_tier = customer.loyalty_program_tier if self.sales_team: - if sum(member.allocated_percentage or 0 for member in self.sales_team) != 100: + total = sum(flt(member.allocated_percentage) for member in self.sales_team) + if flt(total, self.precision("allocated_percentage", "sales_team")) != 100: frappe.throw(_("Total contribution percentage should be equal to 100")) @frappe.whitelist()