AllProductsTransportViewSet
This commit is contained in:
44
app/views.py
44
app/views.py
@@ -4735,31 +4735,40 @@ class AllProductsTransportDashboardView(APIView):
|
||||
product_type = request.GET.get('product_type')
|
||||
date1 = request.GET.get('date1') or None
|
||||
date2 = request.GET.get('date2') or None
|
||||
|
||||
filters={'trash':False}
|
||||
if province == 'undefined':
|
||||
province = None
|
||||
|
||||
queryset = AllProductsTransport.objects.filter(trash=False)
|
||||
|
||||
if product_type and product_type != 'undefined':
|
||||
queryset = queryset.filter(product=product_type)
|
||||
filters['product'] = product_type
|
||||
|
||||
|
||||
if date1 and date2 and date1 != 'undefined' and date2 != 'undefined':
|
||||
try:
|
||||
start_date = datetime.datetime.strptime(str(date1), '%Y-%m-%d')
|
||||
end_date = datetime.datetime.strptime(str(date2), '%Y-%m-%d')
|
||||
queryset = queryset.filter(date__gte=start_date, date__lte=end_date)
|
||||
filters['date__gte'] = start_date
|
||||
filters['date__lte'] = end_date
|
||||
except ValueError:
|
||||
pass
|
||||
destination_province = request.GET.get('destination_province')
|
||||
kill_house_filterset_class = AllProductsTransportFilterSet
|
||||
if destination_province and destination_province != 'undefined':
|
||||
if destination_province == 'مرکزی':
|
||||
filters['destination_province'] = 'مركزي'
|
||||
else:
|
||||
filters['destination_province'] = destination_province
|
||||
queryset = AllProductsTransport.objects.filter(**filters)
|
||||
|
||||
if search and search != 'undefined' and search.strip():
|
||||
queryset = queryset.filter(
|
||||
build_query(kill_house_filterset_class.Meta.fields, search)
|
||||
)
|
||||
|
||||
if role:
|
||||
if role == 'KillHouse':
|
||||
filters_query = {'trash':False}
|
||||
filters_kill_house = {}
|
||||
if province:
|
||||
filters_kill_house['Province'] = province
|
||||
@@ -4772,15 +4781,15 @@ class AllProductsTransportDashboardView(APIView):
|
||||
)
|
||||
|
||||
kill_house_codes = kill_house.values_list('PartIdCode', flat=True)
|
||||
bars = queryset.filter(jihadi_origin__in=kill_house_codes)
|
||||
filters_query['jihadi_origin__in']=kill_house_codes
|
||||
# bars = queryset.filter(jihadi_origin__in=kill_house_codes)
|
||||
|
||||
if destination_province and destination_province != 'undefined':
|
||||
if destination_province=='مرکزی':
|
||||
bars = bars.filter(destination_province='مركزي')
|
||||
|
||||
if destination_province == 'مرکزی':
|
||||
filters_query['destination_province'] = 'مركزي'
|
||||
else:
|
||||
bars = bars.filter(destination_province=destination_province)
|
||||
|
||||
filters_query['destination_province'] = destination_province
|
||||
bars = queryset.filter(**filters_query)
|
||||
aggregation = bars.aggregate(
|
||||
total=Sum('quantity'),
|
||||
input_total=Sum('quantity', filter=Q(out=False)),
|
||||
@@ -4823,6 +4832,7 @@ class AllProductsTransportDashboardView(APIView):
|
||||
|
||||
else:
|
||||
filters_steward = {}
|
||||
filters_query = {'ttrash':False}
|
||||
if province:
|
||||
filters_steward['province'] = province
|
||||
kill_house_filterset_class = AllProductsTransportFilterSet
|
||||
@@ -4840,12 +4850,11 @@ class AllProductsTransportDashboardView(APIView):
|
||||
).order_by('-modify_date')
|
||||
|
||||
if destination_province and destination_province != 'undefined':
|
||||
|
||||
if destination_province == 'مرکزی':
|
||||
bars = bars.filter(destination_province='مركزي')
|
||||
|
||||
filters_query['destination_province'] = 'مركزي'
|
||||
else:
|
||||
bars = bars.filter(destination_province=destination_province)
|
||||
filters_query['destination_province'] = destination_province
|
||||
bars = bars(**filters_query)
|
||||
aggregation = bars.aggregate(
|
||||
total=Sum('quantity'),
|
||||
input_total=Sum('quantity', filter=Q(out=False)),
|
||||
@@ -4885,8 +4894,11 @@ class AllProductsTransportDashboardView(APIView):
|
||||
"last_update": last_update,
|
||||
}, status=status.HTTP_200_OK)
|
||||
|
||||
if destination_province and destination_province != 'undefined':
|
||||
queryset = queryset.filter(destination_province=destination_province)
|
||||
# if destination_province and destination_province != 'undefined':
|
||||
# if destination_province == 'مرکزی':
|
||||
# queryset = queryset.filter(destination_province='مركزي')
|
||||
# else:
|
||||
# queryset = queryset.filter(destination_province=destination_province)
|
||||
|
||||
aggregation = queryset.aggregate(
|
||||
total=Sum('quantity'),
|
||||
|
||||
Reference in New Issue
Block a user