From 333ccd212b4b92e06f19caa5204874e2907d455d Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Thu, 21 May 2015 16:40:27 +0530 Subject: [PATCH] variants combination generation logic added --- .../manage_variants/manage_variants.json | 3 +- .../manage_variants/manage_variants.py | 38 +++++++++++------ .../doctype/variant_item/variant_item.json | 42 +------------------ 3 files changed, 30 insertions(+), 53 deletions(-) diff --git a/erpnext/stock/doctype/manage_variants/manage_variants.json b/erpnext/stock/doctype/manage_variants/manage_variants.json index b00266a5cd..f16910b7f9 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 4169cae243..a583619b62 100644 --- a/erpnext/stock/doctype/manage_variants/manage_variants.py +++ b/erpnext/stock/doctype/manage_variants/manage_variants.py @@ -17,13 +17,14 @@ class ManageVariants(Document): 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 @@ class ManageVariants(Document): 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 @@ class ManageVariants(Document): 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 @@ class ManageVariants(Document): 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 8e1c8621e2..b4a4c0db59 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",