diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index a8f69cac33..350827790f 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -12,7 +12,7 @@ class InvalidItemAttributeValueError(frappe.ValidationError): pass 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 @@ def get_variant(variant, template, args): 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 @@ def validate_item_variant_attributes(item, args): 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 @@ def find_variant(variant_item_code, template, args): 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 d6e47485b5..2caade633c 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -236,7 +236,7 @@ $.extend(erpnext.item, { 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 1004f91edd..47ace46210 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -563,7 +563,7 @@ class Item(WebsiteGenerator): 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)