fix: UOM whole number check truncated instead of rounding

cint truncates, so a stock_qty of 1999.9998 (dust from qty times
conversion factor) compared as abs(1999 - 2000.0) > epsilon and was
rejected as fractional even though it rounds to a whole number at
field precision, with the error confusingly printing the rounded
value: 'Quantity (2000.0) cannot be a fraction'. Round to field
precision first, then require the result to be a whole number.
Dust above an integer already passed; this fixes the asymmetry for
dust below.

(cherry picked from commit a464a6e4a1)
This commit is contained in:
Mihir Kandoi
2026-10-22 03:38:48 +00:00
parent 55a5b9d2af
commit 51afe19467
+3 -3
View File
@@ -338,13 +338,13 @@ def validate_uom_is_integer(doc, uom_field, qty_fields, child_dt=None):
for f in qty_fields:
qty = d.get(f)
if qty:
precision = d.precision(f)
if abs(cint(qty) - flt(qty, precision)) > 0.0000001:
qty = flt(qty, d.precision(f))
if qty != cint(qty):
frappe.throw(
_(
"Row {1}: Quantity ({0}) cannot be a fraction. To allow this, disable '{2}' in UOM {3}."
).format(
flt(qty, precision),
qty,
d.idx,
frappe.bold(_("Must be Whole Number")),
frappe.bold(d.get(uom_field)),