forked from erp-dev/erp
fix: exclude ran out state_id for api_v2.get_plate_orders_bet_by_state_status
This commit is contained in:
@@ -3,7 +3,7 @@ import datetime
|
||||
from django.utils import timezone
|
||||
from django.db import transaction
|
||||
from django.db import models as django_models
|
||||
from django.db.models import Q, Count, CharField, Prefetch, Exists, OuterRef
|
||||
from django.db.models import Q, Count, CharField, Prefetch, Exists, OuterRef, Subquery
|
||||
from django.db.models.functions import Cast, Coalesce
|
||||
from rest_framework import serializers, status, permissions
|
||||
from rest_framework.pagination import LimitOffsetPagination
|
||||
@@ -1092,6 +1092,21 @@ class PlateOrderByStateStatusView(APIView):
|
||||
)
|
||||
)
|
||||
|
||||
if status_value == 'completed':
|
||||
latest_completed_state_subquery = (
|
||||
stateflow_models.StateFlowRecord.objects
|
||||
.filter(
|
||||
business_object_id=OuterRef('business_object_id'),
|
||||
is_cancelled=False,
|
||||
)
|
||||
.order_by('-completed_at', '-id')
|
||||
)
|
||||
queryset = queryset.annotate(
|
||||
latest_completed_state_id=Subquery(
|
||||
latest_completed_state_subquery.values('state_id')[:1]
|
||||
)
|
||||
).filter(latest_completed_state_id=state_id_int)
|
||||
|
||||
ordering = (qp.get('ordering') or '-created_at').strip() or '-created_at'
|
||||
direction = '-' if ordering.startswith('-') else ''
|
||||
field = ordering[1:] if ordering.startswith('-') else ordering
|
||||
|
||||
Reference in New Issue
Block a user