test: Test include_descendants in Item Group Product Listing
- Also made include_descendants field's visibility dependant on show_in_website
This commit is contained in:
parent
ee43f83ff8
commit
3507cf5985
@ -13,8 +13,7 @@ test_dependencies = ["Item", "Item Group"]
|
||||
class TestItemGroupProductDataEngine(unittest.TestCase):
|
||||
"Test Products & Sub-Category Querying for Product Listing on Item Group Page."
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
def setUp(self):
|
||||
item_codes = [
|
||||
("Test Mobile A", "_Test Item Group B"),
|
||||
("Test Mobile B", "_Test Item Group B"),
|
||||
@ -28,8 +27,10 @@ class TestItemGroupProductDataEngine(unittest.TestCase):
|
||||
if not frappe.db.exists("Website Item", {"item_code": item_code}):
|
||||
create_regular_web_item(item_code, item_args=item_args)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
frappe.db.set_value("Item Group", "_Test Item Group B - 1", "show_in_website", 1)
|
||||
frappe.db.set_value("Item Group", "_Test Item Group B - 2", "show_in_website", 1)
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.rollback()
|
||||
|
||||
def test_product_listing_in_item_group(self):
|
||||
@ -87,7 +88,6 @@ class TestItemGroupProductDataEngine(unittest.TestCase):
|
||||
|
||||
def test_item_group_with_sub_groups(self):
|
||||
"Test Valid Sub Item Groups in Item Group Page."
|
||||
frappe.db.set_value("Item Group", "_Test Item Group B - 1", "show_in_website", 1)
|
||||
frappe.db.set_value("Item Group", "_Test Item Group B - 2", "show_in_website", 0)
|
||||
|
||||
result = get_product_filter_data(query_args={
|
||||
@ -114,4 +114,45 @@ class TestItemGroupProductDataEngine(unittest.TestCase):
|
||||
|
||||
# check if child group is fetched if shown in website
|
||||
self.assertIn("_Test Item Group B - 1", child_groups)
|
||||
self.assertIn("_Test Item Group B - 2", child_groups)
|
||||
self.assertIn("_Test Item Group B - 2", child_groups)
|
||||
|
||||
def test_item_group_page_with_descendants_included(self):
|
||||
"""
|
||||
Test if 'include_descendants' pulls Items belonging to descendant Item Groups (Level 2 & 3).
|
||||
> _Test Item Group B [Level 1]
|
||||
> _Test Item Group B - 1 [Level 2]
|
||||
> _Test Item Group B - 1 - 1 [Level 3]
|
||||
"""
|
||||
frappe.get_doc({ # create Level 3 nested child group
|
||||
"doctype": "Item Group",
|
||||
"is_group": 1,
|
||||
"item_group_name": "_Test Item Group B - 1 - 1",
|
||||
"parent_item_group": "_Test Item Group B - 1"
|
||||
}).insert()
|
||||
|
||||
create_regular_web_item( # create an item belonging to level 3 item group
|
||||
"Test Mobile F",
|
||||
item_args={"item_group": "_Test Item Group B - 1 - 1"}
|
||||
)
|
||||
|
||||
frappe.db.set_value("Item Group", "_Test Item Group B - 1 - 1", "show_in_website", 1)
|
||||
|
||||
# enable 'include descendants' in Level 1
|
||||
frappe.db.set_value("Item Group", "_Test Item Group B", "include_descendants", 1)
|
||||
|
||||
result = get_product_filter_data(query_args={
|
||||
"field_filters": {},
|
||||
"attribute_filters": {},
|
||||
"start": 0,
|
||||
"item_group": "_Test Item Group B"
|
||||
})
|
||||
|
||||
items = result.get("items")
|
||||
item_codes = [item.get("item_code") for item in items]
|
||||
|
||||
# check if all sub groups' items are pulled
|
||||
self.assertEqual(len(items), 6)
|
||||
self.assertIn("Test Mobile A", item_codes)
|
||||
self.assertIn("Test Mobile C", item_codes)
|
||||
self.assertIn("Test Mobile E", item_codes)
|
||||
self.assertIn("Test Mobile F", item_codes)
|
@ -219,6 +219,7 @@
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "show_in_website",
|
||||
"description": "Include Website Items belonging to child Item Groups",
|
||||
"fieldname": "include_descendants",
|
||||
"fieldtype": "Check",
|
||||
@ -231,7 +232,7 @@
|
||||
"is_tree": 1,
|
||||
"links": [],
|
||||
"max_attachments": 3,
|
||||
"modified": "2022-03-07 09:44:47.561532",
|
||||
"modified": "2022-03-09 12:27:11.055782",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Item Group",
|
||||
|
0
erpnext/templates/pages/non_profit/__init__.py
Normal file
0
erpnext/templates/pages/non_profit/__init__.py
Normal file
Loading…
x
Reference in New Issue
Block a user