This commit is contained in:
Neil Trini Lasrado 2015-06-09 15:17:33 +05:30
parent 82763f052f
commit f64fae752f
2 changed files with 35 additions and 2 deletions

View File

@ -0,0 +1,33 @@
import frappe
def execute():
variant_item = frappe.db.get_all("Item",
fields=["name"],
filters={"has_variants": 1})
for d in variant_item:
pass
def get_variant_item_codes(self):
"""Get all possible suffixes for variants"""
variant_dict = {}
for d in self.attributes:
variant_dict.setdefault(d.attribute, []).append(d.attribute_value)
all_attributes = [d.name for d in frappe.get_all("Item Attribute", order_by = "priority asc")]
# sort attributes by their priority
attributes = filter(None, map(lambda d: d if d in variant_dict else None, all_attributes))
def add_attribute_suffixes(item_code, my_attributes, attributes):
attr = frappe.get_doc("Item Attribute", attributes[0])
for value in attr.item_attribute_values:
if value.attribute_value in variant_dict[attr.name]:
_my_attributes = copy.deepcopy(my_attributes)
_my_attributes.append([attr.name, value.attribute_value])
if len(attributes) > 1:
add_attribute_suffixes(item_code + "-" + value.abbr, _my_attributes, attributes[1:])
else:
self.append('variants', {"variant": item_code + "-" + value.abbr,
"attributes": json.dumps(_my_attributes)})
add_attribute_suffixes(self.item, [], attributes)

View File

@ -148,7 +148,7 @@
"no_copy": 1,
"oldfieldname": "status",
"oldfieldtype": "Select",
"options": "\nDraft\nSubmitted\nIssued\nOrdered\nTransfered\nStopped\nCancelled",
"options": "\nDraft\nSubmitted\nStopped\nCancelled",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
@ -221,7 +221,7 @@
"icon": "icon-ticket",
"idx": 1,
"is_submittable": 1,
"modified": "2015-06-08 07:24:47.954499",
"modified": "2015-06-09 05:47:05.934432",
"modified_by": "Administrator",
"module": "Stock",
"name": "Material Request",