[fix] Disable atrribute table in variant item record

This commit is contained in:
Nabin Hait 2015-12-31 13:20:32 +05:30
parent b9dcf7f857
commit 6b068e1367
3 changed files with 6 additions and 6 deletions

View File

@ -12,7 +12,7 @@ class InvalidItemAttributeValueError(frappe.ValidationError): pass
class ItemTemplateCannotHaveStock(frappe.ValidationError): pass class ItemTemplateCannotHaveStock(frappe.ValidationError): pass
@frappe.whitelist() @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 """Validates Attributes and their Values, then looks for an exactly matching Item Variant
:param item: Template Item :param item: Template Item
@ -26,7 +26,7 @@ def get_variant(variant, template, args):
validate_item_variant_attributes(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): def validate_item_variant_attributes(item, args):
attribute_values = {} 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( frappe.throw(_("Value {0} for Attribute {1} does not exist in the list of valid Item Attribute Values").format(
value, attribute)) 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}")"""\ 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()] .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 select name from `tabItem Variant Attribute` iv_attribute
where iv_attribute.parent=item.name where iv_attribute.parent=item.name
and ({conditions}) and parent != %s 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: for variant in possible_variants:
variant = frappe.get_doc("Item", variant) variant = frappe.get_doc("Item", variant)

View File

@ -236,7 +236,7 @@ $.extend(erpnext.item, {
frappe.call({ frappe.call({
method:"erpnext.controllers.item_variant.get_variant", method:"erpnext.controllers.item_variant.get_variant",
args: { args: {
"item": cur_frm.doc.name, "template": cur_frm.doc.name,
"args": d.get_values() "args": d.get_values()
}, },
callback: function(r) { callback: function(r) {

View File

@ -563,7 +563,7 @@ class Item(WebsiteGenerator):
frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute)) frappe.throw(_("Please specify Attribute Value for attribute {0}").format(d.attribute))
args[d.attribute] = d.attribute_value 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: if variant:
frappe.throw(_("Item variant {0} exists with same attributes") frappe.throw(_("Item variant {0} exists with same attributes")
.format(variant), ItemVariantExistsError) .format(variant), ItemVariantExistsError)