Considered greater precision of value and increment (better code)

This commit is contained in:
Neil Trini Lasrado 2015-10-20 11:58:07 +05:30
parent e65ac00f36
commit a4fad72a65

View File

@ -51,7 +51,7 @@ def validate_item_variant_attributes(item, args):
frappe.throw(_("Increment for Attribute {0} cannot be 0").format(attribute))
is_in_range = from_range <= flt(value) <= to_range
precision = max(len(cstr(value).split(".")[-1].rstrip("0")), len(cstr(increment).split(".")[-1].rstrip("0")))
precision = max(len(cstr(v).split(".")[-1].rstrip("0")) for v in (value, increment))
#avoid precision error by rounding the remainder
remainder = flt((flt(value) - from_range) % increment, precision)