| Line 1... |
Line 1... |
| 1 |
#!/usr/bin/python
|
1 |
#!/usr/bin/python
|
| 2 |
'''
|
2 |
'''
|
| 3 |
It processes the following reports received from Couriers
|
3 |
It processes the following reports received from Couriers
|
| 4 |
through email:
|
4 |
through email:
|
| 5 |
1. Pickup Report : contains details of orders that were
|
5 |
1. Pickup Report : contains details of orders that were
|
| 6 |
picked up from our warehouse and DOA orders that were
|
6 |
picked up from our warehouse, Return orders and DOA orders that were
|
| 7 |
picked up from our customers.
|
7 |
picked up from our customers.
|
| 8 |
2. Delivery & RTO Report: contains details of orders that
|
8 |
2. Delivery & RTO Report: contains details of orders that
|
| 9 |
were either successfully delivered to our customers or
|
9 |
were either successfully delivered to our customers or
|
| 10 |
which are being returned to us.
|
10 |
which are being returned to us.
|
| 11 |
3. Non-delivery Report: contains details of orders whose
|
11 |
3. Non-delivery Report: contains details of orders whose
|
| 12 |
delivery date has passed but which have not been
|
12 |
delivery date has passed but which have not been
|
| 13 |
delivered yet.
|
13 |
delivered yet.
|
| 14 |
|
14 |
|
| 15 |
It sends out a Pickup mismatch report and a Doa Pickup mismatch
|
15 |
It sends out a Pickup mismatch report, Return orders Pickup Mismatch report, Doa Pickup mismatch report,
|
| 16 |
report to cnc.center@shop2020.in
|
16 |
Undelivered orders report and Returned Orders report to cnc.center@shop2020.in
|
| 17 |
|
17 |
|
| 18 |
@author: Chandranshu
|
18 |
@author: Chandranshu
|
| 19 |
'''
|
19 |
'''
|
| 20 |
import time
|
20 |
import time
|
| 21 |
import datetime
|
21 |
import datetime
|
| Line 41... |
Line 41... |
| 41 |
to = ['cnc.center@shop2020.in', "suraj.sharma@shop2020.in", "sandeep.sachdeva@shop2020.in", "parmod.kumar@shop2020.in"]
|
41 |
to = ['cnc.center@shop2020.in', "suraj.sharma@shop2020.in", "sandeep.sachdeva@shop2020.in", "parmod.kumar@shop2020.in"]
|
| 42 |
|
42 |
|
| 43 |
def process_pickup_records(provider):
|
43 |
def process_pickup_records(provider):
|
| 44 |
try:
|
44 |
try:
|
| 45 |
filename = fetch_report(provider.name.upper() + ' PICKUP REPORT')
|
45 |
filename = fetch_report(provider.name.upper() + ' PICKUP REPORT')
|
| 46 |
pickup_details, doa_pickup_details = read_pickup_report(filename)
|
46 |
pickup_details, doa_pickup_details, returns_pickup_details = read_pickup_report(filename)
|
| 47 |
orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
|
47 |
orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
|
| 48 |
try:
|
48 |
try:
|
| 49 |
if orders_not_picked_up:
|
49 |
if orders_not_picked_up:
|
| 50 |
mismatch_file = "/tmp/PickupMismatch.csv"
|
50 |
mismatch_file = "/tmp/PickupMismatch.csv"
|
| 51 |
print "Some of our orders were not picked up. Printing report to:" + mismatch_file
|
51 |
print "Some of our orders were not picked up. Printing report to:" + mismatch_file
|
| Line 71... |
Line 71... |
| 71 |
"This is a system generated email.Please don't reply to it.",\
|
71 |
"This is a system generated email.Please don't reply to it.",\
|
| 72 |
pickup_mismatch_part)
|
72 |
pickup_mismatch_part)
|
| 73 |
except Exception:
|
73 |
except Exception:
|
| 74 |
print "Some issue sending the DOA mismatch report"
|
74 |
print "Some issue sending the DOA mismatch report"
|
| 75 |
traceback.print_exc()
|
75 |
traceback.print_exc()
|
| - |
|
76 |
|
| - |
|
77 |
returns_not_picked_up = update_picked_returns(provider.id, returns_pickup_details)
|
| - |
|
78 |
try:
|
| - |
|
79 |
if returns_not_picked_up:
|
| - |
|
80 |
mismatch_file = "/tmp/ReturnsPickupMismatch.csv"
|
| - |
|
81 |
print "Some of our Return orders were not picked up. Printing report to:" + mismatch_file
|
| - |
|
82 |
print_pickup_mismatch_report(mismatch_file, returns_not_picked_up)
|
| - |
|
83 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
84 |
mail(from_user, from_pwd, to,\
|
| - |
|
85 |
"Return orders Pickup Mismatch for " + provider.name,\
|
| - |
|
86 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
87 |
pickup_mismatch_part)
|
| - |
|
88 |
except Exception:
|
| - |
|
89 |
print "Some issue sending the Return orders mismatch report"
|
| - |
|
90 |
traceback.print_exc()
|
| 76 |
except:
|
91 |
except:
|
| 77 |
print "Some issue while processing the Pickup Report"
|
92 |
print "Some issue while processing the Pickup Report"
|
| 78 |
traceback.print_exc()
|
93 |
traceback.print_exc()
|
| 79 |
finally:
|
94 |
finally:
|
| 80 |
os.remove(filename)
|
95 |
os.remove(filename)
|
| Line 163... |
Line 178... |
| 163 |
workbook = xlrd.open_workbook(filename)
|
178 |
workbook = xlrd.open_workbook(filename)
|
| 164 |
sheet = workbook.sheet_by_index(0)
|
179 |
sheet = workbook.sheet_by_index(0)
|
| 165 |
num_rows = sheet.nrows
|
180 |
num_rows = sheet.nrows
|
| 166 |
picked_up_orders = {}
|
181 |
picked_up_orders = {}
|
| 167 |
picked_up_doas = {}
|
182 |
picked_up_doas = {}
|
| - |
|
183 |
picked_up_returns = {}
|
| 168 |
for rownum in range(1, num_rows):
|
184 |
for rownum in range(1, num_rows):
|
| 169 |
unused_customer_code, awb, ref_no, timeval, date = sheet.row_values(rownum)[0:5]
|
185 |
unused_customer_code, awb, ref_no, timeval, date = sheet.row_values(rownum)[0:5]
|
| 170 |
picked_up_orders[awb] = str(get_py_datetime(date, timeval))
|
186 |
picked_up_orders[awb] = str(get_py_datetime(date, timeval))
|
| 171 |
picked_up_doas[ref_no] = str(get_py_datetime(date, timeval))
|
187 |
picked_up_doas[ref_no] = str(get_py_datetime(date, timeval))
|
| - |
|
188 |
picked_up_returns[ref_no] = str(get_py_datetime(date, timeval))
|
| 172 |
|
189 |
|
| 173 |
print "Picked up Orders:"
|
190 |
print "Picked up Orders:"
|
| 174 |
print picked_up_orders
|
191 |
print picked_up_orders
|
| - |
|
192 |
print "Picked up DOAs:"
|
| 175 |
print picked_up_doas
|
193 |
print picked_up_doas
|
| - |
|
194 |
print "Picked up RETURNS:"
|
| - |
|
195 |
print picked_up_returns
|
| 176 |
return picked_up_orders, picked_up_doas
|
196 |
return picked_up_orders, picked_up_doas, picked_up_returns
|
| 177 |
|
197 |
|
| 178 |
def read_delivery_report(filename):
|
198 |
def read_delivery_report(filename):
|
| 179 |
print "Reading delivery details from:" + filename
|
199 |
print "Reading delivery details from:" + filename
|
| 180 |
workbook = xlrd.open_workbook(filename)
|
200 |
workbook = xlrd.open_workbook(filename)
|
| 181 |
sheet = workbook.sheet_by_index(0)
|
201 |
sheet = workbook.sheet_by_index(0)
|
| Line 232... |
Line 252... |
| 232 |
doas_not_picked_up = txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
252 |
doas_not_picked_up = txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
| 233 |
return doas_not_picked_up
|
253 |
return doas_not_picked_up
|
| 234 |
except TransactionServiceException as tex:
|
254 |
except TransactionServiceException as tex:
|
| 235 |
print tex.message
|
255 |
print tex.message
|
| 236 |
|
256 |
|
| - |
|
257 |
def update_picked_returns(provider_id, returns_pickup_details):
|
| - |
|
258 |
txnClient = TransactionClient().get_client()
|
| - |
|
259 |
try:
|
| - |
|
260 |
returns_not_picked_up = txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
| - |
|
261 |
return returns_not_picked_up
|
| - |
|
262 |
except TransactionServiceException as tex:
|
| - |
|
263 |
print tex.message
|
| - |
|
264 |
|
| 237 |
def update_delivered_orders(provider_id, delivered_orders):
|
265 |
def update_delivered_orders(provider_id, delivered_orders):
|
| 238 |
txnClient = TransactionClient().get_client()
|
266 |
txnClient = TransactionClient().get_client()
|
| 239 |
try:
|
267 |
try:
|
| 240 |
txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
|
268 |
txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
|
| 241 |
except TransactionServiceException as tex:
|
269 |
except TransactionServiceException as tex:
|