fix: Allow variant attributes to be optional

This commit is contained in:
Faris Ansari
2019-05-03 13:41:50 +05:30
parent 8ca3df7aac
commit cb03bb1c00
5 changed files with 12 additions and 23 deletions

View File

@@ -124,16 +124,8 @@ def find_variant(template, args, variant_item_code=None):
conditions = " or ".join(conditions)
# use approximate match and shortlist possible variant matches
# it is approximate because we are matching using OR condition
# 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)))
from erpnext.portal.product_configurator.utils import get_item_codes_by_attributes
possible_variants = [i for i in get_item_codes_by_attributes(args, template) if i != variant_item_code]
for variant in possible_variants:
variant = frappe.get_doc("Item", variant)