Coverage for apps/orders/filters.py: 74%
13 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-11 13:52 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-10-11 13:52 -0600
1import django_filters
2from django.utils import timezone
3from django_filters import rest_framework as filters
5from .models import Order
8class OrderFilter(filters.FilterSet):
9 """
10 Filter for Order
11 """
13 is_delayed = django_filters.BooleanFilter(method="is_delayed_filter")
15 class Meta:
16 model = Order
17 fields = {
18 "week": ["exact"],
19 "week__period": ["exact"],
20 "supplier": ["exact"],
21 "items": ["exact"],
22 "cancellation_date": ["gte", "lte"],
23 "delivery_date": ["gte", "lte", "lt"],
24 "status": ["exact", "in"],
25 }
27 def is_delayed_filter(self, queryset, name, value):
28 if value:
29 return queryset.filter(
30 status__in=[Order.Status.PENDING, Order.Status.PARTIAL],
31 delivery_date__lt=timezone.datetime.today().date(),
32 )
33 else:
34 return queryset.filter(
35 delivery_date__gte=timezone.datetime.today().date(),
36 )