mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds functionality for traversing "through" installed items to extract test results
This commit is contained in:
parent
8cb3d6ab0a
commit
ef23ab1abc
@ -699,6 +699,36 @@ class StockItem(MPTTModel):
|
||||
|
||||
return True
|
||||
|
||||
def get_installed_items(self, cascade=False):
|
||||
"""
|
||||
Return all stock items which are *installed* in this one!
|
||||
|
||||
Args:
|
||||
cascade - Include items which are installed in items which are installed in items
|
||||
|
||||
Note: This function is recursive, and may result in a number of database hits!
|
||||
"""
|
||||
|
||||
installed = set()
|
||||
|
||||
items = StockItem.objects.filter(belongs_to=self)
|
||||
|
||||
for item in items:
|
||||
|
||||
# Prevent recursion
|
||||
if item not in installed:
|
||||
installed.add(item)
|
||||
|
||||
if cascade:
|
||||
sub_items = item.get_installed_items(cascade=True)
|
||||
|
||||
for sub_item in sub_items:
|
||||
# Prevent recursion
|
||||
if sub_item not in installed:
|
||||
installed.add(sub_item)
|
||||
|
||||
return installed
|
||||
|
||||
def installedItemCount(self):
|
||||
"""
|
||||
Return the number of stock items installed inside this one.
|
||||
@ -1286,6 +1316,23 @@ class StockItem(MPTTModel):
|
||||
key = helpers.generateTestKey(result.test)
|
||||
result_map[key] = result
|
||||
|
||||
# Do we wish to include test results from installed items?
|
||||
include_installed = kwargs.get('include_installed', False)
|
||||
|
||||
# Do we wish to "cascade" and include test results from installed stock items?
|
||||
cascade = kwargs.get('cascade', False)
|
||||
|
||||
if include_installed:
|
||||
installed_items = get_installed_items(cascade=cascade)
|
||||
|
||||
for item in installed_items:
|
||||
item_results = item.testResultMap
|
||||
|
||||
for key in item_results.keys():
|
||||
# Results from sub items should not override master ones
|
||||
if key not in result_map.keys():
|
||||
result_map[key] = item_results[key]
|
||||
|
||||
return result_map
|
||||
|
||||
def testResultList(self, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user