AllProductsTransportViewSet

This commit is contained in:
2026-01-31 22:57:28 +03:30
parent 4eb98a1598
commit 643b06023c
78 changed files with 28 additions and 16 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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