2015-06-29 09:36:46 +00:00
|
|
|
import frappe
|
|
|
|
|
|
|
|
def execute():
|
|
|
|
frappe.reload_doctype("Item")
|
2015-07-01 07:20:52 +00:00
|
|
|
for dt in ["manage_variants", "manage_variants_item", "variant_attribute"]:
|
|
|
|
frappe.reload_doc("stock", "doctype", dt)
|
|
|
|
|
2015-06-29 09:36:46 +00:00
|
|
|
for d in frappe.get_list("Item", filters={"has_variants":1}):
|
|
|
|
manage_variant = frappe.new_doc("Manage Variants")
|
2015-07-01 07:20:52 +00:00
|
|
|
manage_variant.item_code = d.name
|
2015-06-29 09:36:46 +00:00
|
|
|
manage_variant.attributes = frappe.db.sql("select item_attribute as attribute, item_attribute_value as attribute_value \
|
|
|
|
from `tabItem Variant` where parent = %s", d.name, as_dict=1)
|
2015-07-01 07:20:52 +00:00
|
|
|
if manage_variant.attributes:
|
2015-07-03 13:37:23 +00:00
|
|
|
if not frappe.get_list("Item", filters={"variant_of": d.name}, limit_page_length=1):
|
|
|
|
frappe.db.sql("delete from `tabItem Variant` where parent=%s", d.name)
|
|
|
|
else:
|
|
|
|
manage_variant.generate_combinations()
|
|
|
|
manage_variant.create_variants()
|
2015-07-01 07:20:52 +00:00
|
|
|
frappe.delete_doc("DocType", "Item Variant")
|