mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 14:41:53 +00:00
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:
@@ -253,7 +253,7 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
total += sales_person.allocated_percentage
|
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"))
|
throw(_("Total allocated percentage for sales team should be 100"))
|
||||||
|
|
||||||
def validate_sales_team(self, sales_team):
|
def validate_sales_team(self, sales_team):
|
||||||
|
|||||||
@@ -194,7 +194,8 @@ class Customer(TransactionBase):
|
|||||||
self.loyalty_program_tier = customer.loyalty_program_tier
|
self.loyalty_program_tier = customer.loyalty_program_tier
|
||||||
|
|
||||||
if self.sales_team:
|
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.throw(_("Total contribution percentage should be equal to 100"))
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
Reference in New Issue
Block a user