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):
|
except (ValueError, Part.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Filter invalid BOMs
|
# Filter by whether the BOM has been validated (or not)
|
||||||
bom_invalid = params.get('bom_invalid', None)
|
bom_valid = params.get('bom_valid', None)
|
||||||
|
|
||||||
if bom_invalid is not None:
|
if bom_valid is not None:
|
||||||
# Get assemblies with invalid BOMs
|
|
||||||
assemblies = queryset.filter(active=True).filter(assembly=True)
|
|
||||||
valid_boms = []
|
|
||||||
|
|
||||||
for part in assemblies:
|
bom_valid = str2bool(bom_valid)
|
||||||
if part.is_bom_valid:
|
|
||||||
valid_boms.append(part.pk)
|
|
||||||
|
|
||||||
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?
|
# Filter by 'starred' parts?
|
||||||
starred = params.get('starred', None)
|
starred = params.get('starred', None)
|
||||||
@ -468,6 +472,7 @@ class PartList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
# Filter by whether the part has stock
|
# Filter by whether the part has stock
|
||||||
has_stock = params.get("has_stock", None)
|
has_stock = params.get("has_stock", None)
|
||||||
|
|
||||||
if has_stock is not None:
|
if has_stock is not None:
|
||||||
has_stock = str2bool(has_stock)
|
has_stock = str2bool(has_stock)
|
||||||
|
|
||||||
|
@ -845,7 +845,6 @@ class Part(MPTTModel):
|
|||||||
|
|
||||||
return str(hash.digest())
|
return str(hash.digest())
|
||||||
|
|
||||||
@property
|
|
||||||
def is_bom_valid(self):
|
def is_bom_valid(self):
|
||||||
""" Check if the BOM is 'valid' - if the calculated checksum matches the stored value
|
""" 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' %}", {
|
loadSimplePartTable("#bom-invalid-table", "{% url 'api-part-list' %}", {
|
||||||
params: {
|
params: {
|
||||||
"bom_invalid": true,
|
"bom_valid": false,
|
||||||
},
|
},
|
||||||
name: 'bom_invalid_parts',
|
name: 'bom_invalid_parts',
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user