mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add "overdue" flag to serializer
- Also allow filtering by overdue status in the API
This commit is contained in:
parent
834d9ec9a1
commit
4d73aab090
@ -80,6 +80,17 @@ class POList(generics.ListCreateAPIView):
|
|||||||
else:
|
else:
|
||||||
queryset = queryset.exclude(status__in=PurchaseOrderStatus.OPEN)
|
queryset = queryset.exclude(status__in=PurchaseOrderStatus.OPEN)
|
||||||
|
|
||||||
|
# Filter by 'overdue' status
|
||||||
|
overdue = params.get('overdue', None)
|
||||||
|
|
||||||
|
if overdue is not None:
|
||||||
|
overdue = str2bool(overdue)
|
||||||
|
|
||||||
|
if overdue:
|
||||||
|
queryset = queryset.filter(PurchaseOrder.OVERDUE_FILTER)
|
||||||
|
else:
|
||||||
|
queryset = queryset.exclude(PurchaseOrder.OVERDUE_FILTER)
|
||||||
|
|
||||||
# Special filtering for 'status' field
|
# Special filtering for 'status' field
|
||||||
status = params.get('status', None)
|
status = params.get('status', None)
|
||||||
|
|
||||||
|
@ -40,12 +40,24 @@ class POSerializer(InvenTreeModelSerializer):
|
|||||||
def annotate_queryset(queryset):
|
def annotate_queryset(queryset):
|
||||||
"""
|
"""
|
||||||
Add extra information to the queryset
|
Add extra information to the queryset
|
||||||
|
|
||||||
|
- Number of liens in the PurchaseOrder
|
||||||
|
- Overdue status of the PurchaseOrder
|
||||||
"""
|
"""
|
||||||
|
|
||||||
queryset = queryset.annotate(
|
queryset = queryset.annotate(
|
||||||
line_items=SubqueryCount('lines')
|
line_items=SubqueryCount('lines')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
queryset = queryset.annotate(
|
||||||
|
overdue=Case(
|
||||||
|
When(
|
||||||
|
PurchaseOrder.OVERDUE_FILTER, then=Value(True, output_field=BooleanField()),
|
||||||
|
),
|
||||||
|
default=Value(False, output_field=BooleanField())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
supplier_detail = CompanyBriefSerializer(source='supplier', many=False, read_only=True)
|
supplier_detail = CompanyBriefSerializer(source='supplier', many=False, read_only=True)
|
||||||
@ -54,6 +66,8 @@ class POSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||||
|
|
||||||
|
overdue = serializers.BooleanField(required=False, read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PurchaseOrder
|
model = PurchaseOrder
|
||||||
|
|
||||||
@ -65,6 +79,7 @@ class POSerializer(InvenTreeModelSerializer):
|
|||||||
'description',
|
'description',
|
||||||
'line_items',
|
'line_items',
|
||||||
'link',
|
'link',
|
||||||
|
'overdue',
|
||||||
'reference',
|
'reference',
|
||||||
'supplier',
|
'supplier',
|
||||||
'supplier_detail',
|
'supplier_detail',
|
||||||
|
Loading…
Reference in New Issue
Block a user