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.
This commit is contained in:
Mihir Kandoi
2026-08-07 13:04:45 +05:30
parent a219f890df
commit a464a6e4a1

View File

@@ -618,13 +618,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)),