| 4741 |
phani.kuma |
1 |
#!/usr/bin/python
|
|
|
2 |
'''
|
|
|
3 |
It processes the following orders:
|
|
|
4 |
1. Orders in DOA_PICKUP_CONFIRMED status : get details of orders that
|
|
|
5 |
were in DOA_PICKUP_CONFIRMED status from database and
|
|
|
6 |
calls BlueDart api to know whether they are picked up by BlueDart
|
|
|
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 BlueDart api to know whether they are picked up by BlueDart
|
|
|
11 |
and changes the status to RET_RETURN_IN_TRANSIT if it is done.
|
|
|
12 |
3. Orders in SHIPPED_FROM_WH status: get details of orders that
|
|
|
13 |
were in SHIPPED_FROM_WH status from database and
|
|
|
14 |
calls BlueDart api to know whether they are picked up by BlueDart
|
|
|
15 |
and changes the status to SHIPPED_TO_LOGST if it is done.
|
|
|
16 |
4. Orders in SHIPPED_TO_LOGST status: get details of orders that
|
|
|
17 |
were in SHIPPED_TO_LOGST status from database and
|
|
|
18 |
calls BlueDart api to know their status and changes the status accordingly.
|
|
|
19 |
|
|
|
20 |
It sends out a Pickup mismatch report, Return orders Pickup Mismatch report, Doa Pickup mismatch report,
|
|
|
21 |
Undelivered orders report and Returned Orders report to cnc.center@shop2020.in
|
|
|
22 |
|
|
|
23 |
http://www.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery&loginid=DEL24119&awb=ref&format=XML&lickey=6265d61bafa6292c5ddfdb1ee335ca80&verno=1.3&scan=1&numbers={variable1} is hard coded
|
|
|
24 |
to track DOA orders and for other orders ConfigClient is called to get bluedart_update_url
|
|
|
25 |
|
|
|
26 |
@author: Phani Kumar
|
|
|
27 |
'''
|
| 6561 |
amit.gupta |
28 |
from shop2020.clients.CRMClient import CRMClient
|
|
|
29 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
30 |
from shop2020.clients.TransactionClient import TransactionClient
|
|
|
31 |
from shop2020.clients.UserClient import UserClient
|
|
|
32 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 6609 |
amit.gupta |
33 |
from LogisticUtils import enqueueMailForFDA
|
| 6561 |
amit.gupta |
34 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
|
|
35 |
from shop2020.thriftpy.crm.ttypes import *
|
|
|
36 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
|
|
37 |
OrderStatus
|
|
|
38 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
|
|
39 |
from shop2020.utils.Utils import to_py_date
|
|
|
40 |
from xml.etree.ElementTree import parse
|
|
|
41 |
import csv
|
| 4741 |
phani.kuma |
42 |
import datetime
|
|
|
43 |
import optparse
|
|
|
44 |
import sys
|
| 6561 |
amit.gupta |
45 |
import time
|
| 4741 |
phani.kuma |
46 |
import traceback
|
|
|
47 |
import urllib2
|
|
|
48 |
|
|
|
49 |
if __name__ == '__main__' and __package__ is None:
|
|
|
50 |
import os
|
|
|
51 |
sys.path.insert(0, os.getcwd())
|
|
|
52 |
|
|
|
53 |
|
| 4910 |
phani.kuma |
54 |
try:
|
|
|
55 |
config_client = ConfigClient()
|
|
|
56 |
BLUEDART_URL = config_client.get_property("bluedart_update_url")
|
|
|
57 |
except ConfigException as cex:
|
|
|
58 |
print cex.message
|
|
|
59 |
traceback.print_exc()
|
|
|
60 |
|
| 4948 |
phani.kuma |
61 |
defaultUndeliveredAsssigneeId = 19
|
| 4741 |
phani.kuma |
62 |
from_user = 'cnc.center@shop2020.in'
|
|
|
63 |
from_pwd = '5h0p2o2o'
|
| 6697 |
rajveer |
64 |
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "manoj.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
|
| 5163 |
phani.kuma |
65 |
|
| 4741 |
phani.kuma |
66 |
def process_dao_pickup_orders(provider):
|
|
|
67 |
try:
|
| 4910 |
phani.kuma |
68 |
doas_tobe_picked_up = fetch_data(provider.id, [OrderStatus.DOA_PICKUP_CONFIRMED])
|
| 4741 |
phani.kuma |
69 |
doa_pickup_details = read_dao_return_pickup_orders(doas_tobe_picked_up)
|
| 4910 |
phani.kuma |
70 |
if doa_pickup_details:
|
|
|
71 |
update_picked_doas(provider.id, doa_pickup_details)
|
| 4741 |
phani.kuma |
72 |
except:
|
|
|
73 |
print "Some issue while processing the orders in DOA_PICKUP_CONFIRMED status"
|
|
|
74 |
traceback.print_exc()
|
|
|
75 |
|
|
|
76 |
def process_return_pickup_orders(provider):
|
|
|
77 |
try:
|
| 4910 |
phani.kuma |
78 |
returns_tobe_picked_up = fetch_data(provider.id, [OrderStatus.RET_PICKUP_CONFIRMED])
|
| 4741 |
phani.kuma |
79 |
returns_pickup_details = read_dao_return_pickup_orders(returns_tobe_picked_up)
|
| 4910 |
phani.kuma |
80 |
if returns_pickup_details:
|
|
|
81 |
update_picked_returns(provider.id, returns_pickup_details)
|
| 4741 |
phani.kuma |
82 |
except:
|
|
|
83 |
print "Some issue while processing the orders in RET_PICKUP_CONFIRMED status"
|
|
|
84 |
traceback.print_exc()
|
|
|
85 |
|
|
|
86 |
def process_pickup_records(provider):
|
|
|
87 |
try:
|
| 4910 |
phani.kuma |
88 |
orders_tobe_picked_up = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH])
|
| 4741 |
phani.kuma |
89 |
pickup_details = read_pickup_orders(orders_tobe_picked_up)
|
| 4910 |
phani.kuma |
90 |
if pickup_details:
|
|
|
91 |
update_picked_orders(provider.id, pickup_details)
|
| 4741 |
phani.kuma |
92 |
except:
|
|
|
93 |
print "Some issue while processing the orders in SHIPPED_FROM_WH status"
|
|
|
94 |
traceback.print_exc()
|
|
|
95 |
|
| 4910 |
phani.kuma |
96 |
def process_local_connection_orders(provider):
|
|
|
97 |
try:
|
|
|
98 |
orders_tobe_local_connected = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST])
|
|
|
99 |
local_connected_orders = read_local_connection_orders(orders_tobe_local_connected)
|
|
|
100 |
if local_connected_orders:
|
|
|
101 |
update_local_connected_orders(provider.id, local_connected_orders)
|
|
|
102 |
except:
|
|
|
103 |
print "Some issue while processing the orders for local connection status"
|
|
|
104 |
traceback.print_exc()
|
|
|
105 |
|
|
|
106 |
def process_reached_destination_city_orders(provider):
|
|
|
107 |
try:
|
|
|
108 |
orders_tobe_reached_destination_city = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY])
|
|
|
109 |
destination_city_reached_orders = read_reached_destination_orders(orders_tobe_reached_destination_city)
|
|
|
110 |
if destination_city_reached_orders:
|
|
|
111 |
update_destination_city_reached_orders(provider.id, destination_city_reached_orders)
|
|
|
112 |
except:
|
|
|
113 |
print "Some issue while processing the orders for Reached Destination City status"
|
|
|
114 |
traceback.print_exc()
|
|
|
115 |
|
|
|
116 |
def process_first_delivery_attempt_orders(provider):
|
|
|
117 |
try:
|
|
|
118 |
orders_tobe_first_delivery_attempted = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY])
|
|
|
119 |
first_atdl_orders = read_first_delivery_attempt_orders(orders_tobe_first_delivery_attempted)
|
|
|
120 |
if first_atdl_orders:
|
|
|
121 |
update_first_atdl_orders(provider.id, first_atdl_orders)
|
|
|
122 |
except:
|
|
|
123 |
print "Some issue while processing the orders for First delivery attempt status"
|
|
|
124 |
traceback.print_exc()
|
|
|
125 |
|
| 4741 |
phani.kuma |
126 |
def process_delivery_report(provider):
|
|
|
127 |
try:
|
| 4910 |
phani.kuma |
128 |
orders_tobe_delivered = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
|
| 4741 |
phani.kuma |
129 |
delivered_orders, returned_orders, undelivered_orders = read_delivery_orders(orders_tobe_delivered)
|
|
|
130 |
if delivered_orders:
|
|
|
131 |
update_delivered_orders(provider.id, delivered_orders)
|
|
|
132 |
if returned_orders:
|
|
|
133 |
update_returned_orders(provider.id, returned_orders)
|
| 4910 |
phani.kuma |
134 |
if undelivered_orders:
|
|
|
135 |
update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
| 4741 |
phani.kuma |
136 |
except:
|
| 4910 |
phani.kuma |
137 |
print "Some issue while processing the orders for delivery status"
|
| 4741 |
phani.kuma |
138 |
traceback.print_exc()
|
|
|
139 |
|
| 4910 |
phani.kuma |
140 |
def generate_reports(provider):
|
|
|
141 |
get_doas_not_picked_up(provider)
|
|
|
142 |
get_returns_not_picked_up(provider)
|
|
|
143 |
get_orders_not_picked_up(provider)
|
|
|
144 |
get_orders_pending_local_connection(provider)
|
|
|
145 |
get_returned_orders(provider)
|
|
|
146 |
get_orders_not_delivered(provider)
|
|
|
147 |
|
|
|
148 |
def get_doas_not_picked_up(provider):
|
|
|
149 |
txnClient = TransactionClient().get_client()
|
|
|
150 |
try:
|
|
|
151 |
doas_not_picked_up = txnClient.getDoasNotPickedUp(provider.id)
|
|
|
152 |
except TransactionServiceException as tex:
|
|
|
153 |
print tex.message
|
|
|
154 |
|
|
|
155 |
try:
|
|
|
156 |
if doas_not_picked_up:
|
|
|
157 |
print "DOAs not Picked up:"
|
|
|
158 |
print doas_not_picked_up
|
| 5152 |
phani.kuma |
159 |
mismatch_file = "/tmp/BlueDart_DoaPickupMismatch.csv"
|
| 4910 |
phani.kuma |
160 |
print "Some of our DOA orders were not picked up. Printing report to:" + mismatch_file
|
|
|
161 |
print_dao_return_pickup_mismatch_report(mismatch_file, doas_not_picked_up)
|
|
|
162 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
163 |
mail(from_user, from_pwd, to,\
|
|
|
164 |
"DOA Pickup Mismatch for " + provider.name,\
|
|
|
165 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
166 |
pickup_mismatch_part)
|
|
|
167 |
except Exception:
|
|
|
168 |
print "Some issue sending the DOA mismatch report"
|
|
|
169 |
traceback.print_exc()
|
|
|
170 |
|
|
|
171 |
def get_returns_not_picked_up(provider):
|
|
|
172 |
txnClient = TransactionClient().get_client()
|
|
|
173 |
try:
|
|
|
174 |
returns_not_picked_up = txnClient.getReturnOrdersNotPickedUp(provider.id)
|
|
|
175 |
except TransactionServiceException as tex:
|
|
|
176 |
print tex.message
|
|
|
177 |
|
|
|
178 |
try:
|
|
|
179 |
if returns_not_picked_up:
|
|
|
180 |
print "Return Orders not Picked up:"
|
|
|
181 |
print returns_not_picked_up
|
| 5152 |
phani.kuma |
182 |
mismatch_file = "/tmp/BlueDart_ReturnsPickupMismatch.csv"
|
| 4910 |
phani.kuma |
183 |
print "Some of our Return orders were not picked up. Printing report to:" + mismatch_file
|
|
|
184 |
print_dao_return_pickup_mismatch_report(mismatch_file, returns_not_picked_up)
|
|
|
185 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
186 |
mail(from_user, from_pwd, to,\
|
|
|
187 |
"Return orders Pickup Mismatch for " + provider.name,\
|
|
|
188 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
189 |
pickup_mismatch_part)
|
|
|
190 |
except Exception:
|
|
|
191 |
print "Some issue sending the Return orders mismatch report"
|
|
|
192 |
traceback.print_exc()
|
|
|
193 |
|
|
|
194 |
def get_orders_not_picked_up(provider):
|
|
|
195 |
txnClient = TransactionClient().get_client()
|
|
|
196 |
try:
|
|
|
197 |
orders_not_picked_up = txnClient.getOrdersNotPickedUp(provider.id)
|
|
|
198 |
except TransactionServiceException as tex:
|
|
|
199 |
print tex.message
|
|
|
200 |
|
|
|
201 |
try:
|
|
|
202 |
if orders_not_picked_up:
|
|
|
203 |
print "Orders not Picked up:"
|
|
|
204 |
print orders_not_picked_up
|
| 5152 |
phani.kuma |
205 |
mismatch_file = "/tmp/BlueDart_PickupMismatch.csv"
|
| 4910 |
phani.kuma |
206 |
print "Some of our orders were not picked up. Printing report to:" + mismatch_file
|
|
|
207 |
print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
|
|
|
208 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
209 |
mail(from_user, from_pwd, to,\
|
|
|
210 |
"Order Pickup Mismatch for " + provider.name,\
|
|
|
211 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
212 |
pickup_mismatch_part)
|
|
|
213 |
except Exception:
|
|
|
214 |
print "Some issue sending the pickup mismatch report"
|
|
|
215 |
traceback.print_exc()
|
|
|
216 |
|
|
|
217 |
def get_orders_pending_local_connection(provider):
|
|
|
218 |
txnClient = TransactionClient().get_client()
|
|
|
219 |
try:
|
|
|
220 |
orders_pending_local_connection = txnClient.getOrdersNotLocalConnected(provider.id)
|
|
|
221 |
except TransactionServiceException as tex:
|
|
|
222 |
print tex.message
|
|
|
223 |
|
|
|
224 |
try:
|
|
|
225 |
if orders_pending_local_connection:
|
|
|
226 |
print "Local Connection Pending Orders:"
|
|
|
227 |
print orders_pending_local_connection
|
| 5152 |
phani.kuma |
228 |
mismatch_file = "/tmp/BlueDart_LocalConnectionPendingOrders.csv"
|
| 4910 |
phani.kuma |
229 |
print "Some of our Orders were not Shipped to Destination yet. Printing report to:" + mismatch_file
|
|
|
230 |
print_undelivered_orders_report(mismatch_file, orders_pending_local_connection)
|
|
|
231 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
232 |
mail(from_user, from_pwd, to,\
|
|
|
233 |
"Orders that are not Shipped to Destination yet for " + provider.name,\
|
|
|
234 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
235 |
pickup_mismatch_part)
|
|
|
236 |
except Exception:
|
|
|
237 |
print "Some issue updating and sending the Local Connection orders report"
|
|
|
238 |
traceback.print_exc()
|
|
|
239 |
|
|
|
240 |
def get_returned_orders(provider):
|
|
|
241 |
txnClient = TransactionClient().get_client()
|
|
|
242 |
try:
|
|
|
243 |
returned_orders = txnClient.getRTOrders(provider.id)
|
|
|
244 |
except TransactionServiceException as tex:
|
|
|
245 |
print tex.message
|
|
|
246 |
|
|
|
247 |
try:
|
|
|
248 |
if returned_orders:
|
|
|
249 |
print "Returned Orders:"
|
|
|
250 |
print returned_orders
|
| 5152 |
phani.kuma |
251 |
returned_orders_file = "/tmp/BlueDart_ReturnedOrders.csv"
|
| 4910 |
phani.kuma |
252 |
print "Some of our Orders were returned by logistics provider. Printing report to:" + returned_orders_file
|
|
|
253 |
print_rto_orders_report(returned_orders_file, returned_orders)
|
|
|
254 |
returned_orders_report = [get_attachment_part(returned_orders_file)]
|
|
|
255 |
mail(from_user, from_pwd, to,\
|
|
|
256 |
"Returned Orders Report for " + provider.name,\
|
|
|
257 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
258 |
returned_orders_report)
|
|
|
259 |
except:
|
|
|
260 |
print "Some issue sending the returned orders report"
|
|
|
261 |
traceback.print_exc()
|
|
|
262 |
|
|
|
263 |
def get_orders_not_delivered(provider):
|
|
|
264 |
txnClient = TransactionClient().get_client()
|
|
|
265 |
try:
|
|
|
266 |
orders_not_delivered = txnClient.getNonDeliveredOrdersbyCourier(provider.id)
|
|
|
267 |
except TransactionServiceException as tex:
|
|
|
268 |
print tex.message
|
|
|
269 |
|
|
|
270 |
try:
|
|
|
271 |
if orders_not_delivered:
|
|
|
272 |
print "Undelivered Orders:"
|
|
|
273 |
print orders_not_delivered
|
| 5152 |
phani.kuma |
274 |
mismatch_file = "/tmp/BlueDart_UndeliveredOrders.csv"
|
| 4910 |
phani.kuma |
275 |
print "Some of our Orders were not delivered. Printing report to:" + mismatch_file
|
|
|
276 |
print_undelivered_orders_report(mismatch_file, orders_not_delivered)
|
|
|
277 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
278 |
mail(from_user, from_pwd, to,\
|
|
|
279 |
"Orders that are undelivered but picked up or shipped four days ago for " + provider.name,\
|
|
|
280 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
281 |
pickup_mismatch_part)
|
|
|
282 |
except Exception:
|
|
|
283 |
print "Some issue updating and sending the undelivered orders report"
|
|
|
284 |
traceback.print_exc()
|
|
|
285 |
|
| 4741 |
phani.kuma |
286 |
def get_provider_by_name(provider_name):
|
|
|
287 |
logistics_client = LogisticsClient().get_client()
|
|
|
288 |
provider = None
|
|
|
289 |
providers = logistics_client.getAllProviders()
|
|
|
290 |
for p in providers:
|
|
|
291 |
if p.name == provider_name:
|
|
|
292 |
provider=p
|
|
|
293 |
break
|
|
|
294 |
if provider == None:
|
|
|
295 |
sys.exit("Can't continue execution: No such provider")
|
|
|
296 |
return provider
|
|
|
297 |
|
| 4910 |
phani.kuma |
298 |
def fetch_data(provider_id, order_status_list):
|
| 4741 |
phani.kuma |
299 |
txnClient = TransactionClient().get_client()
|
|
|
300 |
try:
|
| 4910 |
phani.kuma |
301 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status_list)
|
| 4741 |
phani.kuma |
302 |
return doas_tobe_picked_up
|
|
|
303 |
except TransactionServiceException as tex:
|
|
|
304 |
print tex.message
|
|
|
305 |
|
|
|
306 |
def read_dao_return_pickup_orders(orders_tobe_picked_up):
|
|
|
307 |
#uri=http://www.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery&loginid=DEL24119&awb=ref&format=XML&lickey=6265d61bafa6292c5ddfdb1ee335ca80&verno=1.3&scan=1&numbers=82390
|
|
|
308 |
picked_up_orders = {}
|
|
|
309 |
for order in orders_tobe_picked_up:
|
|
|
310 |
try:
|
|
|
311 |
uri = 'http://www.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery&loginid=DEL24119&awb=ref&format=XML&lickey=6265d61bafa6292c5ddfdb1ee335ca80&verno=1.3&scan=1&numbers=' + str(order.pickupRequestNo)
|
|
|
312 |
root = parse(urllib2.urlopen(uri)).getroot()
|
|
|
313 |
children = root.getchildren()
|
| 4910 |
phani.kuma |
314 |
for child in children:
|
|
|
315 |
nodes = child.findall('Scans/ScanDetail')
|
|
|
316 |
for element in reversed(nodes):
|
|
|
317 |
datestring = element.findtext('ScanDate', '')
|
|
|
318 |
timestring = element.findtext('ScanTime', '')
|
|
|
319 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
320 |
picked_up_orders[order.pickupRequestNo] = str(delivery_date)
|
|
|
321 |
break
|
| 5163 |
phani.kuma |
322 |
break
|
| 4741 |
phani.kuma |
323 |
except:
|
|
|
324 |
pass
|
|
|
325 |
|
|
|
326 |
print "Picked up Orders:"
|
|
|
327 |
print picked_up_orders
|
|
|
328 |
return picked_up_orders
|
|
|
329 |
|
|
|
330 |
def read_pickup_orders(orders_tobe_picked_up):
|
|
|
331 |
picked_up_orders = {}
|
|
|
332 |
for order in orders_tobe_picked_up:
|
|
|
333 |
try:
|
|
|
334 |
uri = BLUEDART_URL + order.airwaybill_no
|
|
|
335 |
root = parse(urllib2.urlopen(uri)).getroot()
|
|
|
336 |
children = root.getchildren()
|
| 4910 |
phani.kuma |
337 |
for child in children:
|
|
|
338 |
nodes = child.findall('Scans/ScanDetail')
|
|
|
339 |
for element in reversed(nodes):
|
|
|
340 |
datestring = element.findtext('ScanDate', '')
|
|
|
341 |
timestring = element.findtext('ScanTime', '')
|
|
|
342 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
343 |
picked_up_orders[order.airwaybill_no] = str(delivery_date)
|
|
|
344 |
break
|
| 5163 |
phani.kuma |
345 |
break
|
| 4741 |
phani.kuma |
346 |
except:
|
|
|
347 |
pass
|
|
|
348 |
|
|
|
349 |
print "Picked up Orders:"
|
|
|
350 |
print picked_up_orders
|
|
|
351 |
return picked_up_orders
|
|
|
352 |
|
| 4910 |
phani.kuma |
353 |
def read_local_connection_orders(orders_tobe_local_connected):
|
|
|
354 |
local_connected_orders = {}
|
|
|
355 |
for order in orders_tobe_local_connected:
|
|
|
356 |
try:
|
|
|
357 |
uri = BLUEDART_URL + order.airwaybill_no
|
|
|
358 |
root = parse(urllib2.urlopen(uri)).getroot()
|
|
|
359 |
children = root.getchildren()
|
|
|
360 |
for child in children:
|
|
|
361 |
nodes = child.findall('Scans/ScanDetail')
|
|
|
362 |
for element in reversed(nodes):
|
| 7635 |
manish.sha |
363 |
#Start:- Added By Manish Sharma for Making changes in case of Orders dispatched from Mumbai Warehouse on 26-Jun-2013
|
|
|
364 |
if order.warehouse_id == 12:
|
|
|
365 |
if (getTrimedString(element.findtext('ScannedLocation', '')) == getTrimedString('TARDEO') or getTrimedString(element.findtext('ScannedLocation', '')) == getTrimedString('MUMBAI HUB')) and element.findtext('ScanType', '') == 'UD' and getTrimedString(element.findtext('Scan', '')) == getTrimedString('SHIPMENT OUTSCANNED TO NETWORK'):
|
|
|
366 |
datestring = element.findtext('ScanDate', '')
|
|
|
367 |
timestring = element.findtext('ScanTime', '')
|
|
|
368 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
369 |
local_connected_orders[order.airwaybill_no] = str(delivery_date)
|
|
|
370 |
break
|
|
|
371 |
else:
|
|
|
372 |
if (getTrimedString(element.findtext('ScannedLocation', '')) == getTrimedString('RAMA ROAD HUB') or getTrimedString(element.findtext('ScannedLocation', '')) == getTrimedString('DELHI HUB')) and element.findtext('ScanType', '') == 'UD' and getTrimedString(element.findtext('Scan', '')) == getTrimedString('SHIPMENT OUTSCANNED TO NETWORK'):
|
|
|
373 |
datestring = element.findtext('ScanDate', '')
|
|
|
374 |
timestring = element.findtext('ScanTime', '')
|
|
|
375 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
376 |
local_connected_orders[order.airwaybill_no] = str(delivery_date)
|
|
|
377 |
break
|
|
|
378 |
#End:- Added By Manish Sharma for Making changes in case of Orders dispatched from Mumbai Warehouse on 26-Jun-2013
|
| 5163 |
phani.kuma |
379 |
break
|
| 4910 |
phani.kuma |
380 |
except:
|
|
|
381 |
pass
|
|
|
382 |
|
|
|
383 |
print "Local Connected Orders"
|
|
|
384 |
print local_connected_orders
|
|
|
385 |
|
|
|
386 |
return local_connected_orders
|
|
|
387 |
|
|
|
388 |
def read_reached_destination_orders(orders_tobe_reached_destination_city):
|
|
|
389 |
destination_city_reached_orders = {}
|
|
|
390 |
for order in orders_tobe_reached_destination_city:
|
|
|
391 |
try:
|
|
|
392 |
uri = BLUEDART_URL + order.airwaybill_no
|
|
|
393 |
root = parse(urllib2.urlopen(uri)).getroot()
|
|
|
394 |
children = root.getchildren()
|
|
|
395 |
child_number = 0
|
|
|
396 |
for child in children:
|
|
|
397 |
child_number = child_number + 1
|
|
|
398 |
nodes = child.findall('Scans/ScanDetail')
|
|
|
399 |
orderstatus = None
|
|
|
400 |
for element in nodes:
|
| 5152 |
phani.kuma |
401 |
if element.findtext('ScanType', '') == 'UD' and (getTrimedString(element.findtext('Scan', '')) == getTrimedString('Shipment Inscan') or getTrimedString(element.findtext('Scan', '')) == getTrimedString('Shipment-Autoscan')) and element.findtext('ScannedLocation', '') == child.findtext('Destination', ''):
|
| 4910 |
phani.kuma |
402 |
datestring = element.findtext('ScanDate', '')
|
|
|
403 |
timestring = element.findtext('ScanTime', '')
|
|
|
404 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
405 |
destination_city_reached_orders[order.airwaybill_no] = str(delivery_date)
|
|
|
406 |
orderstatus = 'UD'
|
|
|
407 |
break
|
|
|
408 |
elif element.findtext('ScanType', '') == 'RD':
|
|
|
409 |
if child_number < len(children):
|
|
|
410 |
orderstatus = 'RD'
|
|
|
411 |
break
|
|
|
412 |
if orderstatus != 'RD':
|
|
|
413 |
break
|
|
|
414 |
except:
|
|
|
415 |
pass
|
|
|
416 |
|
|
|
417 |
print "Destination City Reached Orders"
|
|
|
418 |
print destination_city_reached_orders
|
|
|
419 |
|
|
|
420 |
return destination_city_reached_orders
|
|
|
421 |
|
|
|
422 |
def read_first_delivery_attempt_orders(orders_tobe_first_delivery_attempted):
|
|
|
423 |
first_atdl_orders = {}
|
|
|
424 |
for order in orders_tobe_first_delivery_attempted:
|
|
|
425 |
try:
|
|
|
426 |
uri = BLUEDART_URL + order.airwaybill_no
|
|
|
427 |
root = parse(urllib2.urlopen(uri)).getroot()
|
|
|
428 |
children = root.getchildren()
|
|
|
429 |
child_number = 0
|
|
|
430 |
for child in children:
|
|
|
431 |
child_number = child_number + 1
|
|
|
432 |
nodes = child.findall('Scans/ScanDetail')
|
|
|
433 |
orderstatus = None
|
|
|
434 |
node_number = len(nodes)-1
|
|
|
435 |
for element in reversed(nodes):
|
|
|
436 |
if element.findtext('ScanType', '') == 'UD' and getTrimedString(element.findtext('Scan', '')) == getTrimedString('Shipment Outscan'):
|
|
|
437 |
if node_number != 0 and nodes[node_number-1].findtext('ScanType', '') == 'UD':
|
|
|
438 |
element = nodes[node_number-1]
|
|
|
439 |
datestring = element.findtext('ScanDate', '')
|
|
|
440 |
timestring = element.findtext('ScanTime', '')
|
|
|
441 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
442 |
reason_for_nondelivery = element.findtext('Scan', '')
|
|
|
443 |
first_atdl_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_nondelivery
|
|
|
444 |
orderstatus = 'UD'
|
|
|
445 |
break
|
| 5520 |
phani.kuma |
446 |
elif element.findtext('ScanType', '') == 'UD' and getTrimedString(element.findtext('Scan', '')) == getTrimedString("Shpt Held At Destination As Per Shipper's Request"):
|
|
|
447 |
datestring = element.findtext('ScanDate', '')
|
|
|
448 |
timestring = element.findtext('ScanTime', '')
|
|
|
449 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
450 |
reason_for_nondelivery = element.findtext('Scan', '')
|
|
|
451 |
first_atdl_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_nondelivery
|
|
|
452 |
orderstatus = 'UD'
|
|
|
453 |
break
|
| 4910 |
phani.kuma |
454 |
elif element.findtext('ScanType', '') == 'RD':
|
|
|
455 |
if child_number < len(children):
|
|
|
456 |
orderstatus = 'RD'
|
|
|
457 |
break
|
|
|
458 |
node_number = node_number - 1
|
|
|
459 |
if orderstatus != 'RD':
|
|
|
460 |
break
|
|
|
461 |
except:
|
|
|
462 |
pass
|
|
|
463 |
|
|
|
464 |
print "FIRST DELIVERY ATTEMPT MADE Orders"
|
|
|
465 |
print first_atdl_orders
|
|
|
466 |
|
|
|
467 |
return first_atdl_orders
|
|
|
468 |
|
| 4741 |
phani.kuma |
469 |
def read_delivery_orders(orders_tobe_delivered):
|
|
|
470 |
delivered_orders = {}
|
|
|
471 |
returned_orders = {}
|
|
|
472 |
undelivered_orders = {}
|
|
|
473 |
for order in orders_tobe_delivered:
|
|
|
474 |
try:
|
|
|
475 |
uri = BLUEDART_URL + order.airwaybill_no
|
|
|
476 |
root = parse(urllib2.urlopen(uri)).getroot()
|
|
|
477 |
children = root.getchildren()
|
|
|
478 |
child_number = 0
|
|
|
479 |
for child in children:
|
|
|
480 |
child_number = child_number + 1
|
|
|
481 |
nodes = child.findall('Scans/ScanDetail')
|
|
|
482 |
orderstatus = None
|
|
|
483 |
if len(nodes):
|
| 4910 |
phani.kuma |
484 |
node_number = len(nodes)-1
|
|
|
485 |
for element in reversed(nodes):
|
| 4999 |
phani.kuma |
486 |
if element.findtext('ScanType', '') == 'DL' and getTrimedString(element.findtext('Scan', '')) == getTrimedString('Shipment delivered'):
|
| 4741 |
phani.kuma |
487 |
orderstatus = 'DL'
|
|
|
488 |
datestring = element.findtext('ScanDate', '')
|
|
|
489 |
timestring = element.findtext('ScanTime', '')
|
|
|
490 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
491 |
receiver = child.findtext('ReceivedBy', '')
|
|
|
492 |
delivered_orders[order.airwaybill_no] = str(delivery_date) + "|" + receiver
|
|
|
493 |
break
|
|
|
494 |
elif element.findtext('ScanType', '') == 'RT':
|
|
|
495 |
orderstatus = 'RT'
|
|
|
496 |
datestring = element.findtext('ScanDate', '')
|
|
|
497 |
timestring = element.findtext('ScanTime', '')
|
|
|
498 |
delivery_date = get_py_datetime(datestring, timestring)
|
| 4910 |
phani.kuma |
499 |
if node_number < len(nodes)-1:
|
|
|
500 |
reason_for_return = nodes[node_number+1].findtext('Scan', '')
|
| 4741 |
phani.kuma |
501 |
else:
|
|
|
502 |
reason_for_return = element.findtext('Scan', '')
|
|
|
503 |
returned_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_return
|
|
|
504 |
break
|
|
|
505 |
elif element.findtext('ScanType', '') == 'RD':
|
| 4910 |
phani.kuma |
506 |
if child_number < len(children):
|
|
|
507 |
orderstatus = 'RD'
|
|
|
508 |
break
|
|
|
509 |
elif node_number == 0:
|
| 4920 |
phani.kuma |
510 |
if child.findtext('StatusType', '') == 'RT':
|
|
|
511 |
orderstatus = 'RT'
|
|
|
512 |
datestring = child.findtext('ScanDate', '')
|
|
|
513 |
timestring = child.findtext('ScanTime', '')
|
|
|
514 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
515 |
reason_for_return = child.findtext('Status', '')
|
|
|
516 |
returned_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_return
|
|
|
517 |
break
|
| 4999 |
phani.kuma |
518 |
elif child.findtext('StatusType', '') == 'DL' and getTrimedString(child.findtext('Scan', '')) == getTrimedString('Shipment delivered'):
|
| 4920 |
phani.kuma |
519 |
orderstatus = 'DL'
|
|
|
520 |
datestring = child.findtext('ScanDate', '')
|
|
|
521 |
timestring = child.findtext('ScanTime', '')
|
|
|
522 |
delivery_date = get_py_datetime(datestring, timestring)
|
|
|
523 |
receiver = child.findtext('ReceivedBy', '')
|
|
|
524 |
delivered_orders[order.airwaybill_no] = str(delivery_date) + "|" + receiver
|
|
|
525 |
break
|
|
|
526 |
else:
|
|
|
527 |
orderstatus = 'UD'
|
|
|
528 |
reason = child.findtext('Status', '')
|
|
|
529 |
undelivered_orders[order.airwaybill_no] = reason
|
|
|
530 |
break
|
| 4910 |
phani.kuma |
531 |
node_number = node_number - 1
|
| 4741 |
phani.kuma |
532 |
else:
|
|
|
533 |
if child_number > 1:
|
|
|
534 |
reason = children[child_number-1].findtext('Status', '')
|
|
|
535 |
undelivered_orders[order.airwaybill_no] = reason
|
|
|
536 |
if orderstatus != 'RD':
|
|
|
537 |
break
|
|
|
538 |
except:
|
|
|
539 |
pass
|
|
|
540 |
|
|
|
541 |
print "Delivered Orders:"
|
|
|
542 |
print delivered_orders
|
|
|
543 |
|
|
|
544 |
print "Returned Orders:"
|
|
|
545 |
print returned_orders
|
|
|
546 |
|
|
|
547 |
print "Undelivered Orders"
|
|
|
548 |
print undelivered_orders
|
|
|
549 |
|
|
|
550 |
return delivered_orders, returned_orders, undelivered_orders
|
|
|
551 |
|
|
|
552 |
def update_picked_orders(provider_id, pickup_details):
|
|
|
553 |
txnClient = TransactionClient().get_client()
|
|
|
554 |
try:
|
| 4910 |
phani.kuma |
555 |
txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
|
| 4741 |
phani.kuma |
556 |
except TransactionServiceException as tex:
|
|
|
557 |
print tex.message
|
|
|
558 |
|
|
|
559 |
def update_picked_doas(provider_id, doa_pickup_details):
|
|
|
560 |
txnClient = TransactionClient().get_client()
|
|
|
561 |
try:
|
| 4910 |
phani.kuma |
562 |
txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
| 4741 |
phani.kuma |
563 |
except TransactionServiceException as tex:
|
|
|
564 |
print tex.message
|
|
|
565 |
|
|
|
566 |
def update_picked_returns(provider_id, returns_pickup_details):
|
|
|
567 |
txnClient = TransactionClient().get_client()
|
|
|
568 |
try:
|
| 4910 |
phani.kuma |
569 |
txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
| 4741 |
phani.kuma |
570 |
except TransactionServiceException as tex:
|
|
|
571 |
print tex.message
|
|
|
572 |
|
|
|
573 |
def update_delivered_orders(provider_id, delivered_orders):
|
|
|
574 |
txnClient = TransactionClient().get_client()
|
|
|
575 |
try:
|
|
|
576 |
txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
|
|
|
577 |
except TransactionServiceException as tex:
|
|
|
578 |
print tex.message
|
|
|
579 |
|
|
|
580 |
def update_returned_orders(provider_id, returned_orders):
|
|
|
581 |
txnClient = TransactionClient().get_client()
|
|
|
582 |
try:
|
| 4910 |
phani.kuma |
583 |
txnClient.markAsRTOrders(provider_id, returned_orders)
|
| 4741 |
phani.kuma |
584 |
except TransactionServiceException as tex:
|
|
|
585 |
print tex.message
|
|
|
586 |
|
|
|
587 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
|
|
588 |
txnClient = TransactionClient().get_client()
|
|
|
589 |
try:
|
| 4910 |
phani.kuma |
590 |
txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
| 4741 |
phani.kuma |
591 |
except TransactionServiceException as tex:
|
|
|
592 |
print tex.message
|
|
|
593 |
|
| 4910 |
phani.kuma |
594 |
def update_local_connected_orders(provider_id, local_connected_orders):
|
|
|
595 |
txnClient = TransactionClient().get_client()
|
|
|
596 |
try:
|
|
|
597 |
txnClient.markOrdersAsLocalConnected(provider_id, local_connected_orders)
|
|
|
598 |
except TransactionServiceException as tex:
|
|
|
599 |
print tex.message
|
|
|
600 |
|
|
|
601 |
def update_destination_city_reached_orders(provider_id, destination_city_reached_orders):
|
|
|
602 |
txnClient = TransactionClient().get_client()
|
|
|
603 |
try:
|
|
|
604 |
txnClient.markOrdersAsDestinationCityReached(provider_id, destination_city_reached_orders)
|
|
|
605 |
except TransactionServiceException as tex:
|
|
|
606 |
print tex.message
|
|
|
607 |
|
|
|
608 |
def update_first_atdl_orders(provider_id, first_atdl_orders):
|
|
|
609 |
txnClient = TransactionClient().get_client()
|
|
|
610 |
try:
|
|
|
611 |
txnClient.markOrdersAsFirstDeliveryAttempted(provider_id, first_atdl_orders)
|
|
|
612 |
except TransactionServiceException as tex:
|
|
|
613 |
print tex.message
|
|
|
614 |
|
| 4741 |
phani.kuma |
615 |
def print_pickup_mismatch_report(filename, orders):
|
|
|
616 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
|
|
617 |
writer.writerow(['Order Id', 'AWB No', 'Shipping timestamp'])
|
|
|
618 |
for order in orders:
|
|
|
619 |
writer.writerow([order.id, order.airwaybill_no, to_py_date(order.shipping_timestamp)])
|
|
|
620 |
|
| 4783 |
phani.kuma |
621 |
def print_dao_return_pickup_mismatch_report(filename, orders):
|
|
|
622 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
|
|
623 |
writer.writerow(['Order Id', 'Pickup Request No', 'Authorization timestamp'])
|
|
|
624 |
for order in orders:
|
|
|
625 |
writer.writerow([order.id, order.pickupRequestNo, to_py_date(order.doa_auth_timestamp)])
|
|
|
626 |
|
| 4910 |
phani.kuma |
627 |
def print_rto_orders_report(filename, orders):
|
| 4741 |
phani.kuma |
628 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 4910 |
phani.kuma |
629 |
writer.writerow(['Order Id', 'AWB No', 'Return date', 'Reason'])
|
|
|
630 |
for order in orders:
|
|
|
631 |
statusDescription = ''
|
|
|
632 |
if order.statusDescription is not None:
|
|
|
633 |
statusDescription = order.statusDescription.replace(","," ")
|
|
|
634 |
writer.writerow([order.id, order.airwaybill_no, to_py_date(order.delivery_timestamp), statusDescription])
|
| 4741 |
phani.kuma |
635 |
|
|
|
636 |
def print_undelivered_orders_report(filename, orders):
|
|
|
637 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 6703 |
rajveer |
638 |
writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp', 'Promised delivery date', 'Expected delivery date', 'OTG'])
|
| 4741 |
phani.kuma |
639 |
for order in orders:
|
| 4792 |
phani.kuma |
640 |
statusDescription = ''
|
|
|
641 |
if order.statusDescription is not None:
|
|
|
642 |
statusDescription = order.statusDescription.replace(","," ")
|
| 6703 |
rajveer |
643 |
writer.writerow([order.id, order.airwaybill_no, order.status, statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp), to_py_date(order.promised_delivery_time), to_py_date(order.expected_delivery_time), 'True' if order.otg else 'False'])
|
| 4741 |
phani.kuma |
644 |
|
| 4910 |
phani.kuma |
645 |
def create_crm_tickets_for_delivey_attempted_orders(provider):
|
|
|
646 |
try:
|
|
|
647 |
tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
|
|
|
648 |
userClient = UserClient().get_client()
|
|
|
649 |
crmServiceClient = CRMClient().get_client()
|
|
|
650 |
for order in tickets_tobe_created:
|
|
|
651 |
ticket_created = False
|
|
|
652 |
searchFilter = SearchFilter()
|
|
|
653 |
user = userClient.getUserByEmail(order.customer_email)
|
|
|
654 |
if user is None or user.userId == -1:
|
|
|
655 |
searchFilter.customerEmailId = order.customer_email
|
|
|
656 |
searchFilter.customerMobileNumber = order.customer_mobilenumber
|
|
|
657 |
else:
|
|
|
658 |
searchFilter.customerId = user.userId
|
| 4999 |
phani.kuma |
659 |
searchFilter.ticketCategory = TicketCategory.UNDELIVERED
|
| 4910 |
phani.kuma |
660 |
tickets = crmServiceClient.getTickets(searchFilter)
|
|
|
661 |
print tickets
|
|
|
662 |
for old_ticket in tickets:
|
|
|
663 |
if old_ticket.orderId == order.id:
|
|
|
664 |
ticket_created = True
|
|
|
665 |
break
|
|
|
666 |
if not ticket_created:
|
|
|
667 |
print "creating ticket for orderId:"+str(order.id)
|
|
|
668 |
ticket = Ticket()
|
|
|
669 |
activity = Activity()
|
|
|
670 |
description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
|
|
|
671 |
ticket.creatorId = 1
|
| 4948 |
phani.kuma |
672 |
ticket.assigneeId = defaultUndeliveredAsssigneeId
|
|
|
673 |
ticket.category = TicketCategory.UNDELIVERED
|
| 4910 |
phani.kuma |
674 |
ticket.priority = TicketPriority.HIGH
|
|
|
675 |
ticket.status = TicketStatus.OPEN
|
|
|
676 |
ticket.description = description
|
|
|
677 |
ticket.orderId = order.id
|
|
|
678 |
ticket.airwayBillNo = order.airwaybill_no
|
|
|
679 |
|
|
|
680 |
activity.creatorId = 1
|
| 4948 |
phani.kuma |
681 |
activity.ticketAssigneeId = ticket.assigneeId
|
| 4910 |
phani.kuma |
682 |
activity.type = ActivityType.OTHER
|
|
|
683 |
activity.description = description
|
|
|
684 |
activity.ticketCategory = ticket.category
|
|
|
685 |
activity.ticketDescription = ticket.description
|
|
|
686 |
activity.ticketPriority = ticket.priority
|
|
|
687 |
activity.ticketStatus = ticket.status
|
|
|
688 |
|
|
|
689 |
if user is None or user.userId == -1:
|
|
|
690 |
ticket.customerEmailId = order.customer_email
|
|
|
691 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
|
|
692 |
ticket.customerName = order.customer_name
|
|
|
693 |
activity.customerEmailId = order.customer_email
|
|
|
694 |
activity.customerMobileNumber = order.customer_mobilenumber
|
|
|
695 |
activity.customerName = order.customer_name
|
|
|
696 |
else:
|
|
|
697 |
ticket.customerId = user.userId
|
|
|
698 |
activity.customerId = user.userId
|
|
|
699 |
|
|
|
700 |
crmServiceClient.insertTicket(ticket, activity)
|
| 6561 |
amit.gupta |
701 |
'''
|
|
|
702 |
Inform user about first delivery attempt
|
|
|
703 |
'''
|
|
|
704 |
enqueueMailForFDA(order)
|
| 4910 |
phani.kuma |
705 |
except:
|
|
|
706 |
print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
|
|
|
707 |
traceback.print_exc()
|
|
|
708 |
|
| 5007 |
phani.kuma |
709 |
def auto_close_crm_tickets_created():
|
| 4999 |
phani.kuma |
710 |
try:
|
|
|
711 |
ticket_created_orders = []
|
|
|
712 |
tickets_map = {}
|
|
|
713 |
crmServiceClient = CRMClient().get_client()
|
|
|
714 |
searchFilter = SearchFilter()
|
|
|
715 |
searchFilter.ticketCategory = TicketCategory.UNDELIVERED
|
|
|
716 |
searchFilter.ticketAssigneeIds = [defaultUndeliveredAsssigneeId]
|
|
|
717 |
searchFilter.ticketPriority = TicketPriority.HIGH
|
|
|
718 |
searchFilter.ticketStatuses = [TicketStatus.OPEN]
|
|
|
719 |
tickets = crmServiceClient.getTickets(searchFilter)
|
|
|
720 |
print tickets
|
|
|
721 |
for old_ticket in tickets:
|
|
|
722 |
ticket_created_orders.append(old_ticket.orderId)
|
|
|
723 |
tickets_map[old_ticket.orderId] = old_ticket
|
|
|
724 |
print ticket_created_orders
|
|
|
725 |
txnClient = TransactionClient().get_client()
|
|
|
726 |
orders = txnClient.getOrderList(ticket_created_orders)
|
|
|
727 |
for order in orders:
|
|
|
728 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE]:
|
|
|
729 |
old_ticket = tickets_map.get(order.id)
|
|
|
730 |
old_ticket.status = TicketStatus.CLOSED
|
|
|
731 |
activity = Activity()
|
|
|
732 |
activity.creatorId = 1
|
|
|
733 |
activity.ticketAssigneeId = old_ticket.assigneeId
|
|
|
734 |
activity.type = ActivityType.OTHER
|
|
|
735 |
activity.description = "Ticket Closed bcoz order status changed to:" + order.statusDescription
|
|
|
736 |
activity.ticketCategory = old_ticket.category
|
|
|
737 |
activity.ticketDescription = old_ticket.description
|
|
|
738 |
activity.ticketPriority = old_ticket.priority
|
|
|
739 |
activity.ticketStatus = old_ticket.status
|
|
|
740 |
|
|
|
741 |
if old_ticket.customerId is None or old_ticket.customerId == -1:
|
|
|
742 |
activity.customerEmailId = old_ticket.customerEmailId
|
|
|
743 |
activity.customerMobileNumber = old_ticket.customerMobileNumber
|
|
|
744 |
activity.customerName = old_ticket.customerName
|
|
|
745 |
else:
|
|
|
746 |
activity.customerId = old_ticket.customerId
|
|
|
747 |
|
|
|
748 |
crmServiceClient.updateTicket(old_ticket, activity)
|
|
|
749 |
except:
|
|
|
750 |
print "Some issue while closing crm tickets for orders in DELIVERY_SUCCESS status"
|
|
|
751 |
traceback.print_exc()
|
|
|
752 |
|
| 4741 |
phani.kuma |
753 |
def get_py_datetime(datestring, timestring):
|
|
|
754 |
# This should be a command line argument.
|
|
|
755 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
|
|
756 |
# get a complete list of format specifiers available for date time.
|
|
|
757 |
if datestring == '':
|
|
|
758 |
return None
|
| 4920 |
phani.kuma |
759 |
if datestring.find('-') == -1:
|
|
|
760 |
time_format = "%d %B %Y %H:%M:%S"
|
|
|
761 |
else:
|
|
|
762 |
time_format = "%d-%b-%Y %H:%M:%S"
|
| 4741 |
phani.kuma |
763 |
if timestring == '':
|
|
|
764 |
timestring = '00:00:00'
|
|
|
765 |
time_array = timestring.split(':')
|
|
|
766 |
if len(time_array) < 3:
|
|
|
767 |
timestring = timestring + ':00'
|
|
|
768 |
time_string = datestring + ' ' + timestring
|
|
|
769 |
mytime = time.strptime(time_string, time_format)
|
|
|
770 |
return datetime.datetime(*mytime[:6])
|
|
|
771 |
|
| 4910 |
phani.kuma |
772 |
def getTrimedString(text):
|
|
|
773 |
if text is None or text == '':
|
|
|
774 |
return ''
|
|
|
775 |
else:
|
|
|
776 |
text = text.strip().lower()
|
|
|
777 |
text_list = list(text)
|
|
|
778 |
new_text = ''
|
|
|
779 |
for letter in text_list:
|
|
|
780 |
if letter.isalnum():
|
|
|
781 |
new_text = new_text + str(letter)
|
|
|
782 |
return new_text
|
|
|
783 |
|
| 4741 |
phani.kuma |
784 |
def main():
|
|
|
785 |
parser = optparse.OptionParser()
|
|
|
786 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
|
|
787 |
action="store_true",
|
|
|
788 |
help="Run the pickup reconciliation")
|
|
|
789 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
|
|
790 |
action="store_true",
|
|
|
791 |
help="Run the delivery reconciliation")
|
| 4910 |
phani.kuma |
792 |
parser.add_option("-r", "--reports", dest="gen_reports",
|
|
|
793 |
action="store_true",
|
|
|
794 |
help="Generate logistic reconciliation reports")
|
| 4741 |
phani.kuma |
795 |
parser.add_option("-a", "--all", dest="all_reports",
|
|
|
796 |
action="store_true",
|
|
|
797 |
help="Run all reconciliations")
|
|
|
798 |
parser.add_option("-P", "--provider", dest="provider",
|
|
|
799 |
default="BlueDart", type="string",
|
|
|
800 |
help="The PROVIDER this report is for",
|
|
|
801 |
metavar="PROVIDER")
|
| 4910 |
phani.kuma |
802 |
parser.set_defaults(pickup_report=False, delivery_report=False, gen_reports=False, all_reports=False)
|
| 4741 |
phani.kuma |
803 |
(options, args) = parser.parse_args()
|
|
|
804 |
if len(args) != 0:
|
|
|
805 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
806 |
|
|
|
807 |
if options.all_reports:
|
|
|
808 |
options.pickup_report = True
|
|
|
809 |
options.delivery_report = True
|
|
|
810 |
|
|
|
811 |
provider = get_provider_by_name(options.provider)
|
|
|
812 |
|
|
|
813 |
if options.pickup_report:
|
|
|
814 |
process_pickup_records(provider)
|
| 4815 |
phani.kuma |
815 |
process_dao_pickup_orders(provider)
|
|
|
816 |
process_return_pickup_orders(provider)
|
| 4741 |
phani.kuma |
817 |
if options.delivery_report:
|
| 4910 |
phani.kuma |
818 |
process_local_connection_orders(provider)
|
|
|
819 |
process_reached_destination_city_orders(provider)
|
|
|
820 |
process_first_delivery_attempt_orders(provider)
|
| 4741 |
phani.kuma |
821 |
process_delivery_report(provider)
|
| 4910 |
phani.kuma |
822 |
create_crm_tickets_for_delivey_attempted_orders(provider)
|
| 5007 |
phani.kuma |
823 |
auto_close_crm_tickets_created()
|
| 4910 |
phani.kuma |
824 |
if options.gen_reports:
|
|
|
825 |
generate_reports(provider)
|
| 4741 |
phani.kuma |
826 |
|
|
|
827 |
if __name__ == '__main__':
|
|
|
828 |
main()
|