| Line 3... |
Line 3... |
| 3 |
It processes the following orders:
|
3 |
It processes the following orders:
|
| 4 |
1. Orders in DOA_PICKUP_CONFIRMED status : get details of orders that
|
4 |
1. Orders in DOA_PICKUP_CONFIRMED status : get details of orders that
|
| 5 |
were in DOA_PICKUP_CONFIRMED status from database and
|
5 |
were in DOA_PICKUP_CONFIRMED status from database and
|
| 6 |
calls aramex api to know whether they are picked up by armaex
|
6 |
calls aramex api to know whether they are picked up by armaex
|
| 7 |
and changes the status to DOA_RETURN_IN_TRANSIT if it is done.
|
7 |
and changes the status to DOA_RETURN_IN_TRANSIT if it is done.
|
| - |
|
8 |
2. Orders in RET_PICKUP_CONFIRMED status : get details of orders that
|
| - |
|
9 |
were in RET_PICKUP_CONFIRMED status from database and
|
| - |
|
10 |
calls aramex api to know whether they are picked up by armaex
|
| - |
|
11 |
and changes the status to RET_RETURN_IN_TRANSIT if it is done.
|
| 8 |
2. Orders in SHIPPED_FROM_WH status: get details of orders that
|
12 |
3. Orders in SHIPPED_FROM_WH status: get details of orders that
|
| 9 |
were in SHIPPED_FROM_WH status from database and
|
13 |
were in SHIPPED_FROM_WH status from database and
|
| 10 |
calls aramex api to know whether they are picked up by armaex
|
14 |
calls aramex api to know whether they are picked up by armaex
|
| 11 |
and changes the status to SHIPPED_TO_LOGST if it is done.
|
15 |
and changes the status to SHIPPED_TO_LOGST if it is done.
|
| 12 |
3. Orders in SHIPPED_TO_LOGST status: get details of orders that
|
16 |
4. Orders in SHIPPED_TO_LOGST status: get details of orders that
|
| 13 |
were in SHIPPED_TO_LOGST status from database and
|
17 |
were in SHIPPED_TO_LOGST status from database and
|
| 14 |
calls aramex api to know their status and changes the status accordingly.
|
18 |
calls aramex api to know their status and changes the status accordingly.
|
| 15 |
|
19 |
|
| 16 |
It sends out a Pickup mismatch report, a Doa Pickup mismatch and Returned Orders Report
|
20 |
It sends out a Pickup mismatch report, Return orders Pickup Mismatch report, Doa Pickup mismatch report,
|
| 17 |
report to cnc.center@shop2020.in
|
21 |
Undelivered orders report and Returned Orders report to cnc.center@shop2020.in
|
| 18 |
|
22 |
|
| 19 |
http://www.aramex.com/track_xml.asp?ShipperRef={variable1}&OrgCntry=In&FromDate={variable2}&ToDate={variable3} is hard coded
|
23 |
http://www.aramex.com/track_xml.asp?ShipperRef={variable1}&OrgCntry=In&FromDate={variable2}&ToDate={variable3} is hard coded
|
| 20 |
to track DOA orders and for other orders ConfigClient is called to get aramex_update_url
|
24 |
to track DOA orders and for other orders ConfigClient is called to get aramex_update_url
|
| 21 |
|
25 |
|
| 22 |
@author: Phani Kumar
|
26 |
@author: Phani Kumar
|
| Line 47... |
Line 51... |
| 47 |
to = ['cnc.center@shop2020.in', "suraj.sharma@shop2020.in", "sandeep.sachdeva@shop2020.in", "parmod.kumar@shop2020.in"]
|
51 |
to = ['cnc.center@shop2020.in', "suraj.sharma@shop2020.in", "sandeep.sachdeva@shop2020.in", "parmod.kumar@shop2020.in"]
|
| 48 |
|
52 |
|
| 49 |
def process_dao_pickup_orders(provider):
|
53 |
def process_dao_pickup_orders(provider):
|
| 50 |
try:
|
54 |
try:
|
| 51 |
doas_tobe_picked_up = fetch_data(provider.id, OrderStatus.DOA_PICKUP_CONFIRMED)
|
55 |
doas_tobe_picked_up = fetch_data(provider.id, OrderStatus.DOA_PICKUP_CONFIRMED)
|
| 52 |
doa_pickup_details = read_dao_pickup_orders(doas_tobe_picked_up)
|
56 |
doa_pickup_details = read_dao_return_pickup_orders(doas_tobe_picked_up)
|
| 53 |
doas_not_picked_up = update_picked_doas(provider.id, doa_pickup_details)
|
57 |
doas_not_picked_up = update_picked_doas(provider.id, doa_pickup_details)
|
| 54 |
try:
|
58 |
try:
|
| 55 |
if doas_not_picked_up:
|
59 |
if doas_not_picked_up:
|
| 56 |
print "DOAs not Picked up:"
|
60 |
print "DOAs not Picked up:"
|
| 57 |
print doas_not_picked_up
|
61 |
print doas_not_picked_up
|
| Line 68... |
Line 72... |
| 68 |
traceback.print_exc()
|
72 |
traceback.print_exc()
|
| 69 |
except:
|
73 |
except:
|
| 70 |
print "Some issue while processing the orders in DOA_PICKUP_CONFIRMED status"
|
74 |
print "Some issue while processing the orders in DOA_PICKUP_CONFIRMED status"
|
| 71 |
traceback.print_exc()
|
75 |
traceback.print_exc()
|
| 72 |
|
76 |
|
| - |
|
77 |
def process_return_pickup_orders(provider):
|
| - |
|
78 |
try:
|
| - |
|
79 |
returns_tobe_picked_up = fetch_data(provider.id, OrderStatus.RET_PICKUP_CONFIRMED)
|
| - |
|
80 |
returns_pickup_details = read_dao_return_pickup_orders(returns_tobe_picked_up)
|
| - |
|
81 |
returns_not_picked_up = update_picked_returns(provider.id, returns_pickup_details)
|
| - |
|
82 |
try:
|
| - |
|
83 |
if returns_not_picked_up:
|
| - |
|
84 |
print "Return Orders not Picked up:"
|
| - |
|
85 |
print returns_not_picked_up
|
| - |
|
86 |
mismatch_file = "/tmp/ReturnsPickupMismatch.csv"
|
| - |
|
87 |
print "Some of our Return orders were not picked up. Printing report to:" + mismatch_file
|
| - |
|
88 |
print_pickup_mismatch_report(mismatch_file, returns_not_picked_up)
|
| - |
|
89 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
90 |
mail(from_user, from_pwd, to,\
|
| - |
|
91 |
"Return orders Pickup Mismatch for " + provider.name,\
|
| - |
|
92 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
93 |
pickup_mismatch_part)
|
| - |
|
94 |
except Exception:
|
| - |
|
95 |
print "Some issue sending the Return orders mismatch report"
|
| - |
|
96 |
traceback.print_exc()
|
| - |
|
97 |
except:
|
| - |
|
98 |
print "Some issue while processing the orders in RET_PICKUP_CONFIRMED status"
|
| - |
|
99 |
traceback.print_exc()
|
| - |
|
100 |
|
| 73 |
def process_pickup_records(provider):
|
101 |
def process_pickup_records(provider):
|
| 74 |
try:
|
102 |
try:
|
| 75 |
orders_tobe_picked_up = fetch_data(provider.id, OrderStatus.SHIPPED_FROM_WH)
|
103 |
orders_tobe_picked_up = fetch_data(provider.id, OrderStatus.SHIPPED_FROM_WH)
|
| 76 |
pickup_details = read_pickup_orders(orders_tobe_picked_up)
|
104 |
pickup_details = read_pickup_orders(orders_tobe_picked_up)
|
| 77 |
orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
|
105 |
orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
|
| Line 163... |
Line 191... |
| 163 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status)
|
191 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status)
|
| 164 |
return doas_tobe_picked_up
|
192 |
return doas_tobe_picked_up
|
| 165 |
except TransactionServiceException as tex:
|
193 |
except TransactionServiceException as tex:
|
| 166 |
print tex.message
|
194 |
print tex.message
|
| 167 |
|
195 |
|
| 168 |
def read_dao_pickup_orders(doas_tobe_picked_up):
|
196 |
def read_dao_return_pickup_orders(orders_tobe_picked_up):
|
| 169 |
#uri=http://www.aramex.com/track_xml.asp?ShipperRef=61582&OrgCntry=In&FromDate=2-6-2012&ToDate=2-6-2012
|
197 |
#uri=http://www.aramex.com/track_xml.asp?ShipperRef=61582&OrgCntry=In&FromDate=2-6-2012&ToDate=2-6-2012
|
| 170 |
picked_up_doas = {}
|
198 |
picked_up_orders = {}
|
| 171 |
for order in doas_tobe_picked_up:
|
199 |
for order in orders_tobe_picked_up:
|
| 172 |
uri = 'http://www.aramex.com/track_xml.asp?ShipperRef=' + str(order.pickupRequestNo) + '&OrgCntry=In&FromDate=' + to_py_date(order.doa_auth_timestamp).strftime("%m-%d-%Y") +'&ToDate=' + datetime.date.today().strftime("%m-%d-%Y")
|
- |
|
| 173 |
root = parse(urllib2.urlopen(uri)).getroot()
|
- |
|
| 174 |
try:
|
200 |
try:
|
| - |
|
201 |
uri = 'http://www.aramex.com/track_xml.asp?ShipperRef=' + str(order.pickupRequestNo) + '&OrgCntry=In&FromDate=' + to_py_date(order.doa_auth_timestamp).strftime("%m-%d-%Y") +'&ToDate=' + datetime.date.today().strftime("%m-%d-%Y")
|
| - |
|
202 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 175 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
203 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| 176 |
if len(nodes):
|
204 |
if len(nodes):
|
| 177 |
element = nodes[len(nodes)-1]
|
205 |
element = nodes[len(nodes)-1]
|
| 178 |
if element.findtext('Status', '') == 'SHOR' and element.findtext('Condition', '') == 'PKUP':
|
206 |
if element.findtext('Status', '') == 'SHOR' and element.findtext('Condition', '') == 'PKUP':
|
| 179 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
207 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| 180 |
picked_up_doas[order.pickupRequestNo] = str(delivery_date)
|
208 |
picked_up_orders[order.pickupRequestNo] = str(delivery_date)
|
| 181 |
except:
|
209 |
except:
|
| 182 |
pass
|
210 |
pass
|
| 183 |
|
211 |
|
| 184 |
print "Picked up DOAs:"
|
212 |
print "Picked up Orders:"
|
| 185 |
print picked_up_doas
|
213 |
print picked_up_orders
|
| 186 |
return picked_up_doas
|
214 |
return picked_up_orders
|
| 187 |
|
215 |
|
| 188 |
def read_pickup_orders(orders_tobe_picked_up):
|
216 |
def read_pickup_orders(orders_tobe_picked_up):
|
| 189 |
try:
|
217 |
try:
|
| 190 |
config_client = ConfigClient()
|
218 |
config_client = ConfigClient()
|
| 191 |
ARAMEX_URL = config_client.get_property("aramex_update_url")
|
219 |
ARAMEX_URL = config_client.get_property("aramex_update_url")
|
| Line 193... |
Line 221... |
| 193 |
print cex.message
|
221 |
print cex.message
|
| 194 |
traceback.print_exc()
|
222 |
traceback.print_exc()
|
| 195 |
|
223 |
|
| 196 |
picked_up_orders = {}
|
224 |
picked_up_orders = {}
|
| 197 |
for order in orders_tobe_picked_up:
|
225 |
for order in orders_tobe_picked_up:
|
| 198 |
uri = ARAMEX_URL + order.airwaybill_no
|
- |
|
| 199 |
root = parse(urllib2.urlopen(uri)).getroot()
|
- |
|
| 200 |
try:
|
226 |
try:
|
| - |
|
227 |
uri = ARAMEX_URL + order.airwaybill_no
|
| - |
|
228 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 201 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
229 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| 202 |
if len(nodes):
|
230 |
if len(nodes):
|
| 203 |
element = nodes[len(nodes)-1]
|
231 |
element = nodes[len(nodes)-1]
|
| 204 |
if element.findtext('Status', '') == 'SHOR' and element.findtext('Condition', '') == 'PKUP':
|
232 |
if element.findtext('Status', '') == 'SHOR' and element.findtext('Condition', '') == 'PKUP':
|
| 205 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
233 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| Line 222... |
Line 250... |
| 222 |
delivered_orders = {}
|
250 |
delivered_orders = {}
|
| 223 |
delivered_orders_but_wrong_code_mentioned = {}
|
251 |
delivered_orders_but_wrong_code_mentioned = {}
|
| 224 |
returned_orders = {}
|
252 |
returned_orders = {}
|
| 225 |
undelivered_orders = {}
|
253 |
undelivered_orders = {}
|
| 226 |
for order in orders_tobe_delivered:
|
254 |
for order in orders_tobe_delivered:
|
| 227 |
uri = ARAMEX_URL + order.airwaybill_no
|
- |
|
| 228 |
root = parse(urllib2.urlopen(uri)).getroot()
|
- |
|
| 229 |
try:
|
255 |
try:
|
| - |
|
256 |
uri = ARAMEX_URL + order.airwaybill_no
|
| - |
|
257 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 230 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
258 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| 231 |
if len(nodes):
|
259 |
if len(nodes):
|
| 232 |
i = len(nodes)-1
|
260 |
i = len(nodes)-1
|
| 233 |
while i>=0:
|
261 |
while i>=0:
|
| 234 |
element = nodes[i]
|
262 |
element = nodes[i]
|
| Line 283... |
Line 311... |
| 283 |
doas_not_picked_up = txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
311 |
doas_not_picked_up = txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
| 284 |
return doas_not_picked_up
|
312 |
return doas_not_picked_up
|
| 285 |
except TransactionServiceException as tex:
|
313 |
except TransactionServiceException as tex:
|
| 286 |
print tex.message
|
314 |
print tex.message
|
| 287 |
|
315 |
|
| - |
|
316 |
def update_picked_returns(provider_id, returns_pickup_details):
|
| - |
|
317 |
txnClient = TransactionClient().get_client()
|
| - |
|
318 |
try:
|
| - |
|
319 |
returns_not_picked_up = txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
| - |
|
320 |
return returns_not_picked_up
|
| - |
|
321 |
except TransactionServiceException as tex:
|
| - |
|
322 |
print tex.message
|
| - |
|
323 |
|
| 288 |
def update_delivered_orders(provider_id, delivered_orders):
|
324 |
def update_delivered_orders(provider_id, delivered_orders):
|
| 289 |
txnClient = TransactionClient().get_client()
|
325 |
txnClient = TransactionClient().get_client()
|
| 290 |
try:
|
326 |
try:
|
| 291 |
txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
|
327 |
txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
|
| 292 |
except TransactionServiceException as tex:
|
328 |
except TransactionServiceException as tex:
|
| Line 342... |
Line 378... |
| 342 |
mytime = time.strptime(time_string, time_format)
|
378 |
mytime = time.strptime(time_string, time_format)
|
| 343 |
return datetime.datetime(*mytime[:6])
|
379 |
return datetime.datetime(*mytime[:6])
|
| 344 |
|
380 |
|
| 345 |
def main():
|
381 |
def main():
|
| 346 |
parser = optparse.OptionParser()
|
382 |
parser = optparse.OptionParser()
|
| 347 |
parser.add_option("-e", "--doa", dest="doa_report",
|
- |
|
| 348 |
action="store_true",
|
- |
|
| 349 |
help="Run the DOA pickup reconciliation")
|
- |
|
| 350 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
383 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
| 351 |
action="store_true",
|
384 |
action="store_true",
|
| 352 |
help="Run the pickup reconciliation")
|
385 |
help="Run the pickup reconciliation")
|
| 353 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
386 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
| 354 |
action="store_true",
|
387 |
action="store_true",
|
| Line 358... |
Line 391... |
| 358 |
help="Run all reconciliations")
|
391 |
help="Run all reconciliations")
|
| 359 |
parser.add_option("-P", "--provider", dest="provider",
|
392 |
parser.add_option("-P", "--provider", dest="provider",
|
| 360 |
default="Aramex", type="string",
|
393 |
default="Aramex", type="string",
|
| 361 |
help="The PROVIDER this report is for",
|
394 |
help="The PROVIDER this report is for",
|
| 362 |
metavar="PROVIDER")
|
395 |
metavar="PROVIDER")
|
| 363 |
parser.set_defaults(doa_report=False, pickup_report=False, delivery_report=False, all_reports=False)
|
396 |
parser.set_defaults(pickup_report=False, delivery_report=False, all_reports=False)
|
| 364 |
(options, args) = parser.parse_args()
|
397 |
(options, args) = parser.parse_args()
|
| 365 |
if len(args) != 0:
|
398 |
if len(args) != 0:
|
| 366 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
399 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 367 |
|
400 |
|
| 368 |
if options.all_reports:
|
401 |
if options.all_reports:
|
| 369 |
options.doa_report = True
|
- |
|
| 370 |
options.pickup_report = True
|
402 |
options.pickup_report = True
|
| 371 |
options.delivery_report = True
|
403 |
options.delivery_report = True
|
| 372 |
|
404 |
|
| 373 |
provider = get_provider_by_name(options.provider)
|
405 |
provider = get_provider_by_name(options.provider)
|
| 374 |
|
406 |
|
| 375 |
if options.doa_report:
|
- |
|
| 376 |
process_dao_pickup_orders(provider)
|
- |
|
| 377 |
if options.pickup_report:
|
407 |
if options.pickup_report:
|
| 378 |
process_pickup_records(provider)
|
408 |
process_pickup_records(provider)
|
| - |
|
409 |
process_dao_pickup_orders(provider)
|
| - |
|
410 |
process_return_pickup_orders(provider)
|
| 379 |
if options.delivery_report:
|
411 |
if options.delivery_report:
|
| 380 |
process_delivery_report(provider)
|
412 |
process_delivery_report(provider)
|
| 381 |
|
413 |
|
| 382 |
if __name__ == '__main__':
|
414 |
if __name__ == '__main__':
|
| 383 |
main()
|
415 |
main()
|