| Line 38... |
Line 38... |
| 38 |
import os
|
38 |
import os
|
| 39 |
sys.path.insert(0, os.getcwd())
|
39 |
sys.path.insert(0, os.getcwd())
|
| 40 |
|
40 |
|
| 41 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
41 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| 42 |
from shop2020.clients.TransactionClient import TransactionClient
|
42 |
from shop2020.clients.TransactionClient import TransactionClient
|
| - |
|
43 |
from shop2020.clients.UserClient import UserClient
|
| 43 |
from shop2020.config.client.ConfigClient import ConfigClient
|
44 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| - |
|
45 |
from shop2020.clients.CRMClient import CRMClient
|
| 44 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
46 |
from shop2020.thriftpy.config.ttypes import ConfigException
|
| 45 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, OrderStatus
|
47 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, OrderStatus
|
| 46 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
48 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part, mail
|
| 47 |
from shop2020.utils.Utils import to_py_date
|
49 |
from shop2020.utils.Utils import to_py_date
|
| - |
|
50 |
from shop2020.thriftpy.crm.ttypes import *
|
| - |
|
51 |
|
| - |
|
52 |
try:
|
| - |
|
53 |
config_client = ConfigClient()
|
| - |
|
54 |
BLUEDART_URL = config_client.get_property("bluedart_update_url")
|
| - |
|
55 |
except ConfigException as cex:
|
| - |
|
56 |
print cex.message
|
| - |
|
57 |
traceback.print_exc()
|
| 48 |
|
58 |
|
| 49 |
from_user = 'cnc.center@shop2020.in'
|
59 |
from_user = 'cnc.center@shop2020.in'
|
| 50 |
from_pwd = '5h0p2o2o'
|
60 |
from_pwd = '5h0p2o2o'
|
| 51 |
to = ['cnc.center@shop2020.in', "suraj.sharma@shop2020.in", "sandeep.sachdeva@shop2020.in", "manoj.kumar@shop2020.in"]
|
61 |
to = ['cnc.center@shop2020.in', "suraj.sharma@shop2020.in", "sandeep.sachdeva@shop2020.in", "manoj.kumar@shop2020.in"]
|
| 52 |
|
62 |
|
| 53 |
def process_dao_pickup_orders(provider):
|
63 |
def process_dao_pickup_orders(provider):
|
| 54 |
try:
|
64 |
try:
|
| 55 |
doas_tobe_picked_up = fetch_data(provider.id, OrderStatus.DOA_PICKUP_CONFIRMED)
|
65 |
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)
|
66 |
doa_pickup_details = read_dao_return_pickup_orders(doas_tobe_picked_up)
|
| 57 |
doas_not_picked_up = update_picked_doas(provider.id, doa_pickup_details)
|
- |
|
| 58 |
try:
|
- |
|
| 59 |
if doas_not_picked_up:
|
67 |
if doa_pickup_details:
|
| 60 |
print "DOAs not Picked up:"
|
- |
|
| 61 |
print doas_not_picked_up
|
- |
|
| 62 |
mismatch_file = "/tmp/DoaPickupMismatch.csv"
|
68 |
update_picked_doas(provider.id, doa_pickup_details)
|
| 63 |
print "Some of our DOA orders were not picked up. Printing report to:" + mismatch_file
|
- |
|
| 64 |
print_dao_return_pickup_mismatch_report(mismatch_file, doas_not_picked_up)
|
- |
|
| 65 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
- |
|
| 66 |
mail(from_user, from_pwd, to,\
|
- |
|
| 67 |
"DOA Pickup Mismatch for " + provider.name,\
|
- |
|
| 68 |
"This is a system generated email.Please don't reply to it.",\
|
- |
|
| 69 |
pickup_mismatch_part)
|
- |
|
| 70 |
except Exception:
|
- |
|
| 71 |
print "Some issue sending the DOA mismatch report"
|
- |
|
| 72 |
traceback.print_exc()
|
- |
|
| 73 |
except:
|
69 |
except:
|
| 74 |
print "Some issue while processing the orders in DOA_PICKUP_CONFIRMED status"
|
70 |
print "Some issue while processing the orders in DOA_PICKUP_CONFIRMED status"
|
| 75 |
traceback.print_exc()
|
71 |
traceback.print_exc()
|
| 76 |
|
72 |
|
| 77 |
def process_return_pickup_orders(provider):
|
73 |
def process_return_pickup_orders(provider):
|
| 78 |
try:
|
74 |
try:
|
| 79 |
returns_tobe_picked_up = fetch_data(provider.id, OrderStatus.RET_PICKUP_CONFIRMED)
|
75 |
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)
|
76 |
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:
|
77 |
if returns_pickup_details:
|
| 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_dao_return_pickup_mismatch_report(mismatch_file, returns_not_picked_up)
|
78 |
update_picked_returns(provider.id, returns_pickup_details)
|
| 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:
|
79 |
except:
|
| 98 |
print "Some issue while processing the orders in RET_PICKUP_CONFIRMED status"
|
80 |
print "Some issue while processing the orders in RET_PICKUP_CONFIRMED status"
|
| 99 |
traceback.print_exc()
|
81 |
traceback.print_exc()
|
| 100 |
|
82 |
|
| 101 |
def process_pickup_records(provider):
|
83 |
def process_pickup_records(provider):
|
| 102 |
try:
|
84 |
try:
|
| 103 |
orders_tobe_picked_up = fetch_data(provider.id, OrderStatus.SHIPPED_FROM_WH)
|
85 |
orders_tobe_picked_up = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH])
|
| 104 |
pickup_details = read_pickup_orders(orders_tobe_picked_up)
|
86 |
pickup_details = read_pickup_orders(orders_tobe_picked_up)
|
| 105 |
orders_not_picked_up = update_picked_orders(provider.id, pickup_details)
|
- |
|
| 106 |
try:
|
- |
|
| 107 |
if orders_not_picked_up:
|
- |
|
| 108 |
print "Orders not Picked up:"
|
- |
|
| 109 |
print orders_not_picked_up
|
- |
|
| 110 |
mismatch_file = "/tmp/PickupMismatch.csv"
|
- |
|
| 111 |
print "Some of our orders were not picked up. Printing report to:" + mismatch_file
|
- |
|
| 112 |
print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
|
- |
|
| 113 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
- |
|
| 114 |
mail(from_user, from_pwd, to,\
|
- |
|
| 115 |
"Order Pickup Mismatch for " + provider.name,\
|
- |
|
| 116 |
"This is a system generated email.Please don't reply to it.",\
|
- |
|
| 117 |
pickup_mismatch_part)
|
- |
|
| 118 |
except Exception:
|
87 |
if pickup_details:
|
| 119 |
print "Some issue sending the pickup mismatch report"
|
88 |
update_picked_orders(provider.id, pickup_details)
|
| 120 |
traceback.print_exc()
|
- |
|
| 121 |
except:
|
89 |
except:
|
| 122 |
print "Some issue while processing the orders in SHIPPED_FROM_WH status"
|
90 |
print "Some issue while processing the orders in SHIPPED_FROM_WH status"
|
| 123 |
traceback.print_exc()
|
91 |
traceback.print_exc()
|
| 124 |
|
92 |
|
| - |
|
93 |
def process_local_connection_orders(provider):
|
| - |
|
94 |
try:
|
| - |
|
95 |
orders_tobe_local_connected = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST])
|
| - |
|
96 |
local_connected_orders = read_local_connection_orders(orders_tobe_local_connected)
|
| - |
|
97 |
if local_connected_orders:
|
| - |
|
98 |
update_local_connected_orders(provider.id, local_connected_orders)
|
| - |
|
99 |
except:
|
| - |
|
100 |
print "Some issue while processing the orders for local connection status"
|
| - |
|
101 |
traceback.print_exc()
|
| - |
|
102 |
|
| - |
|
103 |
def process_reached_destination_city_orders(provider):
|
| - |
|
104 |
try:
|
| - |
|
105 |
orders_tobe_reached_destination_city = fetch_data(provider.id, [OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY])
|
| - |
|
106 |
destination_city_reached_orders = read_reached_destination_orders(orders_tobe_reached_destination_city)
|
| - |
|
107 |
if destination_city_reached_orders:
|
| - |
|
108 |
update_destination_city_reached_orders(provider.id, destination_city_reached_orders)
|
| - |
|
109 |
except:
|
| - |
|
110 |
print "Some issue while processing the orders for Reached Destination City status"
|
| - |
|
111 |
traceback.print_exc()
|
| - |
|
112 |
|
| - |
|
113 |
def process_first_delivery_attempt_orders(provider):
|
| - |
|
114 |
try:
|
| - |
|
115 |
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])
|
| - |
|
116 |
first_atdl_orders = read_first_delivery_attempt_orders(orders_tobe_first_delivery_attempted)
|
| - |
|
117 |
if first_atdl_orders:
|
| - |
|
118 |
update_first_atdl_orders(provider.id, first_atdl_orders)
|
| - |
|
119 |
except:
|
| - |
|
120 |
print "Some issue while processing the orders for First delivery attempt status"
|
| - |
|
121 |
traceback.print_exc()
|
| - |
|
122 |
|
| 125 |
def process_delivery_report(provider):
|
123 |
def process_delivery_report(provider):
|
| 126 |
try:
|
124 |
try:
|
| 127 |
orders_tobe_delivered = fetch_data(provider.id, OrderStatus.SHIPPED_TO_LOGST)
|
125 |
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])
|
| 128 |
delivered_orders, returned_orders, undelivered_orders = read_delivery_orders(orders_tobe_delivered)
|
126 |
delivered_orders, returned_orders, undelivered_orders = read_delivery_orders(orders_tobe_delivered)
|
| 129 |
if delivered_orders:
|
127 |
if delivered_orders:
|
| 130 |
update_delivered_orders(provider.id, delivered_orders)
|
128 |
update_delivered_orders(provider.id, delivered_orders)
|
| 131 |
if returned_orders:
|
129 |
if returned_orders:
|
| 132 |
update_returned_orders(provider.id, returned_orders)
|
130 |
update_returned_orders(provider.id, returned_orders)
|
| 133 |
try:
|
- |
|
| 134 |
returned_orders_file = "/tmp/ReturnedOrders.csv"
|
- |
|
| 135 |
print_rto_orders_report(returned_orders_file, returned_orders)
|
- |
|
| 136 |
returned_orders_report = [get_attachment_part(returned_orders_file)]
|
- |
|
| 137 |
mail(from_user, from_pwd, to,\
|
- |
|
| 138 |
"Returned Orders Report for " + provider.name,\
|
- |
|
| 139 |
"This is a system generated email.Please don't reply to it.",\
|
- |
|
| 140 |
returned_orders_report)
|
131 |
if undelivered_orders:
|
| 141 |
except:
|
- |
|
| 142 |
print "Some issue sending the returned orders report"
|
- |
|
| 143 |
traceback.print_exc()
|
- |
|
| 144 |
try:
|
- |
|
| 145 |
orders_not_delivered = update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
132 |
update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
| 146 |
if orders_not_delivered:
|
- |
|
| 147 |
print "Undelivered Orders:"
|
- |
|
| 148 |
print orders_not_delivered
|
- |
|
| 149 |
mismatch_file = "/tmp/UndeliveredOrders.csv"
|
- |
|
| 150 |
print "Some of our Orders were not delivered. Printing report to:" + mismatch_file
|
- |
|
| 151 |
print_undelivered_orders_report(mismatch_file, orders_not_delivered)
|
- |
|
| 152 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
- |
|
| 153 |
mail(from_user, from_pwd, to,\
|
- |
|
| 154 |
"Orders that are undelivered but picked up or shipped four days ago for " + provider.name,\
|
- |
|
| 155 |
"This is a system generated email.Please don't reply to it.",\
|
- |
|
| 156 |
pickup_mismatch_part)
|
- |
|
| 157 |
except Exception:
|
- |
|
| 158 |
print "Some issue updating and sending the undelivered orders report"
|
- |
|
| 159 |
traceback.print_exc()
|
- |
|
| 160 |
except:
|
133 |
except:
|
| 161 |
print "Some issue while processing the orders in SHIPPED_TO_LOGST status"
|
134 |
print "Some issue while processing the orders for delivery status"
|
| - |
|
135 |
traceback.print_exc()
|
| - |
|
136 |
|
| - |
|
137 |
def generate_reports(provider):
|
| - |
|
138 |
get_doas_not_picked_up(provider)
|
| - |
|
139 |
get_returns_not_picked_up(provider)
|
| - |
|
140 |
get_orders_not_picked_up(provider)
|
| - |
|
141 |
get_orders_pending_local_connection(provider)
|
| - |
|
142 |
get_returned_orders(provider)
|
| - |
|
143 |
get_orders_not_delivered(provider)
|
| - |
|
144 |
|
| - |
|
145 |
def get_doas_not_picked_up(provider):
|
| - |
|
146 |
txnClient = TransactionClient().get_client()
|
| - |
|
147 |
try:
|
| - |
|
148 |
doas_not_picked_up = txnClient.getDoasNotPickedUp(provider.id)
|
| - |
|
149 |
except TransactionServiceException as tex:
|
| - |
|
150 |
print tex.message
|
| - |
|
151 |
|
| - |
|
152 |
try:
|
| - |
|
153 |
if doas_not_picked_up:
|
| - |
|
154 |
print "DOAs not Picked up:"
|
| - |
|
155 |
print doas_not_picked_up
|
| - |
|
156 |
mismatch_file = "/tmp/DoaPickupMismatch.csv"
|
| - |
|
157 |
print "Some of our DOA orders were not picked up. Printing report to:" + mismatch_file
|
| - |
|
158 |
print_dao_return_pickup_mismatch_report(mismatch_file, doas_not_picked_up)
|
| - |
|
159 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
160 |
mail(from_user, from_pwd, to,\
|
| - |
|
161 |
"DOA Pickup Mismatch for " + provider.name,\
|
| - |
|
162 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
163 |
pickup_mismatch_part)
|
| - |
|
164 |
except Exception:
|
| - |
|
165 |
print "Some issue sending the DOA mismatch report"
|
| - |
|
166 |
traceback.print_exc()
|
| - |
|
167 |
|
| - |
|
168 |
def get_returns_not_picked_up(provider):
|
| - |
|
169 |
txnClient = TransactionClient().get_client()
|
| - |
|
170 |
try:
|
| - |
|
171 |
returns_not_picked_up = txnClient.getReturnOrdersNotPickedUp(provider.id)
|
| - |
|
172 |
except TransactionServiceException as tex:
|
| - |
|
173 |
print tex.message
|
| - |
|
174 |
|
| - |
|
175 |
try:
|
| - |
|
176 |
if returns_not_picked_up:
|
| - |
|
177 |
print "Return Orders not Picked up:"
|
| - |
|
178 |
print returns_not_picked_up
|
| - |
|
179 |
mismatch_file = "/tmp/ReturnsPickupMismatch.csv"
|
| - |
|
180 |
print "Some of our Return orders were not picked up. Printing report to:" + mismatch_file
|
| - |
|
181 |
print_dao_return_pickup_mismatch_report(mismatch_file, returns_not_picked_up)
|
| - |
|
182 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
183 |
mail(from_user, from_pwd, to,\
|
| - |
|
184 |
"Return orders Pickup Mismatch for " + provider.name,\
|
| - |
|
185 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
186 |
pickup_mismatch_part)
|
| - |
|
187 |
except Exception:
|
| - |
|
188 |
print "Some issue sending the Return orders mismatch report"
|
| - |
|
189 |
traceback.print_exc()
|
| - |
|
190 |
|
| - |
|
191 |
def get_orders_not_picked_up(provider):
|
| - |
|
192 |
txnClient = TransactionClient().get_client()
|
| - |
|
193 |
try:
|
| - |
|
194 |
orders_not_picked_up = txnClient.getOrdersNotPickedUp(provider.id)
|
| - |
|
195 |
except TransactionServiceException as tex:
|
| - |
|
196 |
print tex.message
|
| - |
|
197 |
|
| - |
|
198 |
try:
|
| - |
|
199 |
if orders_not_picked_up:
|
| - |
|
200 |
print "Orders not Picked up:"
|
| - |
|
201 |
print orders_not_picked_up
|
| - |
|
202 |
mismatch_file = "/tmp/PickupMismatch.csv"
|
| - |
|
203 |
print "Some of our orders were not picked up. Printing report to:" + mismatch_file
|
| - |
|
204 |
print_pickup_mismatch_report(mismatch_file, orders_not_picked_up)
|
| - |
|
205 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
206 |
mail(from_user, from_pwd, to,\
|
| - |
|
207 |
"Order Pickup Mismatch for " + provider.name,\
|
| - |
|
208 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
209 |
pickup_mismatch_part)
|
| - |
|
210 |
except Exception:
|
| - |
|
211 |
print "Some issue sending the pickup mismatch report"
|
| - |
|
212 |
traceback.print_exc()
|
| - |
|
213 |
|
| - |
|
214 |
def get_orders_pending_local_connection(provider):
|
| - |
|
215 |
txnClient = TransactionClient().get_client()
|
| - |
|
216 |
try:
|
| - |
|
217 |
orders_pending_local_connection = txnClient.getOrdersNotLocalConnected(provider.id)
|
| - |
|
218 |
except TransactionServiceException as tex:
|
| - |
|
219 |
print tex.message
|
| - |
|
220 |
|
| - |
|
221 |
try:
|
| - |
|
222 |
if orders_pending_local_connection:
|
| - |
|
223 |
print "Local Connection Pending Orders:"
|
| - |
|
224 |
print orders_pending_local_connection
|
| - |
|
225 |
mismatch_file = "/tmp/LocalConnectionPendingOrders.csv"
|
| - |
|
226 |
print "Some of our Orders were not Shipped to Destination yet. Printing report to:" + mismatch_file
|
| - |
|
227 |
print_undelivered_orders_report(mismatch_file, orders_pending_local_connection)
|
| - |
|
228 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
229 |
mail(from_user, from_pwd, to,\
|
| - |
|
230 |
"Orders that are not Shipped to Destination yet for " + provider.name,\
|
| - |
|
231 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
232 |
pickup_mismatch_part)
|
| - |
|
233 |
except Exception:
|
| - |
|
234 |
print "Some issue updating and sending the Local Connection orders report"
|
| - |
|
235 |
traceback.print_exc()
|
| - |
|
236 |
|
| - |
|
237 |
def get_returned_orders(provider):
|
| - |
|
238 |
txnClient = TransactionClient().get_client()
|
| - |
|
239 |
try:
|
| - |
|
240 |
returned_orders = txnClient.getRTOrders(provider.id)
|
| - |
|
241 |
except TransactionServiceException as tex:
|
| - |
|
242 |
print tex.message
|
| - |
|
243 |
|
| - |
|
244 |
try:
|
| - |
|
245 |
if returned_orders:
|
| - |
|
246 |
print "Returned Orders:"
|
| - |
|
247 |
print returned_orders
|
| - |
|
248 |
returned_orders_file = "/tmp/ReturnedOrders.csv"
|
| - |
|
249 |
print "Some of our Orders were returned by logistics provider. Printing report to:" + returned_orders_file
|
| - |
|
250 |
print_rto_orders_report(returned_orders_file, returned_orders)
|
| - |
|
251 |
returned_orders_report = [get_attachment_part(returned_orders_file)]
|
| - |
|
252 |
mail(from_user, from_pwd, to,\
|
| - |
|
253 |
"Returned Orders Report for " + provider.name,\
|
| - |
|
254 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
255 |
returned_orders_report)
|
| - |
|
256 |
except:
|
| - |
|
257 |
print "Some issue sending the returned orders report"
|
| - |
|
258 |
traceback.print_exc()
|
| - |
|
259 |
|
| - |
|
260 |
def get_orders_not_delivered(provider):
|
| - |
|
261 |
txnClient = TransactionClient().get_client()
|
| - |
|
262 |
try:
|
| - |
|
263 |
orders_not_delivered = txnClient.getNonDeliveredOrdersbyCourier(provider.id)
|
| - |
|
264 |
except TransactionServiceException as tex:
|
| - |
|
265 |
print tex.message
|
| - |
|
266 |
|
| - |
|
267 |
try:
|
| - |
|
268 |
if orders_not_delivered:
|
| - |
|
269 |
print "Undelivered Orders:"
|
| - |
|
270 |
print orders_not_delivered
|
| - |
|
271 |
mismatch_file = "/tmp/UndeliveredOrders.csv"
|
| - |
|
272 |
print "Some of our Orders were not delivered. Printing report to:" + mismatch_file
|
| - |
|
273 |
print_undelivered_orders_report(mismatch_file, orders_not_delivered)
|
| - |
|
274 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
| - |
|
275 |
mail(from_user, from_pwd, to,\
|
| - |
|
276 |
"Orders that are undelivered but picked up or shipped four days ago for " + provider.name,\
|
| - |
|
277 |
"This is a system generated email.Please don't reply to it.",\
|
| - |
|
278 |
pickup_mismatch_part)
|
| - |
|
279 |
except Exception:
|
| - |
|
280 |
print "Some issue updating and sending the undelivered orders report"
|
| 162 |
traceback.print_exc()
|
281 |
traceback.print_exc()
|
| 163 |
|
282 |
|
| 164 |
def get_provider_by_name(provider_name):
|
283 |
def get_provider_by_name(provider_name):
|
| 165 |
logistics_client = LogisticsClient().get_client()
|
284 |
logistics_client = LogisticsClient().get_client()
|
| 166 |
provider = None
|
285 |
provider = None
|
| Line 171... |
Line 290... |
| 171 |
break
|
290 |
break
|
| 172 |
if provider == None:
|
291 |
if provider == None:
|
| 173 |
sys.exit("Can't continue execution: No such provider")
|
292 |
sys.exit("Can't continue execution: No such provider")
|
| 174 |
return provider
|
293 |
return provider
|
| 175 |
|
294 |
|
| 176 |
def fetch_data(provider_id, order_status):
|
295 |
def fetch_data(provider_id, order_status_list):
|
| 177 |
txnClient = TransactionClient().get_client()
|
296 |
txnClient = TransactionClient().get_client()
|
| 178 |
try:
|
297 |
try:
|
| 179 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status)
|
298 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status_list)
|
| 180 |
return doas_tobe_picked_up
|
299 |
return doas_tobe_picked_up
|
| 181 |
except TransactionServiceException as tex:
|
300 |
except TransactionServiceException as tex:
|
| 182 |
print tex.message
|
301 |
print tex.message
|
| 183 |
|
302 |
|
| 184 |
def read_dao_return_pickup_orders(orders_tobe_picked_up):
|
303 |
def read_dao_return_pickup_orders(orders_tobe_picked_up):
|
| Line 187... |
Line 306... |
| 187 |
for order in orders_tobe_picked_up:
|
306 |
for order in orders_tobe_picked_up:
|
| 188 |
try:
|
307 |
try:
|
| 189 |
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)
|
308 |
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)
|
| 190 |
root = parse(urllib2.urlopen(uri)).getroot()
|
309 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 191 |
children = root.getchildren()
|
310 |
children = root.getchildren()
|
| 192 |
if len(children):
|
- |
|
| 193 |
firstchild = children[0]
|
311 |
for child in children:
|
| 194 |
nodes = firstchild.findall('Scans/ScanDetail')
|
312 |
nodes = child.findall('Scans/ScanDetail')
|
| 195 |
if len(nodes):
|
- |
|
| 196 |
element = nodes[len(nodes)-1]
|
313 |
for element in reversed(nodes):
|
| 197 |
if element.findtext('ScanType', '') == 'UD' and element.findtext('Scan', '').strip().lower() == 'Shipment Inscan'.lower():
|
- |
|
| 198 |
datestring = element.findtext('ScanDate', '')
|
314 |
datestring = element.findtext('ScanDate', '')
|
| 199 |
timestring = element.findtext('ScanTime', '')
|
315 |
timestring = element.findtext('ScanTime', '')
|
| 200 |
delivery_date = get_py_datetime(datestring, timestring)
|
316 |
delivery_date = get_py_datetime(datestring, timestring)
|
| 201 |
picked_up_orders[order.pickupRequestNo] = str(delivery_date)
|
317 |
picked_up_orders[order.pickupRequestNo] = str(delivery_date)
|
| - |
|
318 |
break
|
| 202 |
except:
|
319 |
except:
|
| 203 |
pass
|
320 |
pass
|
| 204 |
|
321 |
|
| 205 |
print "Picked up Orders:"
|
322 |
print "Picked up Orders:"
|
| 206 |
print picked_up_orders
|
323 |
print picked_up_orders
|
| 207 |
return picked_up_orders
|
324 |
return picked_up_orders
|
| 208 |
|
325 |
|
| 209 |
def read_pickup_orders(orders_tobe_picked_up):
|
326 |
def read_pickup_orders(orders_tobe_picked_up):
|
| 210 |
try:
|
- |
|
| 211 |
config_client = ConfigClient()
|
- |
|
| 212 |
BLUEDART_URL = config_client.get_property("bluedart_update_url")
|
- |
|
| 213 |
except ConfigException as cex:
|
- |
|
| 214 |
print cex.message
|
- |
|
| 215 |
traceback.print_exc()
|
- |
|
| 216 |
|
- |
|
| 217 |
picked_up_orders = {}
|
327 |
picked_up_orders = {}
|
| 218 |
for order in orders_tobe_picked_up:
|
328 |
for order in orders_tobe_picked_up:
|
| 219 |
try:
|
329 |
try:
|
| 220 |
uri = BLUEDART_URL + order.airwaybill_no
|
330 |
uri = BLUEDART_URL + order.airwaybill_no
|
| 221 |
root = parse(urllib2.urlopen(uri)).getroot()
|
331 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 222 |
children = root.getchildren()
|
332 |
children = root.getchildren()
|
| 223 |
if len(children):
|
- |
|
| 224 |
firstchild = children[0]
|
333 |
for child in children:
|
| 225 |
nodes = firstchild.findall('Scans/ScanDetail')
|
334 |
nodes = child.findall('Scans/ScanDetail')
|
| 226 |
if len(nodes):
|
- |
|
| 227 |
element = nodes[len(nodes)-1]
|
335 |
for element in reversed(nodes):
|
| 228 |
if element.findtext('ScanType', '') == 'UD' and element.findtext('Scan', '').strip().lower() == 'Shipment Inscan'.lower():
|
- |
|
| 229 |
datestring = element.findtext('ScanDate', '')
|
336 |
datestring = element.findtext('ScanDate', '')
|
| 230 |
timestring = element.findtext('ScanTime', '')
|
337 |
timestring = element.findtext('ScanTime', '')
|
| 231 |
delivery_date = get_py_datetime(datestring, timestring)
|
338 |
delivery_date = get_py_datetime(datestring, timestring)
|
| 232 |
picked_up_orders[order.airwaybill_no] = str(delivery_date)
|
339 |
picked_up_orders[order.airwaybill_no] = str(delivery_date)
|
| - |
|
340 |
break
|
| 233 |
except:
|
341 |
except:
|
| 234 |
pass
|
342 |
pass
|
| 235 |
|
343 |
|
| 236 |
print "Picked up Orders:"
|
344 |
print "Picked up Orders:"
|
| 237 |
print picked_up_orders
|
345 |
print picked_up_orders
|
| 238 |
return picked_up_orders
|
346 |
return picked_up_orders
|
| 239 |
|
347 |
|
| 240 |
def read_delivery_orders(orders_tobe_delivered):
|
348 |
def read_local_connection_orders(orders_tobe_local_connected):
|
| - |
|
349 |
local_connected_orders = {}
|
| - |
|
350 |
for order in orders_tobe_local_connected:
|
| 241 |
try:
|
351 |
try:
|
| - |
|
352 |
uri = BLUEDART_URL + order.airwaybill_no
|
| - |
|
353 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 242 |
config_client = ConfigClient()
|
354 |
children = root.getchildren()
|
| - |
|
355 |
for child in children:
|
| - |
|
356 |
nodes = child.findall('Scans/ScanDetail')
|
| - |
|
357 |
for element in reversed(nodes):
|
| 243 |
BLUEDART_URL = config_client.get_property("bluedart_update_url")
|
358 |
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'):
|
| - |
|
359 |
datestring = element.findtext('ScanDate', '')
|
| - |
|
360 |
timestring = element.findtext('ScanTime', '')
|
| - |
|
361 |
delivery_date = get_py_datetime(datestring, timestring)
|
| - |
|
362 |
local_connected_orders[order.airwaybill_no] = str(delivery_date)
|
| - |
|
363 |
break
|
| - |
|
364 |
except:
|
| - |
|
365 |
pass
|
| - |
|
366 |
|
| - |
|
367 |
print "Local Connected Orders"
|
| - |
|
368 |
print local_connected_orders
|
| - |
|
369 |
|
| - |
|
370 |
return local_connected_orders
|
| - |
|
371 |
|
| - |
|
372 |
def read_reached_destination_orders(orders_tobe_reached_destination_city):
|
| - |
|
373 |
destination_city_reached_orders = {}
|
| - |
|
374 |
for order in orders_tobe_reached_destination_city:
|
| - |
|
375 |
try:
|
| - |
|
376 |
uri = BLUEDART_URL + order.airwaybill_no
|
| - |
|
377 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| - |
|
378 |
children = root.getchildren()
|
| - |
|
379 |
child_number = 0
|
| - |
|
380 |
for child in children:
|
| - |
|
381 |
child_number = child_number + 1
|
| - |
|
382 |
nodes = child.findall('Scans/ScanDetail')
|
| - |
|
383 |
orderstatus = None
|
| 244 |
except ConfigException as cex:
|
384 |
for element in nodes:
|
| - |
|
385 |
if element.findtext('ScanType', '') == 'UD' and (getTrimedString(element.findtext('Scan', '')) == getTrimedString('Shipment Inscan') or getTrimedString(element.findtext('Scan', '')) == getTrimedString('Shipment-Autoscan')):
|
| - |
|
386 |
datestring = element.findtext('ScanDate', '')
|
| - |
|
387 |
timestring = element.findtext('ScanTime', '')
|
| - |
|
388 |
delivery_date = get_py_datetime(datestring, timestring)
|
| - |
|
389 |
destination_city_reached_orders[order.airwaybill_no] = str(delivery_date)
|
| - |
|
390 |
orderstatus = 'UD'
|
| - |
|
391 |
break
|
| - |
|
392 |
elif element.findtext('ScanType', '') == 'RD':
|
| - |
|
393 |
if child_number < len(children):
|
| - |
|
394 |
orderstatus = 'RD'
|
| - |
|
395 |
break
|
| - |
|
396 |
if orderstatus != 'RD':
|
| 245 |
print cex.message
|
397 |
break
|
| - |
|
398 |
except:
|
| - |
|
399 |
pass
|
| - |
|
400 |
|
| - |
|
401 |
print "Destination City Reached Orders"
|
| - |
|
402 |
print destination_city_reached_orders
|
| - |
|
403 |
|
| - |
|
404 |
return destination_city_reached_orders
|
| - |
|
405 |
|
| - |
|
406 |
def read_first_delivery_attempt_orders(orders_tobe_first_delivery_attempted):
|
| - |
|
407 |
first_atdl_orders = {}
|
| - |
|
408 |
for order in orders_tobe_first_delivery_attempted:
|
| - |
|
409 |
try:
|
| - |
|
410 |
uri = BLUEDART_URL + order.airwaybill_no
|
| - |
|
411 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| - |
|
412 |
children = root.getchildren()
|
| 246 |
traceback.print_exc()
|
413 |
child_number = 0
|
| - |
|
414 |
for child in children:
|
| - |
|
415 |
child_number = child_number + 1
|
| - |
|
416 |
nodes = child.findall('Scans/ScanDetail')
|
| - |
|
417 |
orderstatus = None
|
| - |
|
418 |
node_number = len(nodes)-1
|
| - |
|
419 |
for element in reversed(nodes):
|
| - |
|
420 |
if element.findtext('ScanType', '') == 'UD' and getTrimedString(element.findtext('Scan', '')) == getTrimedString('Shipment Outscan'):
|
| - |
|
421 |
if node_number != 0 and nodes[node_number-1].findtext('ScanType', '') == 'UD':
|
| - |
|
422 |
element = nodes[node_number-1]
|
| - |
|
423 |
datestring = element.findtext('ScanDate', '')
|
| - |
|
424 |
timestring = element.findtext('ScanTime', '')
|
| - |
|
425 |
delivery_date = get_py_datetime(datestring, timestring)
|
| - |
|
426 |
reason_for_nondelivery = element.findtext('Scan', '')
|
| - |
|
427 |
first_atdl_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_nondelivery
|
| - |
|
428 |
orderstatus = 'UD'
|
| - |
|
429 |
break
|
| - |
|
430 |
elif element.findtext('ScanType', '') == 'RD':
|
| - |
|
431 |
if child_number < len(children):
|
| - |
|
432 |
orderstatus = 'RD'
|
| - |
|
433 |
break
|
| - |
|
434 |
node_number = node_number - 1
|
| - |
|
435 |
if orderstatus != 'RD':
|
| - |
|
436 |
break
|
| - |
|
437 |
except:
|
| - |
|
438 |
pass
|
| 247 |
|
439 |
|
| - |
|
440 |
print "FIRST DELIVERY ATTEMPT MADE Orders"
|
| - |
|
441 |
print first_atdl_orders
|
| - |
|
442 |
|
| - |
|
443 |
return first_atdl_orders
|
| - |
|
444 |
|
| - |
|
445 |
def read_delivery_orders(orders_tobe_delivered):
|
| 248 |
delivered_orders = {}
|
446 |
delivered_orders = {}
|
| 249 |
returned_orders = {}
|
447 |
returned_orders = {}
|
| 250 |
undelivered_orders = {}
|
448 |
undelivered_orders = {}
|
| 251 |
for order in orders_tobe_delivered:
|
449 |
for order in orders_tobe_delivered:
|
| 252 |
try:
|
450 |
try:
|
| Line 257... |
Line 455... |
| 257 |
for child in children:
|
455 |
for child in children:
|
| 258 |
child_number = child_number + 1
|
456 |
child_number = child_number + 1
|
| 259 |
nodes = child.findall('Scans/ScanDetail')
|
457 |
nodes = child.findall('Scans/ScanDetail')
|
| 260 |
orderstatus = None
|
458 |
orderstatus = None
|
| 261 |
if len(nodes):
|
459 |
if len(nodes):
|
| 262 |
i = len(nodes)-1
|
460 |
node_number = len(nodes)-1
|
| 263 |
while i>=0:
|
- |
|
| 264 |
element = nodes[i]
|
461 |
for element in reversed(nodes):
|
| 265 |
if element.findtext('ScanType', '') == 'DL':
|
462 |
if element.findtext('ScanType', '') == 'DL':
|
| 266 |
orderstatus = 'DL'
|
463 |
orderstatus = 'DL'
|
| 267 |
datestring = element.findtext('ScanDate', '')
|
464 |
datestring = element.findtext('ScanDate', '')
|
| 268 |
timestring = element.findtext('ScanTime', '')
|
465 |
timestring = element.findtext('ScanTime', '')
|
| 269 |
delivery_date = get_py_datetime(datestring, timestring)
|
466 |
delivery_date = get_py_datetime(datestring, timestring)
|
| Line 273... |
Line 470... |
| 273 |
elif element.findtext('ScanType', '') == 'RT':
|
470 |
elif element.findtext('ScanType', '') == 'RT':
|
| 274 |
orderstatus = 'RT'
|
471 |
orderstatus = 'RT'
|
| 275 |
datestring = element.findtext('ScanDate', '')
|
472 |
datestring = element.findtext('ScanDate', '')
|
| 276 |
timestring = element.findtext('ScanTime', '')
|
473 |
timestring = element.findtext('ScanTime', '')
|
| 277 |
delivery_date = get_py_datetime(datestring, timestring)
|
474 |
delivery_date = get_py_datetime(datestring, timestring)
|
| 278 |
if i < len(nodes)-1:
|
475 |
if node_number < len(nodes)-1:
|
| 279 |
reason_for_return = nodes[i+1].findtext('Scan', '')
|
476 |
reason_for_return = nodes[node_number+1].findtext('Scan', '')
|
| 280 |
else:
|
477 |
else:
|
| 281 |
reason_for_return = element.findtext('Scan', '')
|
478 |
reason_for_return = element.findtext('Scan', '')
|
| 282 |
returned_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_return
|
479 |
returned_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_return
|
| 283 |
break
|
480 |
break
|
| 284 |
elif element.findtext('ScanType', '') == 'RD':
|
481 |
elif element.findtext('ScanType', '') == 'RD':
|
| - |
|
482 |
if child_number < len(children):
|
| 285 |
orderstatus = 'RD'
|
483 |
orderstatus = 'RD'
|
| 286 |
break
|
484 |
break
|
| 287 |
elif i == 0:
|
485 |
elif node_number == 0:
|
| 288 |
orderstatus = 'UD'
|
486 |
orderstatus = 'UD'
|
| 289 |
reason = child.findtext('Status', '')
|
487 |
reason = child.findtext('Status', '')
|
| 290 |
undelivered_orders[order.airwaybill_no] = reason
|
488 |
undelivered_orders[order.airwaybill_no] = reason
|
| 291 |
break
|
489 |
break
|
| 292 |
i = i-1
|
490 |
node_number = node_number - 1
|
| 293 |
else:
|
491 |
else:
|
| 294 |
if child_number > 1:
|
492 |
if child_number > 1:
|
| 295 |
reason = children[child_number-1].findtext('Status', '')
|
493 |
reason = children[child_number-1].findtext('Status', '')
|
| 296 |
undelivered_orders[order.airwaybill_no] = reason
|
494 |
undelivered_orders[order.airwaybill_no] = reason
|
| 297 |
if orderstatus != 'RD':
|
495 |
if orderstatus != 'RD':
|
| Line 311... |
Line 509... |
| 311 |
return delivered_orders, returned_orders, undelivered_orders
|
509 |
return delivered_orders, returned_orders, undelivered_orders
|
| 312 |
|
510 |
|
| 313 |
def update_picked_orders(provider_id, pickup_details):
|
511 |
def update_picked_orders(provider_id, pickup_details):
|
| 314 |
txnClient = TransactionClient().get_client()
|
512 |
txnClient = TransactionClient().get_client()
|
| 315 |
try:
|
513 |
try:
|
| 316 |
orders_not_picked_up = txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
|
514 |
txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
|
| 317 |
return orders_not_picked_up
|
- |
|
| 318 |
except TransactionServiceException as tex:
|
515 |
except TransactionServiceException as tex:
|
| 319 |
print tex.message
|
516 |
print tex.message
|
| 320 |
|
517 |
|
| 321 |
def update_picked_doas(provider_id, doa_pickup_details):
|
518 |
def update_picked_doas(provider_id, doa_pickup_details):
|
| 322 |
txnClient = TransactionClient().get_client()
|
519 |
txnClient = TransactionClient().get_client()
|
| 323 |
try:
|
520 |
try:
|
| 324 |
doas_not_picked_up = txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
521 |
txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
| 325 |
return doas_not_picked_up
|
- |
|
| 326 |
except TransactionServiceException as tex:
|
522 |
except TransactionServiceException as tex:
|
| 327 |
print tex.message
|
523 |
print tex.message
|
| 328 |
|
524 |
|
| 329 |
def update_picked_returns(provider_id, returns_pickup_details):
|
525 |
def update_picked_returns(provider_id, returns_pickup_details):
|
| 330 |
txnClient = TransactionClient().get_client()
|
526 |
txnClient = TransactionClient().get_client()
|
| 331 |
try:
|
527 |
try:
|
| 332 |
returns_not_picked_up = txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
528 |
txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
| 333 |
return returns_not_picked_up
|
- |
|
| 334 |
except TransactionServiceException as tex:
|
529 |
except TransactionServiceException as tex:
|
| 335 |
print tex.message
|
530 |
print tex.message
|
| 336 |
|
531 |
|
| 337 |
def update_delivered_orders(provider_id, delivered_orders):
|
532 |
def update_delivered_orders(provider_id, delivered_orders):
|
| 338 |
txnClient = TransactionClient().get_client()
|
533 |
txnClient = TransactionClient().get_client()
|
| Line 342... |
Line 537... |
| 342 |
print tex.message
|
537 |
print tex.message
|
| 343 |
|
538 |
|
| 344 |
def update_returned_orders(provider_id, returned_orders):
|
539 |
def update_returned_orders(provider_id, returned_orders):
|
| 345 |
txnClient = TransactionClient().get_client()
|
540 |
txnClient = TransactionClient().get_client()
|
| 346 |
try:
|
541 |
try:
|
| 347 |
txnClient.markOrdersAsFailed(provider_id, returned_orders)
|
542 |
txnClient.markAsRTOrders(provider_id, returned_orders)
|
| 348 |
except TransactionServiceException as tex:
|
543 |
except TransactionServiceException as tex:
|
| 349 |
print tex.message
|
544 |
print tex.message
|
| 350 |
|
545 |
|
| 351 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
546 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
| 352 |
txnClient = TransactionClient().get_client()
|
547 |
txnClient = TransactionClient().get_client()
|
| 353 |
try:
|
548 |
try:
|
| 354 |
orders_not_delivered = txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
549 |
txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
| - |
|
550 |
except TransactionServiceException as tex:
|
| - |
|
551 |
print tex.message
|
| - |
|
552 |
|
| - |
|
553 |
def update_local_connected_orders(provider_id, local_connected_orders):
|
| - |
|
554 |
txnClient = TransactionClient().get_client()
|
| - |
|
555 |
try:
|
| - |
|
556 |
txnClient.markOrdersAsLocalConnected(provider_id, local_connected_orders)
|
| - |
|
557 |
except TransactionServiceException as tex:
|
| - |
|
558 |
print tex.message
|
| - |
|
559 |
|
| - |
|
560 |
def update_destination_city_reached_orders(provider_id, destination_city_reached_orders):
|
| - |
|
561 |
txnClient = TransactionClient().get_client()
|
| - |
|
562 |
try:
|
| - |
|
563 |
txnClient.markOrdersAsDestinationCityReached(provider_id, destination_city_reached_orders)
|
| - |
|
564 |
except TransactionServiceException as tex:
|
| 355 |
return orders_not_delivered
|
565 |
print tex.message
|
| - |
|
566 |
|
| - |
|
567 |
def update_first_atdl_orders(provider_id, first_atdl_orders):
|
| - |
|
568 |
txnClient = TransactionClient().get_client()
|
| - |
|
569 |
try:
|
| - |
|
570 |
txnClient.markOrdersAsFirstDeliveryAttempted(provider_id, first_atdl_orders)
|
| 356 |
except TransactionServiceException as tex:
|
571 |
except TransactionServiceException as tex:
|
| 357 |
print tex.message
|
572 |
print tex.message
|
| 358 |
|
573 |
|
| 359 |
def print_pickup_mismatch_report(filename, orders):
|
574 |
def print_pickup_mismatch_report(filename, orders):
|
| 360 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
575 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| Line 366... |
Line 581... |
| 366 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
581 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 367 |
writer.writerow(['Order Id', 'Pickup Request No', 'Authorization timestamp'])
|
582 |
writer.writerow(['Order Id', 'Pickup Request No', 'Authorization timestamp'])
|
| 368 |
for order in orders:
|
583 |
for order in orders:
|
| 369 |
writer.writerow([order.id, order.pickupRequestNo, to_py_date(order.doa_auth_timestamp)])
|
584 |
writer.writerow([order.id, order.pickupRequestNo, to_py_date(order.doa_auth_timestamp)])
|
| 370 |
|
585 |
|
| 371 |
def print_rto_orders_report(filename, returned_orders):
|
586 |
def print_rto_orders_report(filename, orders):
|
| 372 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
587 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 373 |
writer.writerow(['AWB No', 'Return date', 'Reason'])
|
588 |
writer.writerow(['Order Id', 'AWB No', 'Return date', 'Reason'])
|
| 374 |
for awb, date_reason in returned_orders.iteritems():
|
589 |
for order in orders:
|
| 375 |
date, reason = date_reason.split('|')
|
590 |
statusDescription = ''
|
| 376 |
if reason is not None:
|
591 |
if order.statusDescription is not None:
|
| 377 |
reason = reason.replace(","," ")
|
592 |
statusDescription = order.statusDescription.replace(","," ")
|
| 378 |
writer.writerow([awb, date, reason])
|
593 |
writer.writerow([order.id, order.airwaybill_no, to_py_date(order.delivery_timestamp), statusDescription])
|
| 379 |
|
594 |
|
| 380 |
def print_undelivered_orders_report(filename, orders):
|
595 |
def print_undelivered_orders_report(filename, orders):
|
| 381 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
596 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 382 |
writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp'])
|
597 |
writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp'])
|
| 383 |
for order in orders:
|
598 |
for order in orders:
|
| 384 |
statusDescription = ''
|
599 |
statusDescription = ''
|
| 385 |
if order.statusDescription is not None:
|
600 |
if order.statusDescription is not None:
|
| 386 |
statusDescription = order.statusDescription.replace(","," ")
|
601 |
statusDescription = order.statusDescription.replace(","," ")
|
| 387 |
writer.writerow([order.id, order.airwaybill_no, order.status, statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp)])
|
602 |
writer.writerow([order.id, order.airwaybill_no, order.status, statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp)])
|
| 388 |
|
603 |
|
| - |
|
604 |
def create_crm_tickets_for_delivey_attempted_orders(provider):
|
| - |
|
605 |
try:
|
| - |
|
606 |
tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
|
| - |
|
607 |
userClient = UserClient().get_client()
|
| - |
|
608 |
crmServiceClient = CRMClient().get_client()
|
| - |
|
609 |
for order in tickets_tobe_created:
|
| - |
|
610 |
ticket_created = False
|
| - |
|
611 |
searchFilter = SearchFilter()
|
| - |
|
612 |
user = userClient.getUserByEmail(order.customer_email)
|
| - |
|
613 |
if user is None or user.userId == -1:
|
| - |
|
614 |
searchFilter.customerEmailId = order.customer_email
|
| - |
|
615 |
searchFilter.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
616 |
else:
|
| - |
|
617 |
searchFilter.customerId = user.userId
|
| - |
|
618 |
tickets = crmServiceClient.getTickets(searchFilter)
|
| - |
|
619 |
print tickets
|
| - |
|
620 |
for old_ticket in tickets:
|
| - |
|
621 |
if old_ticket.orderId == order.id:
|
| - |
|
622 |
ticket_created = True
|
| - |
|
623 |
break
|
| - |
|
624 |
if not ticket_created:
|
| - |
|
625 |
print "creating ticket for orderId:"+str(order.id)
|
| - |
|
626 |
ticket = Ticket()
|
| - |
|
627 |
activity = Activity()
|
| - |
|
628 |
description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
|
| - |
|
629 |
ticket.creatorId = 1
|
| - |
|
630 |
ticket.category = TicketCategory.DELIVERY_PROBLEM
|
| - |
|
631 |
ticket.priority = TicketPriority.HIGH
|
| - |
|
632 |
ticket.status = TicketStatus.OPEN
|
| - |
|
633 |
ticket.description = description
|
| - |
|
634 |
ticket.orderId = order.id
|
| - |
|
635 |
ticket.airwayBillNo = order.airwaybill_no
|
| - |
|
636 |
|
| - |
|
637 |
activity.creatorId = 1
|
| - |
|
638 |
activity.type = ActivityType.OTHER
|
| - |
|
639 |
activity.description = description
|
| - |
|
640 |
activity.ticketCategory = ticket.category
|
| - |
|
641 |
activity.ticketDescription = ticket.description
|
| - |
|
642 |
activity.ticketPriority = ticket.priority
|
| - |
|
643 |
activity.ticketStatus = ticket.status
|
| - |
|
644 |
|
| - |
|
645 |
if user is None or user.userId == -1:
|
| - |
|
646 |
ticket.customerEmailId = order.customer_email
|
| - |
|
647 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
648 |
ticket.customerName = order.customer_name
|
| - |
|
649 |
activity.customerEmailId = order.customer_email
|
| - |
|
650 |
activity.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
651 |
activity.customerName = order.customer_name
|
| - |
|
652 |
else:
|
| - |
|
653 |
ticket.customerId = user.userId
|
| - |
|
654 |
activity.customerId = user.userId
|
| - |
|
655 |
|
| - |
|
656 |
crmServiceClient.insertTicket(ticket, activity)
|
| - |
|
657 |
except:
|
| - |
|
658 |
print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
|
| - |
|
659 |
traceback.print_exc()
|
| - |
|
660 |
|
| 389 |
def get_py_datetime(datestring, timestring):
|
661 |
def get_py_datetime(datestring, timestring):
|
| 390 |
# This should be a command line argument.
|
662 |
# This should be a command line argument.
|
| 391 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
663 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
| 392 |
# get a complete list of format specifiers available for date time.
|
664 |
# get a complete list of format specifiers available for date time.
|
| 393 |
time_format = "%d-%b-%Y %H:%M:%S"
|
665 |
time_format = "%d-%b-%Y %H:%M:%S"
|
| Line 400... |
Line 672... |
| 400 |
timestring = timestring + ':00'
|
672 |
timestring = timestring + ':00'
|
| 401 |
time_string = datestring + ' ' + timestring
|
673 |
time_string = datestring + ' ' + timestring
|
| 402 |
mytime = time.strptime(time_string, time_format)
|
674 |
mytime = time.strptime(time_string, time_format)
|
| 403 |
return datetime.datetime(*mytime[:6])
|
675 |
return datetime.datetime(*mytime[:6])
|
| 404 |
|
676 |
|
| - |
|
677 |
def getTrimedString(text):
|
| - |
|
678 |
if text is None or text == '':
|
| - |
|
679 |
return ''
|
| - |
|
680 |
else:
|
| - |
|
681 |
text = text.strip().lower()
|
| - |
|
682 |
text_list = list(text)
|
| - |
|
683 |
new_text = ''
|
| - |
|
684 |
for letter in text_list:
|
| - |
|
685 |
if letter.isalnum():
|
| - |
|
686 |
new_text = new_text + str(letter)
|
| - |
|
687 |
return new_text
|
| - |
|
688 |
|
| 405 |
def main():
|
689 |
def main():
|
| 406 |
parser = optparse.OptionParser()
|
690 |
parser = optparse.OptionParser()
|
| 407 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
691 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
| 408 |
action="store_true",
|
692 |
action="store_true",
|
| 409 |
help="Run the pickup reconciliation")
|
693 |
help="Run the pickup reconciliation")
|
| 410 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
694 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
| 411 |
action="store_true",
|
695 |
action="store_true",
|
| 412 |
help="Run the delivery reconciliation")
|
696 |
help="Run the delivery reconciliation")
|
| - |
|
697 |
parser.add_option("-r", "--reports", dest="gen_reports",
|
| - |
|
698 |
action="store_true",
|
| - |
|
699 |
help="Generate logistic reconciliation reports")
|
| 413 |
parser.add_option("-a", "--all", dest="all_reports",
|
700 |
parser.add_option("-a", "--all", dest="all_reports",
|
| 414 |
action="store_true",
|
701 |
action="store_true",
|
| 415 |
help="Run all reconciliations")
|
702 |
help="Run all reconciliations")
|
| 416 |
parser.add_option("-P", "--provider", dest="provider",
|
703 |
parser.add_option("-P", "--provider", dest="provider",
|
| 417 |
default="BlueDart", type="string",
|
704 |
default="BlueDart", type="string",
|
| 418 |
help="The PROVIDER this report is for",
|
705 |
help="The PROVIDER this report is for",
|
| 419 |
metavar="PROVIDER")
|
706 |
metavar="PROVIDER")
|
| 420 |
parser.set_defaults(pickup_report=False, delivery_report=False, all_reports=False)
|
707 |
parser.set_defaults(pickup_report=False, delivery_report=False, gen_reports=False, all_reports=False)
|
| 421 |
(options, args) = parser.parse_args()
|
708 |
(options, args) = parser.parse_args()
|
| 422 |
if len(args) != 0:
|
709 |
if len(args) != 0:
|
| 423 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
710 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 424 |
|
711 |
|
| 425 |
if options.all_reports:
|
712 |
if options.all_reports:
|
| Line 431... |
Line 718... |
| 431 |
if options.pickup_report:
|
718 |
if options.pickup_report:
|
| 432 |
process_pickup_records(provider)
|
719 |
process_pickup_records(provider)
|
| 433 |
process_dao_pickup_orders(provider)
|
720 |
process_dao_pickup_orders(provider)
|
| 434 |
process_return_pickup_orders(provider)
|
721 |
process_return_pickup_orders(provider)
|
| 435 |
if options.delivery_report:
|
722 |
if options.delivery_report:
|
| - |
|
723 |
process_local_connection_orders(provider)
|
| - |
|
724 |
process_reached_destination_city_orders(provider)
|
| - |
|
725 |
process_first_delivery_attempt_orders(provider)
|
| 436 |
process_delivery_report(provider)
|
726 |
process_delivery_report(provider)
|
| - |
|
727 |
create_crm_tickets_for_delivey_attempted_orders(provider)
|
| - |
|
728 |
if options.gen_reports:
|
| - |
|
729 |
generate_reports(provider)
|
| 437 |
|
730 |
|
| 438 |
if __name__ == '__main__':
|
731 |
if __name__ == '__main__':
|
| 439 |
main()
|
732 |
main()
|