update excel
This commit is contained in:
Binary file not shown.
@@ -2578,8 +2578,7 @@ def import_transporting_detail(request):
|
|||||||
def all_products_transport_excel(request):
|
def all_products_transport_excel(request):
|
||||||
filterset_class = AllProductsTransportFilterSet
|
filterset_class = AllProductsTransportFilterSet
|
||||||
|
|
||||||
transports = AllProductsTransport.objects.filter(trash=False)
|
filters={"trash":False}
|
||||||
|
|
||||||
product_type = request.GET.get('product_type')
|
product_type = request.GET.get('product_type')
|
||||||
destination_province = request.GET.get('destination_province')
|
destination_province = request.GET.get('destination_province')
|
||||||
date1 = request.GET.get('date1')
|
date1 = request.GET.get('date1')
|
||||||
@@ -2587,26 +2586,52 @@ def all_products_transport_excel(request):
|
|||||||
search = request.GET.get('search')
|
search = request.GET.get('search')
|
||||||
|
|
||||||
if product_type and product_type != 'undefined':
|
if product_type and product_type != 'undefined':
|
||||||
transports = transports.filter(product=product_type)
|
filters['product'] = product_type
|
||||||
|
|
||||||
if destination_province and destination_province != 'undefined':
|
if destination_province and destination_province != 'undefined':
|
||||||
transports = transports.filter(destination_province=destination_province)
|
filters['destination_province'] = destination_province
|
||||||
|
|
||||||
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')
|
||||||
transports = transports.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
|
||||||
|
transports = (
|
||||||
|
AllProductsTransport.objects
|
||||||
|
.filter(**filters)
|
||||||
|
.values_list(
|
||||||
|
"tracking",
|
||||||
|
"product",
|
||||||
|
"items",
|
||||||
|
"quantity",
|
||||||
|
"unit",
|
||||||
|
"date",
|
||||||
|
"destination",
|
||||||
|
"jihadi_destination",
|
||||||
|
"destination_province",
|
||||||
|
"destination_city",
|
||||||
|
"origin",
|
||||||
|
"jihadi_origin",
|
||||||
|
"origin_province",
|
||||||
|
"origin_city",
|
||||||
|
"destination_prev",
|
||||||
|
"destination_changed",
|
||||||
|
"car_tracking_code",
|
||||||
|
"unloading_date",
|
||||||
|
"unloading",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if search:
|
if search and search != 'undefined' and search.strip():
|
||||||
if search != 'undefined' and search.strip():
|
|
||||||
transports = transports.filter(
|
transports = transports.filter(
|
||||||
build_query(filterset_class.Meta.fields, search)
|
build_query(filterset_class.Meta.fields, search)
|
||||||
)
|
)
|
||||||
|
transports = transports.iterator(chunk_size=2000)
|
||||||
|
|
||||||
serializer = AllProductsTransportCustomSerializer(transports.order_by('-date', '-create_date'), many=True).data
|
# serializer = AllProductsTransportCustomSerializer(transports.order_by('-date', '-create_date'), many=True).data
|
||||||
|
|
||||||
excel_options = [
|
excel_options = [
|
||||||
'ردیف',
|
'ردیف',
|
||||||
@@ -2670,40 +2695,42 @@ def all_products_transport_excel(request):
|
|||||||
create_header_freez(worksheet, excel_options, 1, 6, 7, 20)
|
create_header_freez(worksheet, excel_options, 1, 6, 7, 20)
|
||||||
l = 5
|
l = 5
|
||||||
m = 1
|
m = 1
|
||||||
if serializer:
|
total_quantity = 0
|
||||||
for data in serializer:
|
|
||||||
list1 = [
|
|
||||||
m, # ردیف
|
|
||||||
|
|
||||||
data.get("tracking"),
|
for row in transports:
|
||||||
data.get("product"),
|
quantity = row[3] or 0
|
||||||
data.get("items") if data.get("items") else '-',
|
total_quantity += quantity
|
||||||
data.get("quantity"),
|
|
||||||
data.get("unit"),
|
list1 = [
|
||||||
str(shamsi_date(convert_str_to_date(data.get("date")),in_value=True)) if data.get('date') else '-',
|
m,
|
||||||
data.get("destination"),
|
row[0], # tracking
|
||||||
data.get("jihadi_destination"),
|
row[1], # product
|
||||||
data.get("destination_province"),
|
row[2] or '-', # items
|
||||||
data.get("destination_city"),
|
quantity,
|
||||||
data.get("origin"),
|
row[4], # unit
|
||||||
data.get("jihadi_origin"),
|
str(shamsi_date(convert_str_to_date(row[5]), in_value=True)) if row[5] else '-',
|
||||||
data.get("origin_province"),
|
row[6], # destination
|
||||||
data.get("origin_city"),
|
row[7], # jihadi_destination
|
||||||
"داخل استان" if data.get("origin_province") == data.get("destination_province") else "خارج استان",
|
row[8], # destination_province
|
||||||
data.get("destination_prev") if data.get("destination_prev") else '-',
|
row[9], # destination_city
|
||||||
data.get("destination_changed") if data.get("destination_changed") else '-',
|
row[10], # origin
|
||||||
data.get("car_tracking_code"),
|
row[11], # jihadi_origin
|
||||||
str(shamsi_date(convert_str_to_date(data.get("unloading_date")), in_value=True)) if data.get("unloading_date") else '-',
|
row[12], # origin_province
|
||||||
data.get("unloading") if data.get("unloading") else '-',
|
row[13], # origin_city
|
||||||
|
"داخل استان" if row[12] == row[8] else "خارج استان",
|
||||||
|
row[14] or '-', # destination_prev
|
||||||
|
row[15] or '-', # destination_changed
|
||||||
|
row[16], # car_tracking_code
|
||||||
|
str(shamsi_date(convert_str_to_date(row[17]), in_value=True)) if row[17] else '-',
|
||||||
|
row[18] or '-', # unloading
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
m += 1
|
m += 1
|
||||||
|
|
||||||
l += 1
|
l += 1
|
||||||
create_value(worksheet, list1, l + 1, 1)
|
create_value(worksheet, list1, l + 1, 1)
|
||||||
total_quantity = sum(
|
|
||||||
item['quantity'] for item in serializer)
|
# total_quantity = sum(
|
||||||
|
# item['quantity'] for item in serializer)
|
||||||
# aggregation1_bars = all_bars.aggregate(
|
# aggregation1_bars = all_bars.aggregate(
|
||||||
# total=Sum('GoodAmount'),
|
# total=Sum('GoodAmount'),
|
||||||
# input_total=Sum('GoodAmount', filter=Q(Out=False)),
|
# input_total=Sum('GoodAmount', filter=Q(Out=False)),
|
||||||
|
|||||||
Reference in New Issue
Block a user