From 75bd0f7cfe45ffc5bd6bb8e9b418b57389d959f8 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Mon, 19 Oct 2015 16:50:22 +0530 Subject: [PATCH 1/3] Fixed issue in Item Variant for Numeric Attributes --- erpnext/controllers/item_variant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index 38536cff32..8cacfc9eba 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -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 = len(cstr(increment).split(".")[-1].rstrip("0")) + precision = len(cstr(value).split(".")[-1].rstrip("0")) #avoid precision error by rounding the remainder remainder = flt((flt(value) - from_range) % increment, precision) From e65ac00f365785df44b54092d44b722d8e13ac43 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Mon, 19 Oct 2015 19:13:03 +0530 Subject: [PATCH 2/3] Considered greater precision of value and increment --- erpnext/controllers/item_variant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index 8cacfc9eba..c80a5f305b 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -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 = len(cstr(value).split(".")[-1].rstrip("0")) + precision = max(len(cstr(value).split(".")[-1].rstrip("0")), len(cstr(increment).split(".")[-1].rstrip("0"))) #avoid precision error by rounding the remainder remainder = flt((flt(value) - from_range) % increment, precision) From a4fad72a651950caa4a50d63fc7fdd99ce3efb48 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 20 Oct 2015 11:58:07 +0530 Subject: [PATCH 3/3] Considered greater precision of value and increment (better code) --- erpnext/controllers/item_variant.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index c80a5f305b..0e1d126832 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -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)