test: add test for item attribute completion
This commit is contained in:
parent
f5a937bc45
commit
eb17732876
@ -1281,12 +1281,13 @@ def get_uom_conv_factor(uom, stock_uom):
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@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"):
|
if not frappe.has_permission("Item"):
|
||||||
frappe.throw(_("No Permission"))
|
frappe.throw(_("No Permission"))
|
||||||
|
|
||||||
return frappe.get_all("Item Attribute Value", fields = ["attribute_value"],
|
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):
|
def update_variants(variants, template, publish_progress=True):
|
||||||
total = len(variants)
|
total = len(variants)
|
||||||
|
@ -10,13 +10,13 @@ from frappe.test_runner import make_test_objects
|
|||||||
from erpnext.controllers.item_variant import (create_variant, ItemVariantExistsError,
|
from erpnext.controllers.item_variant import (create_variant, ItemVariantExistsError,
|
||||||
InvalidItemAttributeValueError, get_variant)
|
InvalidItemAttributeValueError, get_variant)
|
||||||
from erpnext.stock.doctype.item.item import StockExistsForTemplate, InvalidBarcode
|
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.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||||
from erpnext.stock.get_item_details import get_item_details
|
from erpnext.stock.get_item_details import get_item_details
|
||||||
|
|
||||||
|
|
||||||
test_ignore = ["BOM"]
|
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):
|
def make_item(item_code, properties=None):
|
||||||
if frappe.db.exists("Item", item_code):
|
if frappe.db.exists("Item", item_code):
|
||||||
@ -500,6 +500,21 @@ class TestItem(unittest.TestCase):
|
|||||||
if expected_columns:
|
if expected_columns:
|
||||||
self.fail(f"Expected db index on these columns: {', '.join(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):
|
def set_item_variant_settings(fields):
|
||||||
doc = frappe.get_doc('Item Variant Settings')
|
doc = frappe.get_doc('Item Variant Settings')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user