item = frappe.qb.DocType('Item')
item_variant = frappe.qb.DocType('Item Variant Attribute')
query = frappe.qb \
.select(item.name, item.variant_of, item_variant.attribute, item_variant.attribute_value) \
.from_(item_variant).join(item).on(item.name == item_variant.parent) \
.where(item.variant_of == 'Grand Teton')
""" At this point you will get all Item Variants
You will need to find a way to query same column
This is because table 'tabItem Variant Attribute', uses two columns to store the data you want to filter: 'attribute' column and 'attribute_value' column
"""
# You can try from here. If you find a mysql example, sure it can be used with frappe.
query.where(
Tuple(item_variant.attribute, item_variant.attribute_value).isin([
('Width - ft', 12),
('Length - ft', 12),
('Bents', 2)
])
)
# Or do it manually with python. Group all results using the item.name, and then create the custom dict and filter
Hopefully someone from the frappe dev team is paying attention to this thread and adds a way to accomplish that using frappe.get_all shorthand in the future, cause that’s complicated!