| 4607 |
rajveer |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
Creates a CSV report of all the shipped orders and send mail to Sandeep.
|
|
|
5 |
|
|
|
6 |
Created on 20-Feb-2012
|
|
|
7 |
|
|
|
8 |
@author: Rajveer
|
|
|
9 |
'''
|
| 5944 |
mandeep.dh |
10 |
from optparse import OptionParser
|
|
|
11 |
from shop2020.clients.InventoryClient import InventoryClient
|
|
|
12 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
13 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 11795 |
manish.sha |
14 |
from shop2020.thriftpy.model.v1.order.ttypes import Order, DelayReason, OrderStatus
|
| 6004 |
rajveer |
15 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail_html
|
| 5944 |
mandeep.dh |
16 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
|
|
17 |
import datetime
|
| 4607 |
rajveer |
18 |
import xlwt
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
if __name__ == '__main__' and __package__ is None:
|
|
|
23 |
import sys
|
|
|
24 |
import os
|
|
|
25 |
sys.path.insert(0, os.getcwd())
|
| 8405 |
amar.kumar |
26 |
#to = ["amar.kumar@shop2020.in"]
|
| 11977 |
manish.sha |
27 |
to = ["anikendra.das@saholic.com","sandeep.sachdeva@shop2020.in","amit.sirohi@shop2020.in", "chaitnaya.vats@shop2020.in", "khushal.bhatia@shop2020.in", "rajneesh.arora@shop2020.in", "chandan.kumar@shop2020.in","manoj.kumar@shop2020.in", "manoj.pal@saholic.com", "yukti.jain@saholic.com", "ankush.dhingra@saholic.com"]
|
| 4607 |
rajveer |
28 |
|
| 4709 |
rajveer |
29 |
def generate_delayed_orders_file():
|
| 4607 |
rajveer |
30 |
txn_client = TransactionClient().get_client()
|
|
|
31 |
slipped_orders = txn_client.getSlippedSippingDateOrders()
|
|
|
32 |
|
|
|
33 |
wbk = xlwt.Workbook()
|
|
|
34 |
sheet = wbk.add_sheet('main')
|
|
|
35 |
|
|
|
36 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
|
|
|
37 |
sheet.set_panes_frozen(True)
|
|
|
38 |
sheet.set_horz_split_pos(1)
|
|
|
39 |
sheet.set_remove_splits(True)
|
|
|
40 |
|
|
|
41 |
excel_integer_format = '0'
|
|
|
42 |
integer_style = xlwt.XFStyle()
|
|
|
43 |
integer_style.num_format_str = excel_integer_format
|
|
|
44 |
|
|
|
45 |
date_style = xlwt.XFStyle()
|
|
|
46 |
date_style.num_format_str = "M/D/YY"
|
|
|
47 |
|
|
|
48 |
sheet.write(0, 0, "Order ID", heading_xf)
|
| 19412 |
manish.sha |
49 |
sheet.write(0, 1, "Transaction ID", heading_xf)
|
|
|
50 |
sheet.write(0, 2, "Source", heading_xf)
|
|
|
51 |
sheet.write(0, 3, "Mode.", heading_xf)
|
|
|
52 |
sheet.write(0, 4, "Brand", heading_xf)
|
|
|
53 |
sheet.write(0, 5, "Model Name", heading_xf)
|
|
|
54 |
sheet.write(0, 6, "Model Number", heading_xf)
|
|
|
55 |
sheet.write(0, 7, "Colour", heading_xf)
|
|
|
56 |
sheet.write(0, 8, "Quantity", heading_xf)
|
|
|
57 |
sheet.write(0, 9, "Creation Date", heading_xf)
|
|
|
58 |
sheet.write(0, 10, "Promised Shipping Date", heading_xf)
|
|
|
59 |
sheet.write(0, 11, "Expected Shipping Date", heading_xf)
|
|
|
60 |
sheet.write(0, 12, "Delay Reason", heading_xf)
|
|
|
61 |
sheet.write(0, 13, "Detailed Reason Text", heading_xf)
|
|
|
62 |
|
| 5631 |
amar.kumar |
63 |
html = """\
|
|
|
64 |
<html>
|
|
|
65 |
<head>
|
|
|
66 |
<style type="text/css">
|
|
|
67 |
table, tr, th { border :1px solid black;}
|
|
|
68 |
</style>
|
|
|
69 |
</head>
|
|
|
70 |
<body>
|
|
|
71 |
<center><h3>Delayed Orders</h3></center>
|
|
|
72 |
<table>
|
|
|
73 |
<tr>
|
|
|
74 |
<th>Order ID</th>
|
| 19412 |
manish.sha |
75 |
<th>Txn Id</th>
|
| 8732 |
amar.kumar |
76 |
<th>Source</th>
|
| 5631 |
amar.kumar |
77 |
<th>Mode</th>
|
|
|
78 |
<th>Brand</th>
|
|
|
79 |
<th>Model Name</th>
|
|
|
80 |
<th>Model Number</th>
|
|
|
81 |
<th>Colour</th>
|
| 19412 |
manish.sha |
82 |
<th>Quantity</th>
|
| 5631 |
amar.kumar |
83 |
<th>Creation Date</th>
|
|
|
84 |
<th>Promised Shipping Date</th>
|
|
|
85 |
<th>Expected Shipping Date</th>
|
|
|
86 |
<th>Delay Reason</th>
|
|
|
87 |
<th>Detailed Reason Text</th>
|
|
|
88 |
</tr>
|
|
|
89 |
"""
|
|
|
90 |
|
| 4607 |
rajveer |
91 |
order = Order()
|
|
|
92 |
mode = {}
|
|
|
93 |
mode[0] = 'Prepaid'
|
|
|
94 |
mode[1] = 'COD'
|
| 8732 |
amar.kumar |
95 |
source = {}
|
|
|
96 |
source[1] = 'WEBSITE'
|
|
|
97 |
source[2] = 'STORE'
|
|
|
98 |
source[3] = 'AMAZON'
|
|
|
99 |
source[4] = 'HOMESHOP18'
|
|
|
100 |
source[5] = 'NAAPTOL'
|
|
|
101 |
source[6] = 'EBAY'
|
|
|
102 |
source[7] = 'SNAPDEAL'
|
| 9134 |
vikram.rag |
103 |
source[8] = 'FLIPKART'
|
| 11795 |
manish.sha |
104 |
source[9] = 'MOBILESITE'
|
| 8732 |
amar.kumar |
105 |
source[10] = 'UNKNOWN'
|
| 4607 |
rajveer |
106 |
|
|
|
107 |
i = 1
|
|
|
108 |
for order in slipped_orders:
|
| 11795 |
manish.sha |
109 |
if order.source ==8 and order.status == OrderStatus.BILLED:
|
|
|
110 |
continue
|
| 5631 |
amar.kumar |
111 |
html +="<tr>"
|
|
|
112 |
sheet.write(i, 0, order.id)
|
|
|
113 |
html +="<td>" + str(order.id) + "</td>"
|
| 19412 |
manish.sha |
114 |
sheet.write(i, 1, order.transaction_id)
|
|
|
115 |
html +="<td>" + str(order.transaction_id) + "</td>"
|
|
|
116 |
sheet.write(i, 2, source[order.source])
|
| 8732 |
amar.kumar |
117 |
html +="<td>" + str(source[order.source]) + "</td>"
|
| 19412 |
manish.sha |
118 |
sheet.write(i, 3, mode[order.cod])
|
| 5631 |
amar.kumar |
119 |
html +="<td>" + str(mode[order.cod]) + "</td>"
|
| 4607 |
rajveer |
120 |
lineitem = order.lineitems[0]
|
| 19412 |
manish.sha |
121 |
sheet.write(i, 4, lineitem.brand)
|
| 5631 |
amar.kumar |
122 |
html +="<td>" + str(lineitem.brand) + "</td>"
|
| 19412 |
manish.sha |
123 |
sheet.write(i, 5, lineitem.model_name)
|
| 5631 |
amar.kumar |
124 |
html +="<td>" + str(lineitem.model_name) + "</td>"
|
| 19412 |
manish.sha |
125 |
sheet.write(i, 6, lineitem.model_number)
|
| 5631 |
amar.kumar |
126 |
html +="<td>" + str(lineitem.model_number) + "</td>"
|
| 19412 |
manish.sha |
127 |
sheet.write(i, 7, lineitem.color)
|
| 5631 |
amar.kumar |
128 |
html +="<td>" + str(lineitem.color) + "</td>"
|
| 19412 |
manish.sha |
129 |
sheet.write(i, 8, lineitem.quantity)
|
|
|
130 |
html +="<td>" + str(lineitem.quantity) + "</td>"
|
|
|
131 |
sheet.write(i, 9, to_py_date(order.created_timestamp), date_style)
|
| 5631 |
amar.kumar |
132 |
html +="<td>" + str(to_py_date(order.created_timestamp)) + "</td>"
|
| 19412 |
manish.sha |
133 |
sheet.write(i, 10, to_py_date(order.promised_shipping_time), date_style)
|
| 5631 |
amar.kumar |
134 |
html +="<td>" + str(to_py_date(order.promised_shipping_time)) + "</td>"
|
| 19412 |
manish.sha |
135 |
sheet.write(i, 11, to_py_date(order.expected_shipping_time), date_style)
|
| 5631 |
amar.kumar |
136 |
html +="<td>" + str(to_py_date(order.expected_shipping_time)) + "</td>"
|
| 4635 |
rajveer |
137 |
if order.delayReason:
|
| 19412 |
manish.sha |
138 |
sheet.write(i, 12, DelayReason._VALUES_TO_NAMES[order.delayReason])
|
| 5631 |
amar.kumar |
139 |
html +="<td>" + str(DelayReason._VALUES_TO_NAMES[order.delayReason]) + "</td>"
|
| 19412 |
manish.sha |
140 |
sheet.write(i, 13, order.delayReasonText)
|
| 5631 |
amar.kumar |
141 |
html +="<td>" + str(order.delayReasonText) + "</td>"
|
|
|
142 |
html +="</tr>"
|
| 4607 |
rajveer |
143 |
i= i+1
|
|
|
144 |
|
|
|
145 |
today = datetime.date.today()
|
|
|
146 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
|
|
147 |
filename = "/tmp/SlippedOrders-" + datestr + ".xls"
|
|
|
148 |
wbk.save(filename)
|
| 5631 |
amar.kumar |
149 |
html +="</table></body></html>"
|
| 4607 |
rajveer |
150 |
try:
|
|
|
151 |
part = get_attachment_part(filename)
|
| 5631 |
amar.kumar |
152 |
mail_html("cnc.center@shop2020.in", "5h0p2o2o", to, "Slipped Orders as on: " + datestr, html, [part])
|
| 4607 |
rajveer |
153 |
finally:
|
|
|
154 |
os.remove(filename)
|
|
|
155 |
|
| 4709 |
rajveer |
156 |
def generate_cancelled_orders_file():
|
|
|
157 |
txn_client = TransactionClient().get_client()
|
|
|
158 |
#cancelled_orders = txn_client.getAllOrders(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY, to_java_date(datetime.datetime.now() - datetime.timedelta(hours = 24)), to_java_date(datetime.datetime.now()), -1)
|
|
|
159 |
cancelled_orders = txn_client.getCancelledOrders(to_java_date(datetime.datetime.now() - datetime.timedelta(hours = 24)), to_java_date(datetime.datetime.now()))
|
|
|
160 |
|
|
|
161 |
wbk = xlwt.Workbook()
|
|
|
162 |
sheet = wbk.add_sheet('main')
|
|
|
163 |
|
|
|
164 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
|
|
|
165 |
sheet.set_panes_frozen(True)
|
|
|
166 |
sheet.set_horz_split_pos(1)
|
|
|
167 |
sheet.set_remove_splits(True)
|
|
|
168 |
|
|
|
169 |
excel_integer_format = '0'
|
|
|
170 |
integer_style = xlwt.XFStyle()
|
|
|
171 |
integer_style.num_format_str = excel_integer_format
|
|
|
172 |
|
|
|
173 |
date_style = xlwt.XFStyle()
|
|
|
174 |
date_style.num_format_str = "M/D/YY"
|
|
|
175 |
|
|
|
176 |
sheet.write(0, 0, "Order ID", heading_xf)
|
|
|
177 |
sheet.write(0, 1, "Mode.", heading_xf)
|
| 8403 |
amar.kumar |
178 |
sheet.write(0, 2, "Source", heading_xf)
|
|
|
179 |
sheet.write(0, 3, "Brand", heading_xf)
|
|
|
180 |
sheet.write(0, 4, "Model Name", heading_xf)
|
|
|
181 |
sheet.write(0, 5, "Model Number", heading_xf)
|
|
|
182 |
sheet.write(0, 6, "Colour", heading_xf)
|
|
|
183 |
sheet.write(0, 7, "Creation Date", heading_xf)
|
|
|
184 |
sheet.write(0, 8, "Promised Shipping Date", heading_xf)
|
|
|
185 |
sheet.write(0, 9, "Expected Shipping Date", heading_xf)
|
|
|
186 |
sheet.write(0, 10, "Cancellation Reason", heading_xf)
|
|
|
187 |
sheet.write(0, 11, "Cancellation Date", heading_xf)
|
| 4709 |
rajveer |
188 |
|
| 5631 |
amar.kumar |
189 |
html = """\
|
|
|
190 |
<html>
|
|
|
191 |
<head>
|
|
|
192 |
<style type="text/css">
|
|
|
193 |
table, tr, th { border :1px solid black;}
|
|
|
194 |
</style>
|
|
|
195 |
</head>
|
|
|
196 |
<body>
|
| 9134 |
vikram.rag |
197 |
<center><h3>Low Inventory Cancelled Orders</h3></center>
|
| 5631 |
amar.kumar |
198 |
<table>
|
|
|
199 |
<tr>
|
|
|
200 |
<th>Order ID</th>
|
|
|
201 |
<th>Mode</th>
|
| 8403 |
amar.kumar |
202 |
<th>Source</th>
|
| 5631 |
amar.kumar |
203 |
<th>Brand</th>
|
|
|
204 |
<th>Model Name</th>
|
|
|
205 |
<th>Model Number</th>
|
|
|
206 |
<th>Colour</th>
|
|
|
207 |
<th>Creation Date</th>
|
|
|
208 |
<th>Promised Shipping Date</th>
|
|
|
209 |
<th>Expected Shipping Date</th>
|
|
|
210 |
<th>Cancellation Reason</th>
|
|
|
211 |
<th>Cancellation Date</th>
|
|
|
212 |
</tr>
|
|
|
213 |
"""
|
|
|
214 |
|
|
|
215 |
|
| 4709 |
rajveer |
216 |
order = Order()
|
|
|
217 |
mode = {}
|
|
|
218 |
mode[0] = 'Prepaid'
|
|
|
219 |
mode[1] = 'COD'
|
| 8403 |
amar.kumar |
220 |
source = {}
|
|
|
221 |
source[1] = 'WEBSITE'
|
|
|
222 |
source[2] = 'STORE'
|
|
|
223 |
source[3] = 'AMAZON'
|
|
|
224 |
source[4] = 'HOMESHOP18'
|
|
|
225 |
source[5] = 'NAAPTOL'
|
|
|
226 |
source[6] = 'EBAY'
|
|
|
227 |
source[7] = 'SNAPDEAL'
|
| 9134 |
vikram.rag |
228 |
source[8] = 'FLIPKART'
|
| 8403 |
amar.kumar |
229 |
source[9] = 'UNKNOWN'
|
|
|
230 |
source[10] = 'UNKNOWN'
|
| 4709 |
rajveer |
231 |
|
|
|
232 |
i = 1
|
|
|
233 |
for order in cancelled_orders:
|
| 5631 |
amar.kumar |
234 |
html +="<tr>"
|
| 4709 |
rajveer |
235 |
sheet.write(i, 0, order.id)
|
| 5631 |
amar.kumar |
236 |
html +="<td>" + str(order.id) + "</td>"
|
| 4709 |
rajveer |
237 |
sheet.write(i, 1, mode[order.cod])
|
| 5631 |
amar.kumar |
238 |
html +="<td>" + str(mode[order.cod]) + "</td>"
|
| 8404 |
amar.kumar |
239 |
sheet.write(i, 2, source[order.source])
|
|
|
240 |
html +="<td>" + str(source[order.source]) + "</td>"
|
| 4709 |
rajveer |
241 |
lineitem = order.lineitems[0]
|
| 8403 |
amar.kumar |
242 |
sheet.write(i, 3, lineitem.brand)
|
| 5631 |
amar.kumar |
243 |
html +="<td>" + str(lineitem.brand) + "</td>"
|
| 8403 |
amar.kumar |
244 |
sheet.write(i, 4, lineitem.model_name)
|
| 5631 |
amar.kumar |
245 |
html +="<td>" + str(lineitem.model_name) + "</td>"
|
| 8403 |
amar.kumar |
246 |
sheet.write(i, 5, lineitem.model_number)
|
| 5631 |
amar.kumar |
247 |
html +="<td>" + str(lineitem.model_number) + "</td>"
|
| 8403 |
amar.kumar |
248 |
sheet.write(i, 6, lineitem.color)
|
| 5631 |
amar.kumar |
249 |
html +="<td>" + str(lineitem.color) + "</td>"
|
| 4709 |
rajveer |
250 |
|
| 8403 |
amar.kumar |
251 |
sheet.write(i, 7, to_py_date(order.created_timestamp), date_style)
|
| 5631 |
amar.kumar |
252 |
html +="<td>" + str(to_py_date(order.created_timestamp)) + "</td>"
|
| 8403 |
amar.kumar |
253 |
sheet.write(i, 8, to_py_date(order.promised_shipping_time), date_style)
|
| 5631 |
amar.kumar |
254 |
html +="<td>" + str(to_py_date(order.promised_shipping_time)) + "</td>"
|
| 8403 |
amar.kumar |
255 |
sheet.write(i, 9, to_py_date(order.expected_shipping_time), date_style)
|
| 5631 |
amar.kumar |
256 |
html +="<td>" + str(to_py_date(order.expected_shipping_time)) + "</td>"
|
| 8403 |
amar.kumar |
257 |
sheet.write(i, 10, order.refundReason)
|
| 5631 |
amar.kumar |
258 |
html +="<td>" + str(order.refundReason) + "</td>"
|
| 8403 |
amar.kumar |
259 |
sheet.write(i, 11, to_py_date(order.refund_timestamp), date_style)
|
| 5631 |
amar.kumar |
260 |
html +="<td>" + str(to_py_date(order.refund_timestamp)) + "</td>"
|
|
|
261 |
html +="<td>" + str(order.delayReasonText) + "</td>"
|
|
|
262 |
html +="</tr>"
|
| 4709 |
rajveer |
263 |
|
|
|
264 |
i= i+1
|
|
|
265 |
|
|
|
266 |
today = datetime.date.today()
|
|
|
267 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
|
|
268 |
filename = "/tmp/CancelledOrders-" + datestr + ".xls"
|
|
|
269 |
wbk.save(filename)
|
| 5631 |
amar.kumar |
270 |
html +="</table></body></html>"
|
| 4709 |
rajveer |
271 |
|
|
|
272 |
try:
|
|
|
273 |
part = get_attachment_part(filename)
|
| 5631 |
amar.kumar |
274 |
mail_html("cnc.center@shop2020.in", "5h0p2o2o", to, "Low Inventory Cancelled Orders as on: " + datestr, html, [part])
|
| 4709 |
rajveer |
275 |
finally:
|
|
|
276 |
os.remove(filename)
|
| 4783 |
phani.kuma |
277 |
|
|
|
278 |
def generate_expected_delivery_missed_orders_file():
|
|
|
279 |
|
|
|
280 |
txn_client = TransactionClient().get_client()
|
|
|
281 |
orders_not_delivered = txn_client.getUndeliveredOrdersExpectedDeliveryDateNotMet()
|
|
|
282 |
|
|
|
283 |
print "orders_not_delivered"
|
|
|
284 |
print orders_not_delivered
|
|
|
285 |
|
|
|
286 |
logistics_client = LogisticsClient().get_client()
|
|
|
287 |
providers = logistics_client.getAllProviders()
|
|
|
288 |
providers_map = {}
|
|
|
289 |
for provider in providers:
|
|
|
290 |
providers_map[provider.id] = provider.name
|
|
|
291 |
|
| 5944 |
mandeep.dh |
292 |
inventory_client = InventoryClient().get_client()
|
|
|
293 |
warehouses = inventory_client.getAllWarehouses(True)
|
| 4783 |
phani.kuma |
294 |
warehouses_map = {}
|
|
|
295 |
for warehouse in warehouses:
|
|
|
296 |
warehouses_map[warehouse.id] = warehouse.displayName
|
|
|
297 |
|
|
|
298 |
wbk = xlwt.Workbook()
|
|
|
299 |
sheet = wbk.add_sheet('main')
|
|
|
300 |
|
|
|
301 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
|
|
|
302 |
sheet.set_panes_frozen(True)
|
|
|
303 |
sheet.set_horz_split_pos(1)
|
|
|
304 |
sheet.set_remove_splits(True)
|
|
|
305 |
|
|
|
306 |
excel_integer_format = '0'
|
|
|
307 |
integer_style = xlwt.XFStyle()
|
|
|
308 |
integer_style.num_format_str = excel_integer_format
|
|
|
309 |
|
|
|
310 |
date_style = xlwt.XFStyle()
|
|
|
311 |
date_style.num_format_str = "M/D/YY"
|
|
|
312 |
|
|
|
313 |
sheet.write(0, 0, "Order ID", heading_xf)
|
|
|
314 |
sheet.write(0, 1, "Mode.", heading_xf)
|
| 8403 |
amar.kumar |
315 |
sheet.write(0, 2, "Source", heading_xf)
|
|
|
316 |
sheet.write(0, 3, "Airway BillNo", heading_xf)
|
|
|
317 |
sheet.write(0, 4, "Current Status", heading_xf)
|
|
|
318 |
sheet.write(0, 5, "Shipping Date", heading_xf)
|
|
|
319 |
sheet.write(0, 6, "Pickup Date", heading_xf)
|
|
|
320 |
sheet.write(0, 7, "Expected Delivery Date", heading_xf)
|
|
|
321 |
sheet.write(0, 8, "Warehouse", heading_xf)
|
|
|
322 |
sheet.write(0, 9, "Warehouse ID", heading_xf)
|
|
|
323 |
sheet.write(0, 10, "Logistics Provider", heading_xf)
|
|
|
324 |
sheet.write(0, 11, "Logistics Provider ID", heading_xf)
|
|
|
325 |
sheet.write(0, 12, "Customer City", heading_xf)
|
|
|
326 |
sheet.write(0, 13, "Customer State", heading_xf)
|
|
|
327 |
sheet.write(0, 14, "Customer Pincode", heading_xf)
|
| 4783 |
phani.kuma |
328 |
|
| 5631 |
amar.kumar |
329 |
html = """\
|
|
|
330 |
<html>
|
|
|
331 |
<head>
|
|
|
332 |
<style type="text/css">
|
|
|
333 |
table, tr, th { border :1px solid black;}
|
|
|
334 |
</style>
|
|
|
335 |
</head>
|
|
|
336 |
<body>
|
|
|
337 |
<center><h3>Delayed Orders</h3></center>
|
|
|
338 |
<table border=1>
|
|
|
339 |
<tr>
|
|
|
340 |
<th>Order ID</th>
|
|
|
341 |
<th>Mode</th>
|
| 8403 |
amar.kumar |
342 |
<th>Source</th>
|
| 5631 |
amar.kumar |
343 |
<th>Airway BillNo</th>
|
|
|
344 |
<th>Current Status</th>
|
|
|
345 |
<th>Shipping Date</th>
|
|
|
346 |
<th>Pickup Date</th>
|
|
|
347 |
<th>Expected Delivery Date</th>
|
|
|
348 |
<th>Warehouse</th>
|
|
|
349 |
<th>Warehouse ID</th>
|
|
|
350 |
<th>Logistics Provider</th>
|
|
|
351 |
<th>Logistics Provider ID</th>
|
|
|
352 |
<th>Customer City</th>
|
|
|
353 |
<th>Customer State</th>
|
|
|
354 |
<th>Customer Pincode</th>
|
|
|
355 |
</tr>
|
|
|
356 |
"""
|
|
|
357 |
|
| 4783 |
phani.kuma |
358 |
order = Order()
|
|
|
359 |
mode = {}
|
|
|
360 |
mode[0] = 'Prepaid'
|
|
|
361 |
mode[1] = 'COD'
|
|
|
362 |
|
| 8403 |
amar.kumar |
363 |
source = {}
|
|
|
364 |
source[1] = 'WEBSITE'
|
|
|
365 |
source[2] = 'STORE'
|
|
|
366 |
source[3] = 'AMAZON'
|
|
|
367 |
source[4] = 'HOMESHOP18'
|
|
|
368 |
source[5] = 'NAAPTOL'
|
|
|
369 |
source[6] = 'EBAY'
|
|
|
370 |
source[7] = 'SNAPDEAL'
|
| 9134 |
vikram.rag |
371 |
source[8] = 'FLIPKART'
|
| 8403 |
amar.kumar |
372 |
source[9] = 'UNKNOWN'
|
|
|
373 |
source[10] = 'UNKNOWN'
|
|
|
374 |
|
| 4783 |
phani.kuma |
375 |
i = 1
|
|
|
376 |
for order in orders_not_delivered:
|
| 5631 |
amar.kumar |
377 |
html +="<tr>"
|
| 4783 |
phani.kuma |
378 |
sheet.write(i, 0, order.id)
|
| 5631 |
amar.kumar |
379 |
html +="<td>" + str(order.id) + "</td>"
|
| 4783 |
phani.kuma |
380 |
sheet.write(i, 1, mode[order.cod])
|
| 5631 |
amar.kumar |
381 |
html +="<td>" + str(mode[order.cod]) + "</td>"
|
| 8404 |
amar.kumar |
382 |
sheet.write(i, 2, source[order.source])
|
|
|
383 |
html +="<td>" + str(source[order.source]) + "</td>"
|
| 8403 |
amar.kumar |
384 |
sheet.write(i, 3, order.airwaybill_no)
|
| 5631 |
amar.kumar |
385 |
html +="<td>" + str(order.airwaybill_no) + "</td>"
|
| 8403 |
amar.kumar |
386 |
sheet.write(i, 4, order.statusDescription)
|
| 5631 |
amar.kumar |
387 |
html +="<td>" + order.statusDescription + "</td>"
|
| 8403 |
amar.kumar |
388 |
sheet.write(i, 5, to_py_date(order.shipping_timestamp), date_style)
|
| 5631 |
amar.kumar |
389 |
html +="<td>" + str(to_py_date(order.shipping_timestamp)) + "</td>"
|
| 8403 |
amar.kumar |
390 |
sheet.write(i, 6, to_py_date(order.pickup_timestamp), date_style)
|
| 5631 |
amar.kumar |
391 |
html +="<td>" + str(to_py_date(order.pickup_timestamp)) + "</td>"
|
| 8403 |
amar.kumar |
392 |
sheet.write(i, 7, to_py_date(order.expected_delivery_time), date_style)
|
| 5631 |
amar.kumar |
393 |
html +="<td>" + str(to_py_date(order.expected_delivery_time)) + "</td>"
|
| 8403 |
amar.kumar |
394 |
sheet.write(i, 8, warehouses_map.get(order.warehouse_id))
|
| 5631 |
amar.kumar |
395 |
html +="<td>" + str(warehouses_map.get(order.warehouse_id)) + "</td>"
|
| 8403 |
amar.kumar |
396 |
sheet.write(i, 9, order.warehouse_id)
|
| 5631 |
amar.kumar |
397 |
html +="<td>" + str(order.warehouse_id) + "</td>"
|
| 8403 |
amar.kumar |
398 |
sheet.write(i, 10, providers_map.get(order.logistics_provider_id))
|
| 5631 |
amar.kumar |
399 |
html +="<td>" + str(providers_map.get(order.logistics_provider_id)) + "</td>"
|
| 8403 |
amar.kumar |
400 |
sheet.write(i, 11, order.logistics_provider_id)
|
| 5631 |
amar.kumar |
401 |
html +="<td>" + str(order.logistics_provider_id) + "</td>"
|
| 8403 |
amar.kumar |
402 |
sheet.write(i, 12, order.customer_city)
|
| 5631 |
amar.kumar |
403 |
html +="<td>" + str(order.customer_city) + "</td>"
|
| 8403 |
amar.kumar |
404 |
sheet.write(i, 13, order.customer_state)
|
| 5631 |
amar.kumar |
405 |
html +="<td>" + str(order.customer_state) + "</td>"
|
| 8403 |
amar.kumar |
406 |
sheet.write(i, 14, order.customer_pincode)
|
| 5631 |
amar.kumar |
407 |
html +="<td>" + str(order.customer_pincode) + "</td>"
|
| 4709 |
rajveer |
408 |
|
| 5631 |
amar.kumar |
409 |
html +="</tr>"
|
| 4783 |
phani.kuma |
410 |
i= i+1
|
|
|
411 |
|
|
|
412 |
today = datetime.date.today()
|
|
|
413 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
|
|
414 |
filename = "/tmp/UndeliveredOrders-" + datestr + ".xls"
|
|
|
415 |
wbk.save(filename)
|
| 5631 |
amar.kumar |
416 |
html +="</table></body></html>"
|
| 4783 |
phani.kuma |
417 |
|
|
|
418 |
try:
|
|
|
419 |
part = get_attachment_part(filename)
|
| 5631 |
amar.kumar |
420 |
mail_html("cnc.center@shop2020.in", "5h0p2o2o", to, "Orders which missed Expected Delivery Date as on: " + datestr, html, [part])
|
| 4783 |
phani.kuma |
421 |
finally:
|
|
|
422 |
os.remove(filename)
|
|
|
423 |
|
| 4709 |
rajveer |
424 |
def main():
|
|
|
425 |
parser = OptionParser()
|
|
|
426 |
parser.add_option("-d", "--delayed", dest="delayed",
|
|
|
427 |
action="store_true",
|
|
|
428 |
help="")
|
|
|
429 |
parser.add_option("-c", "--cancelled", dest="cancelled",
|
|
|
430 |
action="store_true",
|
|
|
431 |
help="")
|
| 4783 |
phani.kuma |
432 |
parser.add_option("-u", "--undelivered", dest="undelivered",
|
|
|
433 |
action="store_true",
|
|
|
434 |
help="")
|
| 4709 |
rajveer |
435 |
|
|
|
436 |
(options, args) = parser.parse_args()
|
|
|
437 |
if options.delayed:
|
|
|
438 |
generate_delayed_orders_file()
|
|
|
439 |
if options.cancelled:
|
|
|
440 |
generate_cancelled_orders_file()
|
| 4783 |
phani.kuma |
441 |
if options.undelivered:
|
|
|
442 |
generate_expected_delivery_missed_orders_file()
|
|
|
443 |
|
| 4607 |
rajveer |
444 |
if __name__ == '__main__':
|
| 10687 |
rajveer |
445 |
main()
|