| 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 |
ARAMEX_URL = config_client.get_property("aramex_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, delivered_orders_but_wrong_code_mentioned, 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 |
if delivered_orders_but_wrong_code_mentioned:
|
- |
|
| 145 |
try:
|
- |
|
| 146 |
delivered_orders_but_wrong_code_mentioned_file = "/tmp/delivered_orders_but_wrong_code.csv"
|
- |
|
| 147 |
print_delivered_orders_but_wrong_code_mentioned_report(delivered_orders_but_wrong_code_mentioned_file, delivered_orders_but_wrong_code_mentioned)
|
- |
|
| 148 |
delivered_orders_but_wrong_code_mentioned_report = [get_attachment_part(delivered_orders_but_wrong_code_mentioned_file)]
|
- |
|
| 149 |
mail(from_user, from_pwd, to,\
|
- |
|
| 150 |
"Delivered Orders but Wrong Code Mentioned Report for " + provider.name,\
|
- |
|
| 151 |
"This is a system generated email.Please don't reply to it.",\
|
- |
|
| 152 |
delivered_orders_but_wrong_code_mentioned_report)
|
- |
|
| 153 |
except:
|
- |
|
| 154 |
print "Some issue sending the delivered orders but wrong code mentioned report"
|
- |
|
| 155 |
traceback.print_exc()
|
- |
|
| 156 |
try:
|
- |
|
| 157 |
orders_not_delivered = update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
132 |
update_reason_of_undelivered_orders(provider.id, undelivered_orders)
|
| 158 |
if orders_not_delivered:
|
- |
|
| 159 |
print "Undelivered Orders:"
|
- |
|
| 160 |
print orders_not_delivered
|
- |
|
| 161 |
mismatch_file = "/tmp/UndeliveredOrders.csv"
|
- |
|
| 162 |
print "Some of our Orders were not delivered. Printing report to:" + mismatch_file
|
- |
|
| 163 |
print_undelivered_orders_report(mismatch_file, orders_not_delivered)
|
- |
|
| 164 |
pickup_mismatch_part = [get_attachment_part(mismatch_file)]
|
- |
|
| 165 |
mail(from_user, from_pwd, to,\
|
- |
|
| 166 |
"Orders that are undelivered but picked up or shipped four days ago for " + provider.name,\
|
- |
|
| 167 |
"This is a system generated email.Please don't reply to it.",\
|
- |
|
| 168 |
pickup_mismatch_part)
|
- |
|
| 169 |
except Exception:
|
- |
|
| 170 |
print "Some issue updating and sending the undelivered orders report"
|
- |
|
| 171 |
traceback.print_exc()
|
- |
|
| 172 |
except:
|
133 |
except:
|
| 173 |
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"
|
| 174 |
traceback.print_exc()
|
281 |
traceback.print_exc()
|
| 175 |
|
282 |
|
| 176 |
def get_provider_by_name(provider_name):
|
283 |
def get_provider_by_name(provider_name):
|
| 177 |
logistics_client = LogisticsClient().get_client()
|
284 |
logistics_client = LogisticsClient().get_client()
|
| 178 |
provider = None
|
285 |
provider = None
|
| Line 183... |
Line 290... |
| 183 |
break
|
290 |
break
|
| 184 |
if provider == None:
|
291 |
if provider == None:
|
| 185 |
sys.exit("Can't continue execution: No such provider")
|
292 |
sys.exit("Can't continue execution: No such provider")
|
| 186 |
return provider
|
293 |
return provider
|
| 187 |
|
294 |
|
| 188 |
def fetch_data(provider_id, order_status):
|
295 |
def fetch_data(provider_id, order_status_list):
|
| 189 |
txnClient = TransactionClient().get_client()
|
296 |
txnClient = TransactionClient().get_client()
|
| 190 |
try:
|
297 |
try:
|
| 191 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status)
|
298 |
doas_tobe_picked_up = txnClient.getOrdersForProviderForStatus(provider_id, order_status_list)
|
| 192 |
return doas_tobe_picked_up
|
299 |
return doas_tobe_picked_up
|
| 193 |
except TransactionServiceException as tex:
|
300 |
except TransactionServiceException as tex:
|
| 194 |
print tex.message
|
301 |
print tex.message
|
| 195 |
|
302 |
|
| 196 |
def read_dao_return_pickup_orders(orders_tobe_picked_up):
|
303 |
def read_dao_return_pickup_orders(orders_tobe_picked_up):
|
| Line 199... |
Line 306... |
| 199 |
for order in orders_tobe_picked_up:
|
306 |
for order in orders_tobe_picked_up:
|
| 200 |
try:
|
307 |
try:
|
| 201 |
uri = 'http://www.aramex.com/track_xml.asp?ShipperRef=' + str(order.pickupRequestNo) + '&OrgCntry=In&FromDate=' + to_py_date(order.doa_auth_timestamp).strftime("%m-%d-%Y") +'&ToDate=' + datetime.date.today().strftime("%m-%d-%Y")
|
308 |
uri = 'http://www.aramex.com/track_xml.asp?ShipperRef=' + str(order.pickupRequestNo) + '&OrgCntry=In&FromDate=' + to_py_date(order.doa_auth_timestamp).strftime("%m-%d-%Y") +'&ToDate=' + datetime.date.today().strftime("%m-%d-%Y")
|
| 202 |
root = parse(urllib2.urlopen(uri)).getroot()
|
309 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 203 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
310 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| 204 |
if len(nodes):
|
- |
|
| 205 |
element = nodes[len(nodes)-1]
|
311 |
for element in reversed(nodes):
|
| 206 |
if element.findtext('Status', '') == 'SHOR' and element.findtext('Condition', '') == 'PKUP':
|
- |
|
| 207 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
312 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| 208 |
picked_up_orders[order.pickupRequestNo] = str(delivery_date)
|
313 |
picked_up_orders[order.pickupRequestNo] = str(delivery_date)
|
| - |
|
314 |
break
|
| 209 |
except:
|
315 |
except:
|
| 210 |
pass
|
316 |
pass
|
| 211 |
|
317 |
|
| 212 |
print "Picked up Orders:"
|
318 |
print "Picked up Orders:"
|
| 213 |
print picked_up_orders
|
319 |
print picked_up_orders
|
| 214 |
return picked_up_orders
|
320 |
return picked_up_orders
|
| 215 |
|
321 |
|
| 216 |
def read_pickup_orders(orders_tobe_picked_up):
|
322 |
def read_pickup_orders(orders_tobe_picked_up):
|
| 217 |
try:
|
- |
|
| 218 |
config_client = ConfigClient()
|
- |
|
| 219 |
ARAMEX_URL = config_client.get_property("aramex_update_url")
|
- |
|
| 220 |
except ConfigException as cex:
|
- |
|
| 221 |
print cex.message
|
- |
|
| 222 |
traceback.print_exc()
|
- |
|
| 223 |
|
- |
|
| 224 |
picked_up_orders = {}
|
323 |
picked_up_orders = {}
|
| 225 |
for order in orders_tobe_picked_up:
|
324 |
for order in orders_tobe_picked_up:
|
| 226 |
try:
|
325 |
try:
|
| 227 |
uri = ARAMEX_URL + order.airwaybill_no
|
326 |
uri = ARAMEX_URL + order.airwaybill_no
|
| 228 |
root = parse(urllib2.urlopen(uri)).getroot()
|
327 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 229 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
328 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| 230 |
if len(nodes):
|
- |
|
| 231 |
element = nodes[len(nodes)-1]
|
329 |
for element in reversed(nodes):
|
| 232 |
if element.findtext('Status', '') == 'SHOR' and element.findtext('Condition', '') == 'PKUP':
|
- |
|
| 233 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
330 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| 234 |
picked_up_orders[order.airwaybill_no] = str(delivery_date)
|
331 |
picked_up_orders[order.airwaybill_no] = str(delivery_date)
|
| - |
|
332 |
break
|
| 235 |
except:
|
333 |
except:
|
| 236 |
pass
|
334 |
pass
|
| 237 |
|
335 |
|
| 238 |
print "Picked up Orders:"
|
336 |
print "Picked up Orders:"
|
| 239 |
print picked_up_orders
|
337 |
print picked_up_orders
|
| 240 |
return picked_up_orders
|
338 |
return picked_up_orders
|
| 241 |
|
339 |
|
| 242 |
def read_delivery_orders(orders_tobe_delivered):
|
340 |
def read_local_connection_orders(orders_tobe_local_connected):
|
| - |
|
341 |
local_connected_orders = {}
|
| - |
|
342 |
for order in orders_tobe_local_connected:
|
| 243 |
try:
|
343 |
try:
|
| - |
|
344 |
uri = ARAMEX_URL + order.airwaybill_no
|
| - |
|
345 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| - |
|
346 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| 244 |
config_client = ConfigClient()
|
347 |
for element in reversed(nodes):
|
| - |
|
348 |
# For local delivery source city and destination city will be same
|
| - |
|
349 |
if root.findtext('HAWBDetails/HAWBOriginEntity', '') == root.findtext('HAWBDetails/HAWBDestEntity', '') and element.findtext('Status', '') == 'SHMF' and element.findtext('Condition', '') == 'MNOB':
|
| - |
|
350 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| 245 |
ARAMEX_URL = config_client.get_property("aramex_update_url")
|
351 |
local_connected_orders[order.airwaybill_no] = str(delivery_date)
|
| - |
|
352 |
break
|
| - |
|
353 |
# For outside delivery source city and destination city will be different, so checking for last scan at source city branch.
|
| 246 |
except ConfigException as cex:
|
354 |
elif root.findtext('HAWBDetails/HAWBOriginEntity', '') != root.findtext('HAWBDetails/HAWBDestEntity', '') and element.findtext('BranchID', '') == getOriginCityBranchID(root.findtext('HAWBDetails/HAWBOriginEntity', '')) and element.findtext('Status', '') == 'SHMF' and element.findtext('Condition', '') == 'MNOB':
|
| - |
|
355 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| - |
|
356 |
local_connected_orders[order.airwaybill_no] = str(delivery_date)
|
| 247 |
print cex.message
|
357 |
break
|
| 248 |
traceback.print_exc()
|
358 |
except:
|
| - |
|
359 |
pass
|
| - |
|
360 |
|
| - |
|
361 |
print "Local Connected Orders"
|
| - |
|
362 |
print local_connected_orders
|
| 249 |
|
363 |
|
| - |
|
364 |
return local_connected_orders
|
| - |
|
365 |
|
| - |
|
366 |
def read_reached_destination_orders(orders_tobe_reached_destination_city):
|
| - |
|
367 |
destination_city_reached_orders = {}
|
| - |
|
368 |
for order in orders_tobe_reached_destination_city:
|
| - |
|
369 |
try:
|
| - |
|
370 |
uri = ARAMEX_URL + order.airwaybill_no
|
| - |
|
371 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| - |
|
372 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| - |
|
373 |
for element in reversed(nodes):
|
| - |
|
374 |
if root.findtext('HAWBDetails/HAWBOriginEntity', '') == root.findtext('HAWBDetails/HAWBDestEntity', '') and element.findtext('UpdateEntity', '') == root.findtext('HAWBDetails/HAWBDestEntity', ''):
|
| - |
|
375 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| - |
|
376 |
destination_city_reached_orders[order.airwaybill_no] = str(delivery_date)
|
| - |
|
377 |
break
|
| - |
|
378 |
elif root.findtext('HAWBDetails/HAWBOriginEntity', '') != root.findtext('HAWBDetails/HAWBDestEntity', '') and element.findtext('UpdateEntity', '') == root.findtext('HAWBDetails/HAWBDestEntity', '') and element.findtext('Status', '') == 'SHIB' and element.findtext('Condition', '') == 'SHSC':
|
| - |
|
379 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| - |
|
380 |
destination_city_reached_orders[order.airwaybill_no] = str(delivery_date)
|
| - |
|
381 |
break
|
| - |
|
382 |
except:
|
| - |
|
383 |
pass
|
| - |
|
384 |
|
| - |
|
385 |
print "Destination City Reached Orders"
|
| - |
|
386 |
print destination_city_reached_orders
|
| - |
|
387 |
|
| - |
|
388 |
return destination_city_reached_orders
|
| - |
|
389 |
|
| - |
|
390 |
def read_first_delivery_attempt_orders(orders_tobe_first_delivery_attempted):
|
| - |
|
391 |
first_atdl_orders = {}
|
| - |
|
392 |
for order in orders_tobe_first_delivery_attempted:
|
| - |
|
393 |
try:
|
| - |
|
394 |
uri = ARAMEX_URL + order.airwaybill_no
|
| - |
|
395 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| - |
|
396 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| - |
|
397 |
for element in reversed(nodes):
|
| - |
|
398 |
if element.findtext('Status', '') == 'SHUD' and (element.findtext('Condition', '') == 'ATDL' or element.findtext('Condition', '') == 'CSCN'):
|
| - |
|
399 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| - |
|
400 |
reason_for_nondelivery = element.findtext('CustomerDescription', '')
|
| - |
|
401 |
first_atdl_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_nondelivery
|
| - |
|
402 |
break
|
| - |
|
403 |
except:
|
| - |
|
404 |
pass
|
| - |
|
405 |
|
| - |
|
406 |
print "FIRST DELIVERY ATTEMPT MADE Orders"
|
| - |
|
407 |
print first_atdl_orders
|
| - |
|
408 |
|
| - |
|
409 |
return first_atdl_orders
|
| - |
|
410 |
|
| - |
|
411 |
def read_delivery_orders(orders_tobe_delivered):
|
| 250 |
delivered_orders = {}
|
412 |
delivered_orders = {}
|
| 251 |
delivered_orders_but_wrong_code_mentioned = {}
|
- |
|
| 252 |
returned_orders = {}
|
413 |
returned_orders = {}
|
| 253 |
undelivered_orders = {}
|
414 |
undelivered_orders = {}
|
| 254 |
for order in orders_tobe_delivered:
|
415 |
for order in orders_tobe_delivered:
|
| 255 |
try:
|
416 |
try:
|
| 256 |
uri = ARAMEX_URL + order.airwaybill_no
|
417 |
uri = ARAMEX_URL + order.airwaybill_no
|
| 257 |
root = parse(urllib2.urlopen(uri)).getroot()
|
418 |
root = parse(urllib2.urlopen(uri)).getroot()
|
| 258 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
419 |
nodes = root.findall('HAWBDetails/HAWBHistory/HAWBUpdate')
|
| 259 |
if len(nodes):
|
- |
|
| 260 |
i = len(nodes)-1
|
420 |
node_number = len(nodes)-1
|
| 261 |
while i>=0:
|
- |
|
| 262 |
element = nodes[i]
|
421 |
for element in reversed(nodes):
|
| 263 |
if element.findtext('Status', '') == 'SHDL' and (element.findtext('Condition', '') == 'DLVD' or element.findtext('Condition', '') == 'DPTT' or element.findtext('Condition', '') == 'DLPT' or element.findtext('Condition', '') == 'LTRB'):
|
422 |
if element.findtext('Status', '') == 'SHDL' and (element.findtext('Condition', '') == 'DLVD' or element.findtext('Condition', '') == 'DPTT' or element.findtext('Condition', '') == 'DLPT' or element.findtext('Condition', '') == 'LTRB'):
|
| 264 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
423 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| 265 |
receiver = root.findtext('HAWBDetails/DeliveredTo', '')
|
424 |
receiver = root.findtext('HAWBDetails/DeliveredTo', '')
|
| 266 |
delivered_orders[order.airwaybill_no] = str(delivery_date) + "|" + receiver
|
425 |
delivered_orders[order.airwaybill_no] = str(delivery_date) + "|" + receiver
|
| 267 |
if element.findtext('Condition', '') != 'DLVD':
|
- |
|
| 268 |
delivered_orders_but_wrong_code_mentioned[order.airwaybill_no] = element.findtext('Condition', '')
|
- |
|
| 269 |
break
|
426 |
break
|
| 270 |
elif element.findtext('Condition', '') == 'RTRN' and (element.findtext('Status', '') == 'SHRH' or element.findtext('Status', '') == 'SHUP'):
|
427 |
elif element.findtext('Condition', '') == 'RTRN' and (element.findtext('Status', '') == 'SHRH' or element.findtext('Status', '') == 'SHUP'):
|
| 271 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
428 |
delivery_date = get_py_datetime(element.findtext('ActionDate', ''))
|
| 272 |
if i < len(nodes)-1:
|
429 |
if node_number < len(nodes)-1:
|
| 273 |
reason_for_return = nodes[i+1].findtext('CustomerDescription', '')
|
430 |
reason_for_return = nodes[node_number+1].findtext('CustomerDescription', '')
|
| 274 |
else:
|
431 |
else:
|
| 275 |
reason_for_return = element.findtext('CustomerDescription', '')
|
432 |
reason_for_return = element.findtext('CustomerDescription', '')
|
| 276 |
returned_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_return
|
433 |
returned_orders[order.airwaybill_no] = str(delivery_date) + "|" + reason_for_return
|
| 277 |
break
|
434 |
break
|
| 278 |
elif i == 0:
|
435 |
elif node_number == 0:
|
| 279 |
reason = root.findtext('HAWBDetails/CurrentStatus', '')
|
436 |
reason = root.findtext('HAWBDetails/CurrentStatus', '')
|
| 280 |
undelivered_orders[order.airwaybill_no] = reason
|
437 |
undelivered_orders[order.airwaybill_no] = reason
|
| 281 |
break
|
438 |
break
|
| 282 |
i = i-1
|
439 |
node_number = node_number - 1
|
| 283 |
except:
|
440 |
except:
|
| 284 |
pass
|
441 |
pass
|
| 285 |
|
442 |
|
| 286 |
print "Delivered Orders:"
|
443 |
print "Delivered Orders:"
|
| 287 |
print delivered_orders
|
444 |
print delivered_orders
|
| 288 |
|
445 |
|
| 289 |
print "Delivered Orders but wrong code mentioned:"
|
- |
|
| 290 |
print delivered_orders_but_wrong_code_mentioned
|
- |
|
| 291 |
|
- |
|
| 292 |
print "Returned Orders:"
|
446 |
print "Returned Orders:"
|
| 293 |
print returned_orders
|
447 |
print returned_orders
|
| 294 |
|
448 |
|
| 295 |
print "Undelivered Orders"
|
449 |
print "Undelivered Orders"
|
| 296 |
print undelivered_orders
|
450 |
print undelivered_orders
|
| 297 |
|
451 |
|
| 298 |
return delivered_orders, delivered_orders_but_wrong_code_mentioned, returned_orders, undelivered_orders
|
452 |
return delivered_orders, returned_orders, undelivered_orders
|
| 299 |
|
453 |
|
| 300 |
def update_picked_orders(provider_id, pickup_details):
|
454 |
def update_picked_orders(provider_id, pickup_details):
|
| 301 |
txnClient = TransactionClient().get_client()
|
455 |
txnClient = TransactionClient().get_client()
|
| 302 |
try:
|
456 |
try:
|
| 303 |
orders_not_picked_up = txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
|
457 |
txnClient.markOrdersAsPickedUp(provider_id, pickup_details)
|
| 304 |
return orders_not_picked_up
|
- |
|
| 305 |
except TransactionServiceException as tex:
|
458 |
except TransactionServiceException as tex:
|
| 306 |
print tex.message
|
459 |
print tex.message
|
| 307 |
|
460 |
|
| 308 |
def update_picked_doas(provider_id, doa_pickup_details):
|
461 |
def update_picked_doas(provider_id, doa_pickup_details):
|
| 309 |
txnClient = TransactionClient().get_client()
|
462 |
txnClient = TransactionClient().get_client()
|
| 310 |
try:
|
463 |
try:
|
| 311 |
doas_not_picked_up = txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
464 |
txnClient.markDoasAsPickedUp(provider_id, doa_pickup_details)
|
| 312 |
return doas_not_picked_up
|
- |
|
| 313 |
except TransactionServiceException as tex:
|
465 |
except TransactionServiceException as tex:
|
| 314 |
print tex.message
|
466 |
print tex.message
|
| 315 |
|
467 |
|
| 316 |
def update_picked_returns(provider_id, returns_pickup_details):
|
468 |
def update_picked_returns(provider_id, returns_pickup_details):
|
| 317 |
txnClient = TransactionClient().get_client()
|
469 |
txnClient = TransactionClient().get_client()
|
| 318 |
try:
|
470 |
try:
|
| 319 |
returns_not_picked_up = txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
471 |
txnClient.markReturnOrdersAsPickedUp(provider_id, returns_pickup_details)
|
| 320 |
return returns_not_picked_up
|
- |
|
| 321 |
except TransactionServiceException as tex:
|
472 |
except TransactionServiceException as tex:
|
| 322 |
print tex.message
|
473 |
print tex.message
|
| 323 |
|
474 |
|
| 324 |
def update_delivered_orders(provider_id, delivered_orders):
|
475 |
def update_delivered_orders(provider_id, delivered_orders):
|
| 325 |
txnClient = TransactionClient().get_client()
|
476 |
txnClient = TransactionClient().get_client()
|
| Line 329... |
Line 480... |
| 329 |
print tex.message
|
480 |
print tex.message
|
| 330 |
|
481 |
|
| 331 |
def update_returned_orders(provider_id, returned_orders):
|
482 |
def update_returned_orders(provider_id, returned_orders):
|
| 332 |
txnClient = TransactionClient().get_client()
|
483 |
txnClient = TransactionClient().get_client()
|
| 333 |
try:
|
484 |
try:
|
| 334 |
txnClient.markOrdersAsFailed(provider_id, returned_orders)
|
485 |
txnClient.markAsRTOrders(provider_id, returned_orders)
|
| 335 |
except TransactionServiceException as tex:
|
486 |
except TransactionServiceException as tex:
|
| 336 |
print tex.message
|
487 |
print tex.message
|
| 337 |
|
488 |
|
| 338 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
489 |
def update_reason_of_undelivered_orders(provider_id, undelivered_orders):
|
| 339 |
txnClient = TransactionClient().get_client()
|
490 |
txnClient = TransactionClient().get_client()
|
| 340 |
try:
|
491 |
try:
|
| 341 |
orders_not_delivered = txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
492 |
txnClient.updateNonDeliveryReason(provider_id, undelivered_orders)
|
| - |
|
493 |
except TransactionServiceException as tex:
|
| - |
|
494 |
print tex.message
|
| - |
|
495 |
|
| - |
|
496 |
def update_local_connected_orders(provider_id, local_connected_orders):
|
| - |
|
497 |
txnClient = TransactionClient().get_client()
|
| - |
|
498 |
try:
|
| - |
|
499 |
txnClient.markOrdersAsLocalConnected(provider_id, local_connected_orders)
|
| - |
|
500 |
except TransactionServiceException as tex:
|
| - |
|
501 |
print tex.message
|
| - |
|
502 |
|
| - |
|
503 |
def update_destination_city_reached_orders(provider_id, destination_city_reached_orders):
|
| - |
|
504 |
txnClient = TransactionClient().get_client()
|
| - |
|
505 |
try:
|
| - |
|
506 |
txnClient.markOrdersAsDestinationCityReached(provider_id, destination_city_reached_orders)
|
| - |
|
507 |
except TransactionServiceException as tex:
|
| 342 |
return orders_not_delivered
|
508 |
print tex.message
|
| - |
|
509 |
|
| - |
|
510 |
def update_first_atdl_orders(provider_id, first_atdl_orders):
|
| - |
|
511 |
txnClient = TransactionClient().get_client()
|
| - |
|
512 |
try:
|
| - |
|
513 |
txnClient.markOrdersAsFirstDeliveryAttempted(provider_id, first_atdl_orders)
|
| 343 |
except TransactionServiceException as tex:
|
514 |
except TransactionServiceException as tex:
|
| 344 |
print tex.message
|
515 |
print tex.message
|
| 345 |
|
516 |
|
| 346 |
def print_pickup_mismatch_report(filename, orders):
|
517 |
def print_pickup_mismatch_report(filename, orders):
|
| 347 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
518 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| Line 353... |
Line 524... |
| 353 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
524 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 354 |
writer.writerow(['Order Id', 'Pickup Request No', 'Authorization timestamp'])
|
525 |
writer.writerow(['Order Id', 'Pickup Request No', 'Authorization timestamp'])
|
| 355 |
for order in orders:
|
526 |
for order in orders:
|
| 356 |
writer.writerow([order.id, order.pickupRequestNo, to_py_date(order.doa_auth_timestamp)])
|
527 |
writer.writerow([order.id, order.pickupRequestNo, to_py_date(order.doa_auth_timestamp)])
|
| 357 |
|
528 |
|
| 358 |
def print_rto_orders_report(filename, returned_orders):
|
529 |
def print_rto_orders_report(filename, orders):
|
| 359 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
530 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 360 |
writer.writerow(['AWB No', 'Return date', 'Reason'])
|
531 |
writer.writerow(['Order Id', 'AWB No', 'Return date', 'Reason'])
|
| 361 |
for awb, date_reason in returned_orders.iteritems():
|
532 |
for order in orders:
|
| 362 |
date, reason = date_reason.split('|')
|
533 |
statusDescription = ''
|
| 363 |
if reason is not None:
|
534 |
if order.statusDescription is not None:
|
| 364 |
reason = reason.replace(","," ")
|
535 |
statusDescription = order.statusDescription.replace(","," ")
|
| 365 |
writer.writerow([awb, date, reason])
|
- |
|
| 366 |
|
- |
|
| 367 |
def print_delivered_orders_but_wrong_code_mentioned_report(filename, delivered_orders_but_wrong_code_mentioned):
|
536 |
writer.writerow([order.id, order.airwaybill_no, to_py_date(order.delivery_timestamp), statusDescription])
|
| 368 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
- |
|
| 369 |
writer.writerow(['AWB No', 'Code Used'])
|
- |
|
| 370 |
for awb, code_used in delivered_orders_but_wrong_code_mentioned.iteritems():
|
- |
|
| 371 |
writer.writerow([awb, code_used])
|
- |
|
| 372 |
|
537 |
|
| 373 |
def print_undelivered_orders_report(filename, orders):
|
538 |
def print_undelivered_orders_report(filename, orders):
|
| 374 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
539 |
writer = csv.writer(open(filename, "wb"), delimiter=',', quoting=csv.QUOTE_NONE)
|
| 375 |
writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp'])
|
540 |
writer.writerow(['Order Id', 'AWB No', 'Status', 'Status Description', 'Shipping timestamp', 'Pickup timestamp'])
|
| 376 |
for order in orders:
|
541 |
for order in orders:
|
| 377 |
statusDescription = ''
|
542 |
statusDescription = ''
|
| 378 |
if order.statusDescription is not None:
|
543 |
if order.statusDescription is not None:
|
| 379 |
statusDescription = order.statusDescription.replace(","," ")
|
544 |
statusDescription = order.statusDescription.replace(","," ")
|
| 380 |
writer.writerow([order.id, order.airwaybill_no, order.status, statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp)])
|
545 |
writer.writerow([order.id, order.airwaybill_no, order.status, statusDescription, to_py_date(order.shipping_timestamp), to_py_date(order.pickup_timestamp)])
|
| 381 |
|
546 |
|
| - |
|
547 |
def create_crm_tickets_for_delivey_attempted_orders(provider):
|
| - |
|
548 |
try:
|
| - |
|
549 |
tickets_tobe_created = fetch_data(provider.id, [OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE])
|
| - |
|
550 |
userClient = UserClient().get_client()
|
| - |
|
551 |
crmServiceClient = CRMClient().get_client()
|
| - |
|
552 |
for order in tickets_tobe_created:
|
| - |
|
553 |
ticket_created = False
|
| - |
|
554 |
searchFilter = SearchFilter()
|
| - |
|
555 |
user = userClient.getUserByEmail(order.customer_email)
|
| - |
|
556 |
if user is None or user.userId == -1:
|
| - |
|
557 |
searchFilter.customerEmailId = order.customer_email
|
| - |
|
558 |
searchFilter.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
559 |
else:
|
| - |
|
560 |
searchFilter.customerId = user.userId
|
| - |
|
561 |
tickets = crmServiceClient.getTickets(searchFilter)
|
| - |
|
562 |
print tickets
|
| - |
|
563 |
for old_ticket in tickets:
|
| - |
|
564 |
if old_ticket.orderId == order.id:
|
| - |
|
565 |
ticket_created = True
|
| - |
|
566 |
break
|
| - |
|
567 |
if not ticket_created:
|
| - |
|
568 |
print "creating ticket for orderId:"+str(order.id)
|
| - |
|
569 |
ticket = Ticket()
|
| - |
|
570 |
activity = Activity()
|
| - |
|
571 |
description = order.statusDescription + "\n\nOrder not delivered by courier due to problems at customer end."
|
| - |
|
572 |
ticket.creatorId = 1
|
| - |
|
573 |
ticket.category = TicketCategory.DELIVERY_PROBLEM
|
| - |
|
574 |
ticket.priority = TicketPriority.HIGH
|
| - |
|
575 |
ticket.status = TicketStatus.OPEN
|
| - |
|
576 |
ticket.description = description
|
| - |
|
577 |
ticket.orderId = order.id
|
| - |
|
578 |
ticket.airwayBillNo = order.airwaybill_no
|
| - |
|
579 |
|
| - |
|
580 |
activity.creatorId = 1
|
| - |
|
581 |
activity.type = ActivityType.OTHER
|
| - |
|
582 |
activity.description = description
|
| - |
|
583 |
activity.ticketCategory = ticket.category
|
| - |
|
584 |
activity.ticketDescription = ticket.description
|
| - |
|
585 |
activity.ticketPriority = ticket.priority
|
| - |
|
586 |
activity.ticketStatus = ticket.status
|
| - |
|
587 |
|
| - |
|
588 |
if user is None or user.userId == -1:
|
| - |
|
589 |
ticket.customerEmailId = order.customer_email
|
| - |
|
590 |
ticket.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
591 |
ticket.customerName = order.customer_name
|
| - |
|
592 |
activity.customerEmailId = order.customer_email
|
| - |
|
593 |
activity.customerMobileNumber = order.customer_mobilenumber
|
| - |
|
594 |
activity.customerName = order.customer_name
|
| - |
|
595 |
else:
|
| - |
|
596 |
ticket.customerId = user.userId
|
| - |
|
597 |
activity.customerId = user.userId
|
| - |
|
598 |
|
| - |
|
599 |
crmServiceClient.insertTicket(ticket, activity)
|
| - |
|
600 |
except:
|
| - |
|
601 |
print "Some issue while creating crm tickets for orders in FIRST_DELIVERY_ATTEMPT_MADE status"
|
| - |
|
602 |
traceback.print_exc()
|
| - |
|
603 |
|
| 382 |
def get_py_datetime(time_string):
|
604 |
def get_py_datetime(time_string):
|
| 383 |
# This should be a command line argument.
|
605 |
# This should be a command line argument.
|
| 384 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
606 |
# Refer http://docs.python.org/library/time.html#time.strftime to
|
| 385 |
# get a complete list of format specifiers available for date time.
|
607 |
# get a complete list of format specifiers available for date time.
|
| 386 |
time_format = "%m/%d/%Y %I:%M:%S %p"
|
608 |
time_format = "%m/%d/%Y %I:%M:%S %p"
|
| 387 |
if time_string == '':
|
609 |
if time_string == '':
|
| 388 |
return None
|
610 |
return None
|
| 389 |
mytime = time.strptime(time_string, time_format)
|
611 |
mytime = time.strptime(time_string, time_format)
|
| 390 |
return datetime.datetime(*mytime[:6])
|
612 |
return datetime.datetime(*mytime[:6])
|
| 391 |
|
613 |
|
| - |
|
614 |
def getOriginCityBranchID(originCity):
|
| - |
|
615 |
branchId_OriginCitymap = {'DEL':'7933'}
|
| - |
|
616 |
if originCity is None or originCity == '':
|
| - |
|
617 |
return ''
|
| - |
|
618 |
else:
|
| - |
|
619 |
return branchId_OriginCitymap.get(originCity)
|
| - |
|
620 |
|
| 392 |
def main():
|
621 |
def main():
|
| 393 |
parser = optparse.OptionParser()
|
622 |
parser = optparse.OptionParser()
|
| 394 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
623 |
parser.add_option("-p", "--pickup", dest="pickup_report",
|
| 395 |
action="store_true",
|
624 |
action="store_true",
|
| 396 |
help="Run the pickup reconciliation")
|
625 |
help="Run the pickup reconciliation")
|
| 397 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
626 |
parser.add_option("-d", "--delivery", dest="delivery_report",
|
| 398 |
action="store_true",
|
627 |
action="store_true",
|
| 399 |
help="Run the delivery reconciliation")
|
628 |
help="Run the delivery reconciliation")
|
| - |
|
629 |
parser.add_option("-r", "--reports", dest="gen_reports",
|
| - |
|
630 |
action="store_true",
|
| - |
|
631 |
help="Generate logistic reconciliation reports")
|
| 400 |
parser.add_option("-a", "--all", dest="all_reports",
|
632 |
parser.add_option("-a", "--all", dest="all_reports",
|
| 401 |
action="store_true",
|
633 |
action="store_true",
|
| 402 |
help="Run all reconciliations")
|
634 |
help="Run all reconciliations")
|
| 403 |
parser.add_option("-P", "--provider", dest="provider",
|
635 |
parser.add_option("-P", "--provider", dest="provider",
|
| 404 |
default="Aramex", type="string",
|
636 |
default="Aramex", type="string",
|
| 405 |
help="The PROVIDER this report is for",
|
637 |
help="The PROVIDER this report is for",
|
| 406 |
metavar="PROVIDER")
|
638 |
metavar="PROVIDER")
|
| 407 |
parser.set_defaults(pickup_report=False, delivery_report=False, all_reports=False)
|
639 |
parser.set_defaults(pickup_report=False, delivery_report=False, gen_reports=False, all_reports=False)
|
| 408 |
(options, args) = parser.parse_args()
|
640 |
(options, args) = parser.parse_args()
|
| 409 |
if len(args) != 0:
|
641 |
if len(args) != 0:
|
| 410 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
642 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| 411 |
|
643 |
|
| 412 |
if options.all_reports:
|
644 |
if options.all_reports:
|
| Line 418... |
Line 650... |
| 418 |
if options.pickup_report:
|
650 |
if options.pickup_report:
|
| 419 |
process_pickup_records(provider)
|
651 |
process_pickup_records(provider)
|
| 420 |
process_dao_pickup_orders(provider)
|
652 |
process_dao_pickup_orders(provider)
|
| 421 |
process_return_pickup_orders(provider)
|
653 |
process_return_pickup_orders(provider)
|
| 422 |
if options.delivery_report:
|
654 |
if options.delivery_report:
|
| - |
|
655 |
process_local_connection_orders(provider)
|
| - |
|
656 |
process_reached_destination_city_orders(provider)
|
| - |
|
657 |
process_first_delivery_attempt_orders(provider)
|
| 423 |
process_delivery_report(provider)
|
658 |
process_delivery_report(provider)
|
| - |
|
659 |
create_crm_tickets_for_delivey_attempted_orders(provider)
|
| - |
|
660 |
if options.gen_reports:
|
| - |
|
661 |
generate_reports(provider)
|
| 424 |
|
662 |
|
| 425 |
if __name__ == '__main__':
|
663 |
if __name__ == '__main__':
|
| 426 |
main()
|
664 |
main()
|