Merge pull request #17475 from netchampfaris/item-variant-attributes-optional
fix: Allow variant attributes to be optional
This commit is contained in:
commit
4d2c307d6d
@ -124,16 +124,8 @@ def find_variant(template, args, variant_item_code=None):
|
|||||||
|
|
||||||
conditions = " or ".join(conditions)
|
conditions = " or ".join(conditions)
|
||||||
|
|
||||||
# use approximate match and shortlist possible variant matches
|
from erpnext.portal.product_configurator.utils import get_item_codes_by_attributes
|
||||||
# it is approximate because we are matching using OR condition
|
possible_variants = [i for i in get_item_codes_by_attributes(args, template) if i != variant_item_code]
|
||||||
# and it need not be exact match at this stage
|
|
||||||
# this uses a simpler query instead of using multiple exists conditions
|
|
||||||
possible_variants = frappe.db.sql_list("""select name from `tabItem` item
|
|
||||||
where variant_of=%s and exists (
|
|
||||||
select name from `tabItem Variant Attribute` iv_attribute
|
|
||||||
where iv_attribute.parent=item.name
|
|
||||||
and ({conditions}) and parent != %s
|
|
||||||
)""".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)
|
||||||
@ -317,7 +309,7 @@ def make_variant_item_code(template_item_code, template_item_name, variant):
|
|||||||
}, as_dict=True)
|
}, as_dict=True)
|
||||||
|
|
||||||
if not item_attribute:
|
if not item_attribute:
|
||||||
return
|
continue
|
||||||
# frappe.throw(_('Invalid attribute {0} {1}').format(frappe.bold(attr.attribute),
|
# frappe.throw(_('Invalid attribute {0} {1}').format(frappe.bold(attr.attribute),
|
||||||
# frappe.bold(attr.attribute_value)), title=_('Invalid Attribute'),
|
# frappe.bold(attr.attribute_value)), title=_('Invalid Attribute'),
|
||||||
# exc=InvalidItemAttributeValueError)
|
# exc=InvalidItemAttributeValueError)
|
||||||
|
@ -102,6 +102,9 @@ def get_item_codes_by_attributes(attribute_filters, template_item_code=None):
|
|||||||
for attribute, values in attribute_filters.items():
|
for attribute, values in attribute_filters.items():
|
||||||
attribute_values = values
|
attribute_values = values
|
||||||
|
|
||||||
|
if not isinstance(attribute_values, list):
|
||||||
|
attribute_values = [attribute_values]
|
||||||
|
|
||||||
if not attribute_values: continue
|
if not attribute_values: continue
|
||||||
|
|
||||||
wheres = []
|
wheres = []
|
||||||
|
@ -390,15 +390,6 @@ frappe.ui.form.ItemQuickEntryForm = frappe.ui.form.QuickEntryForm.extend({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (mandatory.length) {
|
|
||||||
frappe.msgprint({
|
|
||||||
title: __('Missing Values Required'),
|
|
||||||
message: __('Following fields have missing values:') + '<br><br><ul><li>' + mandatory.join('<li>') + '</ul>',
|
|
||||||
indicator: 'orange'
|
|
||||||
});
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.is_manufacturer) {
|
if (this.is_manufacturer) {
|
||||||
$.each(this.manufacturer_fields, function(index, field) {
|
$.each(this.manufacturer_fields, function(index, field) {
|
||||||
attribute[field.fieldname] = me.dialog.fields_dict[field.fieldname].input.value;
|
attribute[field.fieldname] = me.dialog.fields_dict[field.fieldname].input.value;
|
||||||
|
@ -585,7 +585,7 @@ $.extend(erpnext.item, {
|
|||||||
"label": row.attribute,
|
"label": row.attribute,
|
||||||
"fieldname": row.attribute,
|
"fieldname": row.attribute,
|
||||||
"fieldtype": fieldtype,
|
"fieldtype": fieldtype,
|
||||||
"reqd": 1,
|
"reqd": 0,
|
||||||
"description": desc
|
"description": desc
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -600,6 +600,7 @@ $.extend(erpnext.item, {
|
|||||||
if(!args) return;
|
if(!args) return;
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method:"erpnext.controllers.item_variant.get_variant",
|
method:"erpnext.controllers.item_variant.get_variant",
|
||||||
|
btn: d.get_primary_btn(),
|
||||||
args: {
|
args: {
|
||||||
"template": frm.doc.name,
|
"template": frm.doc.name,
|
||||||
"args": d.get_values()
|
"args": d.get_values()
|
||||||
|
@ -800,10 +800,12 @@ class Item(WebsiteGenerator):
|
|||||||
|
|
||||||
def validate_variant_attributes(self):
|
def validate_variant_attributes(self):
|
||||||
if self.is_new() and self.variant_of and self.variant_based_on == 'Item Attribute':
|
if self.is_new() and self.variant_of and self.variant_based_on == 'Item Attribute':
|
||||||
|
# remove attributes with no attribute_value set
|
||||||
|
self.attributes = [d for d in self.attributes if cstr(d.attribute_value).strip()]
|
||||||
|
|
||||||
args = {}
|
args = {}
|
||||||
for d in self.attributes:
|
for i, d in enumerate(self.attributes):
|
||||||
if cstr(d.attribute_value).strip() == '':
|
d.idx = i + 1
|
||||||
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.variant_of, args, self.name)
|
variant = get_variant(self.variant_of, args, self.name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user