| Line 96... |
Line 96... |
| 96 |
|
96 |
|
| 97 |
def process_delivery_report(provider):
|
97 |
def process_delivery_report(provider):
|
| 98 |
try:
|
98 |
try:
|
| 99 |
orders_tobe_delivered = fetch_data(provider.id, OrderStatus.SHIPPED_TO_LOGST)
|
99 |
orders_tobe_delivered = fetch_data(provider.id, OrderStatus.SHIPPED_TO_LOGST)
|
| 100 |
delivered_orders, delivered_orders_but_wrong_code_mentioned, returned_orders, undelivered_orders = read_delivery_orders(orders_tobe_delivered)
|
100 |
delivered_orders, delivered_orders_but_wrong_code_mentioned, returned_orders, undelivered_orders = read_delivery_orders(orders_tobe_delivered)
|
| 101 |
if undelivered_orders:
|
- |
|
| 102 |
update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
- |
|
| 103 |
if delivered_orders:
|
101 |
if delivered_orders:
|
| 104 |
update_delivered_orders(provider.id, delivered_orders)
|
102 |
update_delivered_orders(provider.id, delivered_orders)
|
| 105 |
if returned_orders:
|
103 |
if returned_orders:
|
| 106 |
update_returned_orders(provider.id, returned_orders)
|
104 |
update_returned_orders(provider.id, returned_orders)
|
| 107 |
try:
|
105 |
try:
|
| Line 124... |
Line 122... |
| 124 |
"Delivered Orders but Wrong Code Mentioned Report for " + provider.name,\
|
122 |
"Delivered Orders but Wrong Code Mentioned Report for " + provider.name,\
|
| 125 |
"This is a system generated email.Please don't reply to it.",\
|
123 |
"This is a system generated email.Please don't reply to it.",\
|
| 126 |
delivered_orders_but_wrong_code_mentioned_report)
|
124 |
delivered_orders_but_wrong_code_mentioned_report)
|
| 127 |
except:
|
125 |
except:
|
| 128 |
print "Some issue sending the delivered orders but wrong code mentioned report"
|
126 |
print "Some issue sending the delivered orders but wrong code mentioned report"
|
| 129 |
traceback.print_exc()
|
127 |
traceback.print_exc()
|
| - |
|
128 |
try:
|
| - |
|
129 |
orders_not_delivered = update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
| - |
|
130 |
if orders_not_delivered:
|
| - |
|
131 |
print "Undelivered Orders:"
|
| - |
|
132 |
print orders_not_delivered
|
| - |
|
133 |
mismatch_file = "/tmp/UndeliveredOrders.csv"
|
| - |
|
134 |
print "Some of our Orders were not delivered. Printing report to:" + mismatch_file
|
| - |
|
135 |
print_undelivered_orders_report(mismatch_file, orders_not_delivered)
|
| - |
|
136 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
137 |
mail(from_user, from_pwd, to,\
|
| - |
|
138 |
"Orders that are undelivered but picked up or shipped four days ago for " + provider.name,\
|
| - |
|
139 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
140 |
pickup_mismatch_part)
|
| - |
|
141 |
except Exception:
|
| - |
|
142 |
print "Some issue updating and sending the undelivered orders report"
|
| - |
|
143 |
traceback.print_exc()
|
| 130 |
except:
|
144 |
except:
|
| 131 |
print "Some issue while processing the orders in SHIPPED_TO_LOGST status"
|
145 |
print "Some issue while processing the orders in SHIPPED_TO_LOGST status"
|
| 132 |
traceback.print_exc()
|
146 |
traceback.print_exc()
|
| 133 |
|
147 |
|
| 134 |
def get_provider_by_name(provider_name):
|
148 |
def get_provider_by_name(provider_name):
|
| Line 286... |
Line 300... |
| 286 |
print tex.message
|
300 |
print tex.message
|
| 287 |
|
301 |
|
| 288 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
302 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
| 289 |
txnClient = TransactionClient().get_client()
|
303 |
txnClient = TransactionClient().get_client()
|
| 290 |
try:
|
304 |
try:
|
| 291 |
txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
305 |
orders_not_delivered = txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
| - |
|
306 |
return orders_not_delivered
|
| 292 |
except TransactionServiceException as tex:
|
307 |
except TransactionServiceException as tex:
|
| 293 |
print tex.message
|
308 |
print tex.message
|
| 294 |
|
309 |
|
| 295 |
def print_pickup_mismatch_report(filename, orders):
|
310 |
def print_pickup_mismatch_report(filename, orders):
|
| 296 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
311 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| Line 309... |
Line 324... |
| 309 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
324 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 310 |
writer.writerow(['AWB No', 'Code Used'])
|
325 |
writer.writerow(['AWB No', 'Code Used'])
|
| 311 |
for awb, code_used in delivered_orders_but_wrong_code_mentioned.iteritems():
|
326 |
for awb, code_used in delivered_orders_but_wrong_code_mentioned.iteritems():
|
| 312 |
writer.writerow([awb, code_used])
|
327 |
writer.writerow([awb, code_used])
|
| 313 |
|
328 |
|
| - |
|
329 |
def print_undelivered_orders_report(filename, orders):
|
| - |
|
330 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| - |
|
331 |
writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp'])
|
| - |
|
332 |
for order in orders:
|
| - |
|
333 |
writer.writerow([order.id, order.airwaybill_no, order.status, order.statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp)])
|
| - |
|
334 |
|
| 314 |
def get_py_datetime(time_string):
|
335 |
def get_py_datetime(time_string):
|
| 315 |
# This should be a command line argument.
|
336 |
# This should be a command line argument.
|
| 316 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
337 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
| 317 |
# get a complete list of format specifiers available for date time.
|
338 |
# get a complete list of format specifiers available for date time.
|
| 318 |
time_format = "%m/%d/%Y %I:%M:%S %p"
|
339 |
time_format = "%m/%d/%Y %I:%M:%S %p"
|