test: add test for item attribute completion
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index a5bc492..ec46f60 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -1281,12 +1281,13 @@
@frappe.whitelist()
-def get_item_attribute(parent, attribute_value=''):
+def get_item_attribute(parent, attribute_value=""):
+ """Used for providing auto-completions in child table."""
if not frappe.has_permission("Item"):
frappe.throw(_("No Permission"))
return frappe.get_all("Item Attribute Value", fields = ["attribute_value"],
- filters = {'parent': parent, 'attribute_value': ("like", "%%%s%%" % attribute_value)})
+ filters = {'parent': parent, 'attribute_value': ("like", f"%{attribute_value}%")})
def update_variants(variants, template, publish_progress=True):
total = len(variants)
diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py
index d9d1e5a..7cd6050 100644
--- a/erpnext/stock/doctype/item/test_item.py
+++ b/erpnext/stock/doctype/item/test_item.py
@@ -10,13 +10,13 @@
from erpnext.controllers.item_variant import (create_variant, ItemVariantExistsError,
InvalidItemAttributeValueError, get_variant)
from erpnext.stock.doctype.item.item import StockExistsForTemplate, InvalidBarcode
-from erpnext.stock.doctype.item.item import get_uom_conv_factor
+from erpnext.stock.doctype.item.item import get_uom_conv_factor, get_item_attribute
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
from erpnext.stock.get_item_details import get_item_details
test_ignore = ["BOM"]
-test_dependencies = ["Warehouse", "Item Group", "Item Tax Template", "Brand"]
+test_dependencies = ["Warehouse", "Item Group", "Item Tax Template", "Brand", "Item Attribute"]
def make_item(item_code, properties=None):
if frappe.db.exists("Item", item_code):
@@ -500,6 +500,21 @@
if expected_columns:
self.fail(f"Expected db index on these columns: {', '.join(expected_columns)}")
+ def test_attribute_completions(self):
+ expected_attrs = [{'attribute_value': 'Small'},
+ {'attribute_value': 'Extra Small'},
+ {'attribute_value': 'Extra Large'},
+ {'attribute_value': 'Large'},
+ {'attribute_value': '2XL'},
+ {'attribute_value': 'Medium'}]
+
+ attrs = get_item_attribute("Test Size")
+ self.assertEqual(attrs, expected_attrs)
+
+ attrs = get_item_attribute("Test Size", attribute_value="extra")
+ self.assertEqual(attrs, [{'attribute_value': 'Extra Small'}, {'attribute_value': 'Extra Large'}])
+
+
def set_item_variant_settings(fields):
doc = frappe.get_doc('Item Variant Settings')