Add "overdue" status to SalesOrder serializer

This commit is contained in:
Oliver Walters 2020-12-18 12:26:58 +11:00
parent 000348f70f
commit c6134b54ab
2 changed files with 30 additions and 6 deletions

View File

@ -9,6 +9,9 @@ from rest_framework import serializers
from sql_util.utils import SubqueryCount
from django.db.models import Case, When, Value
from django.db.models import BooleanField
from InvenTree.serializers import InvenTreeModelSerializer
from InvenTree.serializers import InvenTreeAttachmentSerializerField
@ -152,12 +155,24 @@ class SalesOrderSerializer(InvenTreeModelSerializer):
def annotate_queryset(queryset):
"""
Add extra information to the queryset
- Number of line items in the SalesOrder
- Overdue status of the SalesOrder
"""
queryset = queryset.annotate(
line_items=SubqueryCount('lines')
)
queryset = queryset.annotate(
overdue=Case(
When(
SalesOrder.OVERDUE_FILTER, then=Value(True, output_field=BooleanField()),
),
default=Value(False, output_field=BooleanField())
)
)
return queryset
customer_detail = CompanyBriefSerializer(source='customer', many=False, read_only=True)
@ -166,6 +181,8 @@ class SalesOrderSerializer(InvenTreeModelSerializer):
status_text = serializers.CharField(source='get_status_display', read_only=True)
overdue = serializers.BooleanField()
class Meta:
model = SalesOrder
@ -173,17 +190,18 @@ class SalesOrderSerializer(InvenTreeModelSerializer):
'pk',
'shipment_date',
'creation_date',
'description',
'line_items',
'link',
'reference',
'customer',
'customer_detail',
'customer_reference',
'description',
'line_items',
'link',
'notes',
'overdue',
'reference',
'status',
'status_text',
'shipment_date',
'notes',
]
read_only_fields = [

View File

@ -235,7 +235,13 @@ function loadSalesOrderTable(table, options) {
value = `${prefix}${value}`;
}
return renderLink(value, `/order/sales-order/${row.pk}/`);
var html = renderLink(value, `/order/sales-order/${row.pk}/`);
if (row.overdue) {
html += makeIconBadge('fa-calendar-times icon-red', '{% trans "Order is overdue" %}');
}
return html;
},
},
{