variants combination generation logic added

This commit is contained in:
Neil Trini Lasrado 2015-05-21 16:40:27 +05:30
parent c8cc8b7115
commit 333ccd212b
3 changed files with 30 additions and 53 deletions

View File

@ -62,6 +62,7 @@
"fieldname": "create_variants", "fieldname": "create_variants",
"fieldtype": "Button", "fieldtype": "Button",
"label": "Create Variants", "label": "Create Variants",
"options": "create_variants",
"permlevel": 0, "permlevel": 0,
"precision": "" "precision": ""
} }
@ -73,7 +74,7 @@
"is_submittable": 0, "is_submittable": 0,
"issingle": 1, "issingle": 1,
"istable": 0, "istable": 0,
"modified": "2015-05-20 18:00:48.331950", "modified": "2015-05-21 16:21:33.707125",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Manage Variants", "name": "Manage Variants",

View File

@ -17,6 +17,7 @@ class ManageVariants(Document):
self.validate_attributes() self.validate_attributes()
self.validate_template_item() self.validate_template_item()
self.validate_stock_for_template_must_be_zero() self.validate_stock_for_template_must_be_zero()
self.validate_attribute_values()
self.validate_attributes_are_unique() self.validate_attributes_are_unique()
self.get_variant_item_codes() self.get_variant_item_codes()
@ -39,6 +40,15 @@ class ManageVariants(Document):
frappe.throw(_("Item Template cannot have stock and varaiants. Please remove \ frappe.throw(_("Item Template cannot have stock and varaiants. Please remove \
stock from warehouses {0}").format(", ".join(stock_in)), ItemTemplateCannotHaveStock) 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): def validate_attributes_are_unique(self):
attributes = [] attributes = []
for d in self.attributes: for d in self.attributes:
@ -74,4 +84,8 @@ class ManageVariants(Document):
add_attribute_suffixes(self.item, [], attributes) add_attribute_suffixes(self.item, [], attributes)
print variant_item_codes for v in variant_item_codes:
self.append('variants', {"variant": v})
def create_variants(self):
pass

View File

@ -11,7 +11,7 @@
"fields": [ "fields": [
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"fieldname": "varient", "fieldname": "variant",
"fieldtype": "Data", "fieldtype": "Data",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
@ -23,44 +23,6 @@
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 0, "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, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
@ -76,7 +38,7 @@
"is_submittable": 0, "is_submittable": 0,
"issingle": 0, "issingle": 0,
"istable": 1, "istable": 1,
"modified": "2015-05-20 18:20:10.555404", "modified": "2015-05-21 16:18:16.605271",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Variant Item", "name": "Variant Item",