| 8367 |
manish.sha |
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 |
|
|
|
24 |
@author: Manish Sharma
|
|
|
25 |
'''
|
|
|
26 |
from shop2020.clients.CRMClient import CRMClient
|
|
|
27 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
|
|
28 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 13085 |
amit.gupta |
29 |
from shop2020.model.v1.order.script.LogisticUtils import \
|
|
|
30 |
create_crm_tickets_for_delivey_attempted_orders
|
|
|
31 |
from shop2020.thriftpy.crm.ttypes import SearchFilter, TicketCategory, Activity, \
|
|
|
32 |
TicketPriority, TicketStatus, ActivityType
|
| 8367 |
manish.sha |
33 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
|
|
34 |
OrderStatus
|
|
|
35 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
|
|
36 |
from shop2020.utils.Utils import to_py_date
|
|
|
37 |
import csv
|
|
|
38 |
import optparse
|
|
|
39 |
import sys
|
|
|
40 |
import traceback
|
|
|
41 |
|
|
|
42 |
if __name__ == '__main__' and __package__ is None:
|
|
|
43 |
import os
|
|
|
44 |
sys.path.insert(0, os.getcwd())
|
|
|
45 |
|
| 20088 |
kshitij.so |
46 |
defaultUndeliveredAsssigneeId = 65
|
| 13085 |
amit.gupta |
47 |
dtrUndeliveredAsssigneeId = 33
|
| 8367 |
manish.sha |
48 |
from_user = 'cnc.center@shop2020.in'
|
|
|
49 |
from_pwd = '5h0p2o2o'
|
| 9173 |
manish.sha |
50 |
to = ['cnc.center@shop2020.in', "amit.sirohi@shop2020.in", "sandeep.sachdeva@shop2020.in", "sunil.kumar@shop2020.in", "rajveer.singh@shop2020.in"]
|
| 8367 |
manish.sha |
51 |
|
|
|
52 |
|
|
|
53 |
def process_dao_pickup_orders(provider):
|
|
|
54 |
try:
|
|
|
55 |
doas_tobe_picked_up = fetch_data(provider.id, [OrderStatus.DOA_PICKUP_CONFIRMED])
|
|
|
56 |
doa_pickup_details = read_dao_return_pickup_orders(doas_tobe_picked_up)
|
|
|
57 |
if doa_pickup_details:
|
|
|
58 |
update_picked_doas(provider.id, doa_pickup_details)
|
|
|
59 |
except:
|
|
|
60 |
print "Some issue while processing the orders in DOA_PICKUP_CONFIRMED status"
|
|
|
61 |
traceback.print_exc()
|
|
|
62 |
|
|
|
63 |
def process_pickup_records(provider):
|
|
|
64 |
try:
|
|
|
65 |
orders_tobe_picked_up = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH])
|
|
|
66 |
pickup_details = read_pickup_orders(orders_tobe_picked_up)
|
|
|
67 |
if pickup_details:
|
|
|
68 |
update_picked_orders(provider.id, pickup_details)
|
|
|
69 |
except:
|
|
|
70 |
print "Some issue while processing the orders in SHIPPED_FROM_WH status"
|
|
|
71 |
traceback.print_exc()
|
|
|
72 |
|
|
|
73 |
def process_return_pickup_orders(provider):
|
|
|
74 |
try:
|
|
|
75 |
returns_tobe_picked_up = fetch_data(provider.id, [OrderStatus.RET_PICKUP_CONFIRMED])
|
|
|
76 |
returns_pickup_details = read_dao_return_pickup_orders(returns_tobe_picked_up)
|
|
|
77 |
if returns_pickup_details:
|
|
|
78 |
update_picked_returns(provider.id, returns_pickup_details)
|
|
|
79 |
except:
|
|
|
80 |
print "Some issue while processing the orders in RET_PICKUP_CONFIRMED status"
|
|
|
81 |
traceback.print_exc()
|
|
|
82 |
|
|
|
83 |
def process_local_connection_orders(provider):
|
|
|
84 |
try:
|
|
|
85 |
orders_tobe_local_connected = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST])
|
|
|
86 |
local_connected_orders = read_local_connection_orders(orders_tobe_local_connected)
|
|
|
87 |
if local_connected_orders:
|
|
|
88 |
update_local_connected_orders(provider.id, local_connected_orders)
|
|
|
89 |
except:
|
|
|
90 |
print "Some issue while processing the orders for local connection status"
|
|
|
91 |
traceback.print_exc()
|
|
|
92 |
|
|
|
93 |
def process_reached_destination_city_orders(provider):
|
|
|
94 |
try:
|
|
|
95 |
orders_tobe_reached_destination_city = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY])
|
|
|
96 |
destination_city_reached_orders = read_reached_destination_orders(orders_tobe_reached_destination_city)
|
|
|
97 |
if destination_city_reached_orders:
|
|
|
98 |
update_destination_city_reached_orders(provider.id, destination_city_reached_orders)
|
|
|
99 |
except:
|
|
|
100 |
print "Some issue while processing the orders for Reached Destination City status"
|
|
|
101 |
traceback.print_exc()
|
|
|
102 |
|
|
|
103 |
def process_first_delivery_attempt_orders(provider):
|
|
|
104 |
try:
|
|
|
105 |
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])
|
|
|
106 |
first_atdl_orders = read_first_delivery_attempt_orders(orders_tobe_first_delivery_attempted)
|
|
|
107 |
if first_atdl_orders:
|
|
|
108 |
update_first_atdl_orders(provider.id, first_atdl_orders)
|
|
|
109 |
except:
|
|
|
110 |
print "Some issue while processing the orders for First delivery attempt status"
|
|
|
111 |
traceback.print_exc()
|
|
|
112 |
|
|
|
113 |
def process_delivery_report(provider):
|
|
|
114 |
try:
|
| 20088 |
kshitij.so |
115 |
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, OrderStatus.RTO_IN_TRANSIT])
|
| 8367 |
manish.sha |
116 |
delivered_orders, returned_orders, undelivered_orders = read_delivery_orders(orders_tobe_delivered)
|
|
|
117 |
if delivered_orders:
|
| 20088 |
kshitij.so |
118 |
print "Marking delivery"
|
| 8367 |
manish.sha |
119 |
update_delivered_orders(provider.id, delivered_orders)
|
|
|
120 |
if returned_orders:
|
|
|
121 |
update_returned_orders(provider.id, returned_orders)
|
|
|
122 |
if undelivered_orders:
|
|
|
123 |
update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
|
|
124 |
except:
|
|
|
125 |
print "Some issue while processing the orders for delivery status"
|
|
|
126 |
traceback.print_exc()
|
|
|
127 |
|
|
|
128 |
def read_delivery_orders(orders_tobe_delivered):
|
|
|
129 |
delivered_orders = {}
|
|
|
130 |
returned_orders = {}
|
|
|
131 |
undelivered_orders = {}
|
|
|
132 |
order_list = []
|
| 20088 |
kshitij.so |
133 |
print "Orders to be delivered"
|
| 8367 |
manish.sha |
134 |
for order in orders_tobe_delivered:
|
| 20088 |
kshitij.so |
135 |
print order.id
|
| 8367 |
manish.sha |
136 |
order_list.append(order.id)
|
| 20088 |
kshitij.so |
137 |
print "========================="
|
| 8367 |
manish.sha |
138 |
|
|
|
139 |
try:
|
|
|
140 |
crmServiceClient = CRMClient().get_client()
|
|
|
141 |
delivered_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, "delivered_orders")
|
|
|
142 |
returned_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, "returned_orders")
|
|
|
143 |
undelivered_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, "undelivered_orders")
|
|
|
144 |
except:
|
| 20088 |
kshitij.so |
145 |
print "Exception in getting tracking details from crm server"
|
|
|
146 |
traceback.print_exc()
|
| 8367 |
manish.sha |
147 |
|
|
|
148 |
print "Delivered Orders:"
|
|
|
149 |
print delivered_orders
|
|
|
150 |
|
|
|
151 |
print "Returned Orders:"
|
|
|
152 |
print returned_orders
|
|
|
153 |
|
|
|
154 |
print "Undelivered Orders"
|
|
|
155 |
print undelivered_orders
|
|
|
156 |
|
|
|
157 |
return delivered_orders, returned_orders, undelivered_orders
|
|
|
158 |
|
|
|
159 |
def read_first_delivery_attempt_orders(orders_tobe_first_delivery_attempted):
|
|
|
160 |
first_atdl_orders = {}
|
|
|
161 |
order_list = []
|
|
|
162 |
for order in orders_tobe_first_delivery_attempted:
|
|
|
163 |
order_list.append(order.id)
|
|
|
164 |
|
|
|
165 |
try:
|
|
|
166 |
crmServiceClient = CRMClient().get_client()
|
|
|
167 |
first_atdl_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, "first_delivery_attempted_orders")
|
|
|
168 |
except:
|
|
|
169 |
pass
|
|
|
170 |
|
|
|
171 |
print "FIRST DELIVERY ATTEMPT MADE Orders"
|
|
|
172 |
print first_atdl_orders
|
|
|
173 |
|
|
|
174 |
return first_atdl_orders
|
|
|
175 |
|
|
|
176 |
def read_reached_destination_orders(orders_tobe_reached_destination_city):
|
|
|
177 |
destination_city_reached_orders = {}
|
|
|
178 |
order_list = []
|
|
|
179 |
for order in orders_tobe_reached_destination_city:
|
|
|
180 |
order_list.append(order.id)
|
|
|
181 |
|
|
|
182 |
try:
|
|
|
183 |
crmServiceClient = CRMClient().get_client()
|
|
|
184 |
destination_city_reached_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, "destination_city_reached_orders")
|
|
|
185 |
except:
|
|
|
186 |
pass
|
|
|
187 |
|
|
|
188 |
print "Destination City Reached Orders"
|
|
|
189 |
print destination_city_reached_orders
|
|
|
190 |
|
|
|
191 |
return destination_city_reached_orders
|
|
|
192 |
|
|
|
193 |
def read_local_connection_orders(orders_tobe_local_connected):
|
|
|
194 |
local_connected_orders = {}
|
|
|
195 |
order_list = []
|
|
|
196 |
for order in orders_tobe_local_connected:
|
|
|
197 |
order_list.append(order.id)
|
|
|
198 |
|
|
|
199 |
try:
|
|
|
200 |
crmServiceClient = CRMClient().get_client()
|
|
|
201 |
local_connected_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, "local_connection_orders")
|
|
|
202 |
except:
|
|
|
203 |
pass
|
|
|
204 |
|
|
|
205 |
print "Local Connected Orders"
|
|
|
206 |
print local_connected_orders
|
|
|
207 |
|
|
|
208 |
return local_connected_orders
|
|
|
209 |
|
|
|
210 |
def read_dao_return_pickup_orders(orders_tobe_picked_up):
|
|
|
211 |
picked_up_orders = {}
|
|
|
212 |
order_list = []
|
|
|
213 |
for order in orders_tobe_picked_up:
|
|
|
214 |
order_list.append(order.id)
|
|
|
215 |
|
|
|
216 |
try:
|
|
|
217 |
crmServiceClient = CRMClient().get_client()
|
|
|
218 |
picked_up_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, "dao_return_pickup_orders")
|
|
|
219 |
except:
|
|
|
220 |
pass
|
|
|
221 |
|
|
|
222 |
print "Picked up Orders:"
|
|
|
223 |
print picked_up_orders
|
|
|
224 |
return picked_up_orders
|
|
|
225 |
|
|
|
226 |
def read_pickup_orders(orders_tobe_picked_up):
|
|
|
227 |
picked_up_orders = {}
|
|
|
228 |
order_list = []
|
|
|
229 |
for order in orders_tobe_picked_up:
|
|
|
230 |
order_list.append(order.id)
|
|
|
231 |
|
|
|
232 |
try:
|
|
|
233 |
crmServiceClient = CRMClient().get_client()
|
|
|
234 |
picked_up_orders = crmServiceClient.getFedexReconciliationDataMap(order_list, 'picked_up_orders')
|
|
|
235 |
except:
|
|
|
236 |
pass
|
|
|
237 |
|
|
|
238 |
print "Picked up Orders:"
|
|
|
239 |
print picked_up_orders
|
|
|
240 |
return picked_up_orders
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
|
|
244 |
txnClient = TransactionClient().get_client()
|
|
|
245 |
try:
|
|
|
246 |
txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
|
|
247 |
except TransactionServiceException as tex:
|
|
|
248 |
print tex.message
|
|
|
249 |
|
|
|
250 |
def update_returned_orders(provider_id, returned_orders):
|
|
|
251 |
txnClient = TransactionClient().get_client()
|
|
|
252 |
try:
|
|
|
253 |
txnClient.markAsRTOrders(provider_id, returned_orders)
|
|
|
254 |
except TransactionServiceException as tex:
|
|
|
255 |
print tex.message
|
|
|
256 |
|
|
|
257 |
def update_delivered_orders(provider_id, delivered_orders):
|
| 20088 |
kshitij.so |
258 |
print "Marking delivery for ", delivered_orders
|
| 8367 |
manish.sha |
259 |
txnClient = TransactionClient().get_client()
|
|
|
260 |
try:
|
|
|
261 |
txnClient.markOrdersAsDelivered(provider_id, delivered_orders)
|
|
|
262 |
except TransactionServiceException as tex:
|
|
|
263 |
print tex.message
|
|
|
264 |
|
|
|
265 |
def update_first_atdl_orders(provider_id, first_atdl_orders):
|
|
|
266 |
txnClient = TransactionClient().get_client()
|
|
|
267 |
try:
|
|
|
268 |
txnClient.markOrdersAsFirstDeliveryAttempted(provider_id, first_atdl_orders)
|
|
|
269 |
except TransactionServiceException as tex:
|
|
|
270 |
print tex.message
|
|
|
271 |
|
|
|
272 |
|
|
|
273 |
def update_destination_city_reached_orders(provider_id, destination_city_reached_orders):
|
|
|
274 |
txnClient = TransactionClient().get_client()
|
|
|
275 |
try:
|
|
|
276 |
txnClient.markOrdersAsDestinationCityReached(provider_id, destination_city_reached_orders)
|
|
|
277 |
except TransactionServiceException as tex:
|
|
|
278 |
print tex.message
|
|
|
279 |
|
|
|
280 |
def update_local_connected_orders(provider_id, local_connected_orders):
|
|
|
281 |
txnClient = TransactionClient().get_client()
|
|
|
282 |
try:
|
|
|
283 |
txnClient.markOrdersAsLocalConnected(provider_id, local_connected_orders)
|
|
|
284 |
except TransactionServiceException as tex:
|
|
|
285 |
print tex.message
|
|
|
286 |
|
|
|
287 |
|
|
|
288 |
def update_picked_returns(provider_id, returns_pickup_details):
|
|
|
289 |
txnClient = TransactionClient().get_client()
|
|
|
290 |
try:
|
|
|
291 |
txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
|
|
292 |
except TransactionServiceException as tex:
|
|
|
293 |
print tex.message
|
|
|
294 |
|
|
|
295 |
def update_picked_doas(provider_id, doa_pickup_details):
|
|
|
296 |
txnClient = TransactionClient().get_client()
|
|
|
297 |
try:
|
|
|
298 |
txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
|
|
299 |
except TransactionServiceException as tex:
|
|
|
300 |
print tex.message
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
def update_picked_orders(provider_id, pickup_details):
|
|
|
304 |
txnClient = TransactionClient().get_client()
|
|
|
305 |
try:
|
|
|
306 |
txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
|
|
|
307 |
except TransactionServiceException as tex:
|
|
|
308 |
print tex.message
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
def fetch_data(provider_id, order_status_list):
|
|
|
312 |
txnClient = TransactionClient().get_client()
|
|
|
313 |
try:
|
|
|
314 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status_list)
|
|
|
315 |
return doas_tobe_picked_up
|
|
|
316 |
except TransactionServiceException as tex:
|
|
|
317 |
print tex.message
|
|
|
318 |
|
|
|
319 |
def get_provider_by_name(provider_name):
|
|
|
320 |
logistics_client = LogisticsClient().get_client()
|
|
|
321 |
provider = None
|
|
|
322 |
providers = logistics_client.getAllProviders()
|
|
|
323 |
for p in providers:
|
|
|
324 |
if p.name == provider_name:
|
|
|
325 |
provider=p
|
|
|
326 |
break
|
|
|
327 |
if provider == None:
|
|
|
328 |
sys.exit("Can't continue execution: No such provider")
|
|
|
329 |
return provider
|
|
|
330 |
|
|
|
331 |
def auto_close_crm_tickets_created():
|
|
|
332 |
try:
|
|
|
333 |
ticket_created_orders = []
|
|
|
334 |
tickets_map = {}
|
|
|
335 |
crmServiceClient = CRMClient().get_client()
|
|
|
336 |
searchFilter = SearchFilter()
|
|
|
337 |
searchFilter.ticketCategory = TicketCategory.UNDELIVERED
|
|
|
338 |
searchFilter.ticketAssigneeIds = [defaultUndeliveredAsssigneeId]
|
|
|
339 |
searchFilter.ticketPriority = TicketPriority.HIGH
|
|
|
340 |
searchFilter.ticketStatuses = [TicketStatus.OPEN]
|
|
|
341 |
tickets = crmServiceClient.getTickets(searchFilter)
|
|
|
342 |
print tickets
|
|
|
343 |
for old_ticket in tickets:
|
|
|
344 |
ticket_created_orders.append(old_ticket.orderId)
|
|
|
345 |
tickets_map[old_ticket.orderId] = old_ticket
|
|
|
346 |
print ticket_created_orders
|
|
|
347 |
txnClient = TransactionClient().get_client()
|
|
|
348 |
orders = txnClient.getOrderList(ticket_created_orders)
|
|
|
349 |
for order in orders:
|
| 13085 |
amit.gupta |
350 |
if order.status not in [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE, OrderStatus.RTO_IN_TRANSIT]:
|
| 8367 |
manish.sha |
351 |
old_ticket = tickets_map.get(order.id)
|
|
|
352 |
old_ticket.status = TicketStatus.CLOSED
|
|
|
353 |
activity = Activity()
|
|
|
354 |
activity.creatorId = 1
|
|
|
355 |
activity.ticketAssigneeId = old_ticket.assigneeId
|
|
|
356 |
activity.type = ActivityType.OTHER
|
|
|
357 |
activity.description = "Ticket Closed bcoz order status changed to:" + order.statusDescription
|
|
|
358 |
activity.ticketCategory = old_ticket.category
|
|
|
359 |
activity.ticketDescription = old_ticket.description
|
|
|
360 |
activity.ticketPriority = old_ticket.priority
|
|
|
361 |
activity.ticketStatus = old_ticket.status
|
|
|
362 |
|
|
|
363 |
if old_ticket.customerId is None or old_ticket.customerId == -1:
|
|
|
364 |
activity.customerEmailId = old_ticket.customerEmailId
|
|
|
365 |
activity.customerMobileNumber = old_ticket.customerMobileNumber
|
|
|
366 |
activity.customerName = old_ticket.customerName
|
|
|
367 |
else:
|
|
|
368 |
activity.customerId = old_ticket.customerId
|
|
|
369 |
|
|
|
370 |
crmServiceClient.updateTicket(old_ticket, activity)
|
|
|
371 |
except:
|
|
|
372 |
print "Some issue while closing crm tickets for orders in DELIVERY_SUCCESS status"
|
|
|
373 |
traceback.print_exc()
|
|
|
374 |
|
|
|
375 |
def generate_reports(provider):
|
|
|
376 |
#get_doas_not_picked_up(provider)
|
|
|
377 |
#get_returns_not_picked_up(provider)
|
|
|
378 |
get_orders_not_picked_up(provider)
|
|
|
379 |
get_orders_pending_local_connection(provider)
|
|
|
380 |
get_returned_orders(provider)
|
|
|
381 |
get_orders_not_delivered(provider)
|
|
|
382 |
|
|
|
383 |
def get_doas_not_picked_up(provider):
|
|
|
384 |
txnClient = TransactionClient().get_client()
|
|
|
385 |
try:
|
|
|
386 |
doas_not_picked_up = txnClient.getDoasNotPickedUp(provider.id)
|
|
|
387 |
except TransactionServiceException as tex:
|
|
|
388 |
print tex.message
|
|
|
389 |
|
|
|
390 |
try:
|
|
|
391 |
if doas_not_picked_up:
|
|
|
392 |
print "DOAs not Picked up:"
|
|
|
393 |
print doas_not_picked_up
|
|
|
394 |
mismatch_file = "/tmp/FedEx_DoaPickupMismatch.csv"
|
|
|
395 |
print "Some of our DOA orders were not picked up. Printing report to:" + mismatch_file
|
|
|
396 |
print_dao_return_pickup_mismatch_report(mismatch_file, doas_not_picked_up)
|
|
|
397 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
398 |
mail(from_user, from_pwd, to,\
|
|
|
399 |
"DOA Pickup Mismatch for " + provider.name,\
|
|
|
400 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
401 |
pickup_mismatch_part)
|
|
|
402 |
except Exception:
|
|
|
403 |
print "Some issue sending the DOA mismatch report"
|
|
|
404 |
traceback.print_exc()
|
|
|
405 |
|
|
|
406 |
def get_returns_not_picked_up(provider):
|
|
|
407 |
txnClient = TransactionClient().get_client()
|
|
|
408 |
try:
|
|
|
409 |
returns_not_picked_up = txnClient.getReturnOrdersNotPickedUp(provider.id)
|
|
|
410 |
except TransactionServiceException as tex:
|
|
|
411 |
print tex.message
|
|
|
412 |
|
|
|
413 |
try:
|
|
|
414 |
if returns_not_picked_up:
|
|
|
415 |
print "Return Orders not Picked up:"
|
|
|
416 |
print returns_not_picked_up
|
|
|
417 |
mismatch_file = "/tmp/FedEx_ReturnsPickupMismatch.csv"
|
|
|
418 |
print "Some of our Return orders were not picked up. Printing report to:" + mismatch_file
|
|
|
419 |
print_dao_return_pickup_mismatch_report(mismatch_file, returns_not_picked_up)
|
|
|
420 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
421 |
mail(from_user, from_pwd, to,\
|
|
|
422 |
"Return orders Pickup Mismatch for " + provider.name,\
|
|
|
423 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
424 |
pickup_mismatch_part)
|
|
|
425 |
except Exception:
|
|
|
426 |
print "Some issue sending the Return orders mismatch report"
|
|
|
427 |
traceback.print_exc()
|
|
|
428 |
|
|
|
429 |
def get_orders_not_picked_up(provider):
|
|
|
430 |
txnClient = TransactionClient().get_client()
|
|
|
431 |
try:
|
|
|
432 |
orders_not_picked_up = txnClient.getOrdersNotPickedUp(provider.id)
|
|
|
433 |
except TransactionServiceException as tex:
|
|
|
434 |
print tex.message
|
|
|
435 |
|
|
|
436 |
try:
|
|
|
437 |
if orders_not_picked_up:
|
|
|
438 |
print "Orders not Picked up:"
|
|
|
439 |
print orders_not_picked_up
|
|
|
440 |
mismatch_file = "/tmp/FedEx_PickupMismatch.csv"
|
|
|
441 |
print "Some of our orders were not picked up. Printing report to:" + mismatch_file
|
|
|
442 |
print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
|
|
|
443 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
444 |
mail(from_user, from_pwd, to,\
|
|
|
445 |
"Order Pickup Mismatch for " + provider.name,\
|
|
|
446 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
447 |
pickup_mismatch_part)
|
|
|
448 |
except Exception:
|
|
|
449 |
print "Some issue sending the pickup mismatch report"
|
|
|
450 |
traceback.print_exc()
|
|
|
451 |
|
|
|
452 |
def get_orders_pending_local_connection(provider):
|
|
|
453 |
txnClient = TransactionClient().get_client()
|
|
|
454 |
try:
|
|
|
455 |
orders_pending_local_connection = txnClient.getOrdersNotLocalConnected(provider.id)
|
|
|
456 |
except TransactionServiceException as tex:
|
|
|
457 |
print tex.message
|
|
|
458 |
|
|
|
459 |
try:
|
|
|
460 |
if orders_pending_local_connection:
|
|
|
461 |
print "Local Connection Pending Orders:"
|
|
|
462 |
print orders_pending_local_connection
|
|
|
463 |
mismatch_file = "/tmp/FedEx_LocalConnectionPendingOrders.csv"
|
|
|
464 |
print "Some of our Orders were not Shipped to Destination yet. Printing report to:" + mismatch_file
|
|
|
465 |
print_undelivered_orders_report(mismatch_file, orders_pending_local_connection)
|
|
|
466 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
467 |
mail(from_user, from_pwd, to,\
|
|
|
468 |
"Orders that are not Shipped to Destination yet for " + provider.name,\
|
|
|
469 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
470 |
pickup_mismatch_part)
|
|
|
471 |
except Exception:
|
|
|
472 |
print "Some issue updating and sending the Local Connection orders report"
|
|
|
473 |
traceback.print_exc()
|
|
|
474 |
|
|
|
475 |
def get_returned_orders(provider):
|
|
|
476 |
txnClient = TransactionClient().get_client()
|
|
|
477 |
try:
|
|
|
478 |
returned_orders = txnClient.getRTOrders(provider.id)
|
|
|
479 |
except TransactionServiceException as tex:
|
|
|
480 |
print tex.message
|
|
|
481 |
|
|
|
482 |
try:
|
|
|
483 |
if returned_orders:
|
|
|
484 |
print "Returned Orders:"
|
|
|
485 |
print returned_orders
|
|
|
486 |
returned_orders_file = "/tmp/Fedex_ReturnedOrders.csv"
|
|
|
487 |
print "Some of our Orders were returned by logistics provider. Printing report to:" + returned_orders_file
|
|
|
488 |
print_rto_orders_report(returned_orders_file, returned_orders)
|
|
|
489 |
returned_orders_report = [get_attachment_part(returned_orders_file)]
|
|
|
490 |
mail(from_user, from_pwd, to,\
|
|
|
491 |
"Returned Orders Report for " + provider.name,\
|
|
|
492 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
493 |
returned_orders_report)
|
|
|
494 |
except:
|
|
|
495 |
print "Some issue sending the returned orders report"
|
|
|
496 |
traceback.print_exc()
|
|
|
497 |
|
|
|
498 |
def get_orders_not_delivered(provider):
|
|
|
499 |
txnClient = TransactionClient().get_client()
|
|
|
500 |
try:
|
|
|
501 |
orders_not_delivered = txnClient.getNonDeliveredOrdersbyCourier(provider.id)
|
|
|
502 |
except TransactionServiceException as tex:
|
|
|
503 |
print tex.message
|
|
|
504 |
|
|
|
505 |
try:
|
|
|
506 |
if orders_not_delivered:
|
|
|
507 |
print "Undelivered Orders:"
|
|
|
508 |
print orders_not_delivered
|
|
|
509 |
mismatch_file = "/tmp/FedEx_UndeliveredOrders.csv"
|
|
|
510 |
print "Some of our Orders were not delivered. Printing report to:" + mismatch_file
|
|
|
511 |
print_undelivered_orders_report(mismatch_file, orders_not_delivered)
|
|
|
512 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
|
|
513 |
mail(from_user, from_pwd, to,\
|
|
|
514 |
"Orders that are undelivered but picked up or shipped four days ago for " + provider.name,\
|
|
|
515 |
"This is a system generated email.Please don't reply to it.",\
|
|
|
516 |
pickup_mismatch_part)
|
|
|
517 |
except Exception:
|
|
|
518 |
print "Some issue updating and sending the undelivered orders report"
|
|
|
519 |
traceback.print_exc()
|
|
|
520 |
|
|
|
521 |
def print_pickup_mismatch_report(filename, orders):
|
|
|
522 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
|
|
523 |
writer.writerow(['Order Id', 'AWB No', 'Shipping timestamp'])
|
|
|
524 |
for order in orders:
|
|
|
525 |
writer.writerow([order.id, order.airwaybill_no, to_py_date(order.shipping_timestamp)])
|
|
|
526 |
|
|
|
527 |
def print_dao_return_pickup_mismatch_report(filename, orders):
|
|
|
528 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
|
|
529 |
writer.writerow(['Order Id', 'Pickup Request No', 'Authorization timestamp'])
|
|
|
530 |
for order in orders:
|
|
|
531 |
writer.writerow([order.id, order.pickupRequestNo, to_py_date(order.doa_auth_timestamp)])
|
|
|
532 |
|
|
|
533 |
def print_rto_orders_report(filename, orders):
|
|
|
534 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
|
|
535 |
writer.writerow(['Order Id', 'AWB No', 'Return date', 'Reason'])
|
|
|
536 |
for order in orders:
|
|
|
537 |
statusDescription = ''
|
|
|
538 |
if order.statusDescription is not None:
|
|
|
539 |
statusDescription = order.statusDescription.replace(","," ")
|
|
|
540 |
writer.writerow([order.id, order.airwaybill_no, to_py_date(order.delivery_timestamp), statusDescription])
|
|
|
541 |
|
|
|
542 |
def print_undelivered_orders_report(filename, orders):
|
|
|
543 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
|
|
544 |
writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp', 'Promised delivery date', 'Expected delivery date', 'OTG'])
|
|
|
545 |
for order in orders:
|
|
|
546 |
statusDescription = ''
|
|
|
547 |
if order.statusDescription is not None:
|
|
|
548 |
statusDescription = order.statusDescription.replace(","," ")
|
|
|
549 |
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'])
|
|
|
550 |
|
|
|
551 |
|
|
|
552 |
def main():
|
|
|
553 |
parser = optparse.OptionParser()
|
|
|
554 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
|
|
555 |
action="store_true",
|
|
|
556 |
help="Run the pickup reconciliation")
|
|
|
557 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
|
|
558 |
action="store_true",
|
|
|
559 |
help="Run the delivery reconciliation")
|
|
|
560 |
parser.add_option("-r", "--reports", dest="gen_reports",
|
|
|
561 |
action="store_true",
|
|
|
562 |
help="Generate logistic reconciliation reports")
|
|
|
563 |
parser.add_option("-a", "--all", dest="all_reports",
|
|
|
564 |
action="store_true",
|
|
|
565 |
help="Run all reconciliations")
|
|
|
566 |
parser.add_option("-P", "--provider", dest="provider",
|
|
|
567 |
default="FedEx", type="string",
|
|
|
568 |
help="The PROVIDER this report is for",
|
|
|
569 |
metavar="PROVIDER")
|
|
|
570 |
parser.set_defaults(pickup_report=False, delivery_report=False, gen_reports=False, all_reports=False)
|
|
|
571 |
(options, args) = parser.parse_args()
|
|
|
572 |
if len(args) != 0:
|
|
|
573 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
574 |
|
|
|
575 |
if options.all_reports:
|
|
|
576 |
options.pickup_report = True
|
|
|
577 |
options.delivery_report = True
|
|
|
578 |
|
|
|
579 |
provider = get_provider_by_name(options.provider)
|
|
|
580 |
|
|
|
581 |
if options.pickup_report:
|
|
|
582 |
process_pickup_records(provider)
|
|
|
583 |
#process_dao_pickup_orders(provider)
|
|
|
584 |
#process_return_pickup_orders(provider)
|
|
|
585 |
if options.delivery_report:
|
|
|
586 |
process_local_connection_orders(provider)
|
|
|
587 |
process_reached_destination_city_orders(provider)
|
|
|
588 |
process_first_delivery_attempt_orders(provider)
|
|
|
589 |
process_delivery_report(provider)
|
|
|
590 |
create_crm_tickets_for_delivey_attempted_orders(provider)
|
|
|
591 |
auto_close_crm_tickets_created()
|
|
|
592 |
if options.gen_reports:
|
|
|
593 |
generate_reports(provider)
|
|
|
594 |
|
|
|
595 |
if __name__ == '__main__':
|
| 20088 |
kshitij.so |
596 |
main()
|
|
|
597 |
#-a -P FedEx-Surface
|
|
|
598 |
#760683,146
|