Merge pull request #57911 from aerele/fix/sales-team-allocated-percentage-float

fix: tolerate floating-point drift in sales team allocated percentage
This commit is contained in:
Mihir Kandoi
2026-08-09 12:28:56 +05:30
committed by GitHub
3 changed files with 14 additions and 2 deletions

View File

@@ -254,7 +254,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

@@ -199,7 +199,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(methods=["POST"])

View File

@@ -3215,6 +3215,17 @@ class TestSalesOrder(ERPNextTestSuite):
so.save()
self.assertEqual(sum(d.allocated_percentage for d in so.sales_team), 100)
with self.subTest("floating-point drift in the total is tolerated"):
# 10.0 + 58.02 + 31.98 accumulates to 100.00000000000001 in binary floating point
so = make_sales_order(do_not_save=True)
for sales_person, percentage in (
("_Test Sales Person", 10.0),
("_Test Sales Person 1", 58.02),
("_Test Sales Person 2", 31.98),
):
so.append("sales_team", {"sales_person": sales_person, "allocated_percentage": percentage})
so.save()
def test_sales_team_disabled_sales_person_rejected(self):
frappe.db.set_value("Sales Person", "_Test Sales Person 2", "enabled", 0)
try: