variants combination generation logic added
diff --git a/erpnext/stock/doctype/manage_variants/manage_variants.json b/erpnext/stock/doctype/manage_variants/manage_variants.json
index b00266a..f16910b 100644
--- a/erpnext/stock/doctype/manage_variants/manage_variants.json
+++ b/erpnext/stock/doctype/manage_variants/manage_variants.json
@@ -62,6 +62,7 @@
"fieldname": "create_variants",
"fieldtype": "Button",
"label": "Create Variants",
+ "options": "create_variants",
"permlevel": 0,
"precision": ""
}
@@ -73,7 +74,7 @@
"is_submittable": 0,
"issingle": 1,
"istable": 0,
- "modified": "2015-05-20 18:00:48.331950",
+ "modified": "2015-05-21 16:21:33.707125",
"modified_by": "Administrator",
"module": "Stock",
"name": "Manage Variants",
diff --git a/erpnext/stock/doctype/manage_variants/manage_variants.py b/erpnext/stock/doctype/manage_variants/manage_variants.py
index 4169cae..a583619 100644
--- a/erpnext/stock/doctype/manage_variants/manage_variants.py
+++ b/erpnext/stock/doctype/manage_variants/manage_variants.py
@@ -17,13 +17,14 @@
self.validate_attributes()
self.validate_template_item()
self.validate_stock_for_template_must_be_zero()
+ self.validate_attribute_values()
self.validate_attributes_are_unique()
self.get_variant_item_codes()
-
+
def validate_attributes(self):
if not self.attributes:
frappe.throw("Enter atleast one Attribute & its Value in Attribute table.")
-
+
def validate_template_item(self):
template_item = frappe.get_doc("Item", self.item)
if not template_item.has_variants:
@@ -31,7 +32,7 @@
if template_item.variant_of:
frappe.throw(_("Item cannot be a variant of a variant"))
-
+
def validate_stock_for_template_must_be_zero(self):
stock_in = frappe.db.sql_list("""select warehouse from tabBin
where item_code=%s and ifnull(actual_qty, 0) > 0""", self.item)
@@ -39,15 +40,24 @@
frappe.throw(_("Item Template cannot have stock and varaiants. Please remove \
stock from warehouses {0}").format(", ".join(stock_in)), ItemTemplateCannotHaveStock)
+ def validate_attribute_values(self):
+ attributes = {}
+ for d in self.attributes:
+ attributes.setdefault(d.attribute,
+ [t.attribute_value for t in
+ frappe.db.get_all("Item Attribute Value", fields=["attribute_value"], filters={"parent": d.attribute })])
+ if d.attribute_value not in attributes.get(d.attribute):
+ frappe.throw(_("Attribute value {0} does not exist in Item Attribute Master.").format(d.attribute_value))
+
def validate_attributes_are_unique(self):
- attributes = []
- for d in self.attributes:
- key = (d.attribute, d.attribute_value)
- if key in attributes:
- frappe.throw(_("{0} {1} is entered more than once in Attributes table")
- .format(d.attribute, d.attribute_value), DuplicateAttribute)
- attributes.append(key)
-
+ attributes = []
+ for d in self.attributes:
+ key = (d.attribute, d.attribute_value)
+ if key in attributes:
+ frappe.throw(_("{0} {1} is entered more than once in Attributes table")
+ .format(d.attribute, d.attribute_value), DuplicateAttribute)
+ attributes.append(key)
+
def get_variant_item_codes(self):
"""Get all possible suffixes for variants"""
variant_dict = {}
@@ -74,4 +84,8 @@
add_attribute_suffixes(self.item, [], attributes)
- print variant_item_codes
\ No newline at end of file
+ for v in variant_item_codes:
+ self.append('variants', {"variant": v})
+
+ def create_variants(self):
+ pass
\ No newline at end of file
diff --git a/erpnext/stock/doctype/variant_item/variant_item.json b/erpnext/stock/doctype/variant_item/variant_item.json
index 8e1c862..b4a4c0d 100644
--- a/erpnext/stock/doctype/variant_item/variant_item.json
+++ b/erpnext/stock/doctype/variant_item/variant_item.json
@@ -11,7 +11,7 @@
"fields": [
{
"allow_on_submit": 0,
- "fieldname": "varient",
+ "fieldname": "variant",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
@@ -23,44 +23,6 @@
"permlevel": 0,
"precision": "",
"print_hide": 0,
- "read_only": 1,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0
- },
- {
- "allow_on_submit": 0,
- "fieldname": "column_break_2",
- "fieldtype": "Column Break",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "in_filter": 0,
- "in_list_view": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "read_only": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0
- },
- {
- "allow_on_submit": 0,
- "fieldname": "item_code",
- "fieldtype": "Data",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "in_filter": 0,
- "in_list_view": 1,
- "label": "Item Code",
- "no_copy": 0,
- "options": "",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
@@ -76,7 +38,7 @@
"is_submittable": 0,
"issingle": 0,
"istable": 1,
- "modified": "2015-05-20 18:20:10.555404",
+ "modified": "2015-05-21 16:18:16.605271",
"modified_by": "Administrator",
"module": "Stock",
"name": "Variant Item",