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