Merge pull request #4560 from nabinhait/item_variants
[fix] Disable atrribute table in variant item record
diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py
index a8f69ca..3508277 100644
--- a/erpnext/controllers/item_variant.py
+++ b/erpnext/controllers/item_variant.py
@@ -12,7 +12,7 @@
class ItemTemplateCannotHaveStock(frappe.ValidationError): pass
@frappe.whitelist()
-def get_variant(variant, template, args):
+def get_variant(template, args, variant=None):
"""Validates Attributes and their Values, then looks for an exactly matching Item Variant
:param item: Template Item
@@ -26,7 +26,7 @@
validate_item_variant_attributes(template, args)
- return find_variant(variant, template, args)
+ return find_variant(template, args, variant)
def validate_item_variant_attributes(item, args):
attribute_values = {}
@@ -65,7 +65,7 @@
frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values").format(
value, attribute))
-def find_variant(variant_item_code, template, args):
+def find_variant(template, args, variant_item_code=None):
conditions = ["""(iv_attribute.attribute="{0}" and iv_attribute.attribute_value="{1}")"""\
.format(frappe.db.escape(key), frappe.db.escape(cstr(value))) for key, value in args.items()]
@@ -80,7 +80,7 @@
select name from `tabItem Variant Attribute` iv_attribute
where iv_attribute.parent=item.name
and ({conditions}) and parent != %s
- )""".format(conditions=conditions), (template, variant_item_code))
+ )""".format(conditions=conditions), (template, cstr(variant_item_code)))
for variant in possible_variants:
variant = frappe.get_doc("Item", variant)
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index d6e4748..2caade6 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -236,7 +236,7 @@
frappe.call({
method:"erpnext.controllers.item_variant.get_variant",
args: {
- "item": cur_frm.doc.name,
+ "template": cur_frm.doc.name,
"args": d.get_values()
},
callback: function(r) {
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index fe13fa1..6a3cf6f 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -572,7 +572,7 @@
frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute))
args[d.attribute] = d.attribute_value
- variant = get_variant(self.name, self.variant_of, args)
+ variant = get_variant(self.variant_of, args, self.name)
if variant:
frappe.throw(_("Item variant {0} exists with same attributes")
.format(variant), ItemVariantExistsError)