mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Cleanup "bom_invalid" filter
- Allow filtering by bom either valid or invalid - Use "bom_valid" as the filter (positive tense)
This commit is contained in:
parent
87d0d872e0
commit
1b6843e72d
@ -405,19 +405,23 @@ class PartList(generics.ListCreateAPIView):
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
pass
|
||||
|
||||
# Filter invalid BOMs
|
||||
bom_invalid = params.get('bom_invalid', None)
|
||||
# Filter by whether the BOM has been validated (or not)
|
||||
bom_valid = params.get('bom_valid', None)
|
||||
|
||||
if bom_invalid is not None:
|
||||
# Get assemblies with invalid BOMs
|
||||
assemblies = queryset.filter(active=True).filter(assembly=True)
|
||||
valid_boms = []
|
||||
if bom_valid is not None:
|
||||
|
||||
for part in assemblies:
|
||||
if part.is_bom_valid:
|
||||
valid_boms.append(part.pk)
|
||||
bom_valid = str2bool(bom_valid)
|
||||
|
||||
queryset = assemblies.exclude(pk__in=valid_boms)
|
||||
# Limit queryset to active assemblies
|
||||
queryset = queryset.filter(active=True, assembly=True)
|
||||
|
||||
pks = []
|
||||
|
||||
for part in queryset:
|
||||
if part.is_bom_valid() == bom_valid:
|
||||
pks.append(part.pk)
|
||||
|
||||
queryset = queryset.filter(pk__in=pks)
|
||||
|
||||
# Filter by 'starred' parts?
|
||||
starred = params.get('starred', None)
|
||||
@ -468,6 +472,7 @@ class PartList(generics.ListCreateAPIView):
|
||||
|
||||
# Filter by whether the part has stock
|
||||
has_stock = params.get("has_stock", None)
|
||||
|
||||
if has_stock is not None:
|
||||
has_stock = str2bool(has_stock)
|
||||
|
||||
|
@ -845,7 +845,6 @@ class Part(MPTTModel):
|
||||
|
||||
return str(hash.digest())
|
||||
|
||||
@property
|
||||
def is_bom_valid(self):
|
||||
""" Check if the BOM is 'valid' - if the calculated checksum matches the stored value
|
||||
"""
|
||||
|
@ -72,7 +72,7 @@ loadSimplePartTable("#starred-parts-table", "{% url 'api-part-list' %}", {
|
||||
|
||||
loadSimplePartTable("#bom-invalid-table", "{% url 'api-part-list' %}", {
|
||||
params: {
|
||||
"bom_invalid": true,
|
||||
"bom_valid": false,
|
||||
},
|
||||
name: 'bom_invalid_parts',
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user