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 f7b2775829)
This commit is contained in:
pandiyan
2026-08-09 11:25:12 +05:30
committed by Mergify
parent a97beb6d9b
commit 39f15bb3e9
2 changed files with 3 additions and 2 deletions

View File

@@ -253,7 +253,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):

View File

@@ -194,7 +194,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()