mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add "overdue" status to SalesOrder serializer
This commit is contained in:
parent
000348f70f
commit
c6134b54ab
@ -9,6 +9,9 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
from sql_util.utils import SubqueryCount
|
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 InvenTreeModelSerializer
|
||||||
from InvenTree.serializers import InvenTreeAttachmentSerializerField
|
from InvenTree.serializers import InvenTreeAttachmentSerializerField
|
||||||
|
|
||||||
@ -152,12 +155,24 @@ class SalesOrderSerializer(InvenTreeModelSerializer):
|
|||||||
def annotate_queryset(queryset):
|
def annotate_queryset(queryset):
|
||||||
"""
|
"""
|
||||||
Add extra information to the queryset
|
Add extra information to the queryset
|
||||||
|
|
||||||
|
- Number of line items in the SalesOrder
|
||||||
|
- Overdue status of the SalesOrder
|
||||||
"""
|
"""
|
||||||
|
|
||||||
queryset = queryset.annotate(
|
queryset = queryset.annotate(
|
||||||
line_items=SubqueryCount('lines')
|
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
|
return queryset
|
||||||
|
|
||||||
customer_detail = CompanyBriefSerializer(source='customer', many=False, read_only=True)
|
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)
|
status_text = serializers.CharField(source='get_status_display', read_only=True)
|
||||||
|
|
||||||
|
overdue = serializers.BooleanField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SalesOrder
|
model = SalesOrder
|
||||||
|
|
||||||
@ -173,17 +190,18 @@ class SalesOrderSerializer(InvenTreeModelSerializer):
|
|||||||
'pk',
|
'pk',
|
||||||
'shipment_date',
|
'shipment_date',
|
||||||
'creation_date',
|
'creation_date',
|
||||||
'description',
|
|
||||||
'line_items',
|
|
||||||
'link',
|
|
||||||
'reference',
|
|
||||||
'customer',
|
'customer',
|
||||||
'customer_detail',
|
'customer_detail',
|
||||||
'customer_reference',
|
'customer_reference',
|
||||||
|
'description',
|
||||||
|
'line_items',
|
||||||
|
'link',
|
||||||
|
'notes',
|
||||||
|
'overdue',
|
||||||
|
'reference',
|
||||||
'status',
|
'status',
|
||||||
'status_text',
|
'status_text',
|
||||||
'shipment_date',
|
'shipment_date',
|
||||||
'notes',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
|
@ -235,7 +235,13 @@ function loadSalesOrderTable(table, options) {
|
|||||||
value = `${prefix}${value}`;
|
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;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user