mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Filter builds by "overdue" status
This commit is contained in:
parent
802dd5174c
commit
51da26d21d
@ -73,6 +73,17 @@ class BuildList(generics.ListCreateAPIView):
|
||||
else:
|
||||
queryset = queryset.exclude(status__in=BuildStatus.ACTIVE_CODES)
|
||||
|
||||
# Filter by "overdue" status?
|
||||
overdue = params.get('overdue', None)
|
||||
|
||||
if overdue is not None:
|
||||
overdue = str2bool(overdue)
|
||||
|
||||
if overdue:
|
||||
queryset = queryset.filter(Build.OVERDUE_FILTER)
|
||||
else:
|
||||
queryset = queryset.exclude(Build.OVERDUE_FILTER)
|
||||
|
||||
# Filter by associated part?
|
||||
part = params.get('part', None)
|
||||
|
||||
|
@ -14,7 +14,7 @@ from django.core.exceptions import ValidationError
|
||||
|
||||
from django.urls import reverse
|
||||
from django.db import models, transaction
|
||||
from django.db.models import Sum
|
||||
from django.db.models import Sum, Q
|
||||
from django.db.models.functions import Coalesce
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
@ -53,6 +53,8 @@ class Build(MPTTModel):
|
||||
notes: Text notes
|
||||
"""
|
||||
|
||||
OVERDUE_FILTER = Q(status__in=BuildStatus.ACTIVE_CODES) & ~Q(target_date=None) & Q(target_date__lte=datetime.now().date())
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("Build Order")
|
||||
verbose_name_plural = _("Build Orders")
|
||||
|
@ -48,14 +48,10 @@ class BuildSerializer(InvenTreeModelSerializer):
|
||||
|
||||
# Annotate a boolean 'overdue' flag
|
||||
|
||||
# Construct a filter for finding overdue builds
|
||||
today = datetime.datetime.now().date()
|
||||
overdue = Q(status__in=BuildStatus.ACTIVE_CODES) & ~Q(target_date=None) & Q(target_date__lte=today)
|
||||
|
||||
queryset = queryset.annotate(
|
||||
overdue=Case(
|
||||
When(
|
||||
overdue, then=Value(True, output_field=BooleanField()),
|
||||
Build.OVERDUE_FILTER, then=Value(True, output_field=BooleanField()),
|
||||
),
|
||||
default=Value(False, output_field=BooleanField())
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user