variants combination generation logic added
This commit is contained in:
		
							parent
							
								
									c8cc8b7115
								
							
						
					
					
						commit
						333ccd212b
					
				| @ -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",  | ||||||
|  | |||||||
| @ -17,13 +17,14 @@ 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() | ||||||
| 	 | 
 | ||||||
| 	def validate_attributes(self): | 	def validate_attributes(self): | ||||||
| 		if not self.attributes: | 		if not self.attributes: | ||||||
| 			frappe.throw("Enter atleast one Attribute & its Value in Attribute table.") | 			frappe.throw("Enter atleast one Attribute & its Value in Attribute table.") | ||||||
| 	 | 
 | ||||||
| 	def validate_template_item(self): | 	def validate_template_item(self): | ||||||
| 		template_item = frappe.get_doc("Item", self.item) | 		template_item = frappe.get_doc("Item", self.item) | ||||||
| 		if not template_item.has_variants: | 		if not template_item.has_variants: | ||||||
| @ -31,7 +32,7 @@ class ManageVariants(Document): | |||||||
| 			 | 			 | ||||||
| 		if template_item.variant_of: | 		if template_item.variant_of: | ||||||
| 			frappe.throw(_("Item cannot be a variant of a variant")) | 			frappe.throw(_("Item cannot be a variant of a variant")) | ||||||
| 		 | 
 | ||||||
| 	def validate_stock_for_template_must_be_zero(self): | 	def validate_stock_for_template_must_be_zero(self): | ||||||
| 		stock_in = frappe.db.sql_list("""select warehouse from tabBin | 		stock_in = frappe.db.sql_list("""select warehouse from tabBin | ||||||
| 			where item_code=%s and ifnull(actual_qty, 0) > 0""", self.item) | 			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 \ | 			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: | ||||||
| 				key = (d.attribute, d.attribute_value) | 			key = (d.attribute, d.attribute_value) | ||||||
| 				if key in attributes: | 			if key in attributes: | ||||||
| 					frappe.throw(_("{0} {1} is entered more than once in Attributes table") | 				frappe.throw(_("{0} {1} is entered more than once in Attributes table") | ||||||
| 						.format(d.attribute, d.attribute_value), DuplicateAttribute) | 					.format(d.attribute, d.attribute_value), DuplicateAttribute) | ||||||
| 				attributes.append(key) | 			attributes.append(key) | ||||||
| 				 | 
 | ||||||
| 	def get_variant_item_codes(self): | 	def get_variant_item_codes(self): | ||||||
| 		"""Get all possible suffixes for variants""" | 		"""Get all possible suffixes for variants""" | ||||||
| 		variant_dict = {} | 		variant_dict = {} | ||||||
| @ -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 | ||||||
| @ -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",  | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user