| Line 18... |
Line 18... |
| 18 |
import os
|
18 |
import os
|
| 19 |
sys.path.insert(0, os.getcwd())
|
19 |
sys.path.insert(0, os.getcwd())
|
| 20 |
|
20 |
|
| 21 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
21 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 22 |
from shop2020.clients.TransactionClient import TransactionClient
|
22 |
from shop2020.clients.TransactionClient import TransactionClient
|
| - |
|
23 |
from shop2020.clients.LogisticsClient import LogisticsClient
|
| - |
|
24 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 23 |
from shop2020.thriftpy.model.v1.order.ttypes import Order, DelayReason
|
25 |
from shop2020.thriftpy.model.v1.order.ttypes import Order, DelayReason
|
| 24 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
26 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 25 |
|
27 |
|
| 26 |
def generate_delayed_orders_file():
|
28 |
def generate_delayed_orders_file():
|
| 27 |
txn_client = TransactionClient().get_client()
|
29 |
txn_client = TransactionClient().get_client()
|
| Line 154... |
Line 156... |
| 154 |
try:
|
156 |
try:
|
| 155 |
part = get_attachment_part(filename)
|
157 |
part = get_attachment_part(filename)
|
| 156 |
mail("cnc.center@shop2020.in", "5h0p2o2o", ["sandeep.sachdeva@shop2020.in","suraj.sharma@shop2020.in","pankaj.jain@spiceglobal.com", "pankaj.kankar@shop2020.in", "chaitnaya.vats@shop2020.in"], "Low Inventory Cancelled Orders as on: " + datestr, "PFA attached xls files for the orders which has been cancelled.", [part])
|
158 |
mail("cnc.center@shop2020.in", "5h0p2o2o", ["sandeep.sachdeva@shop2020.in","suraj.sharma@shop2020.in","pankaj.jain@spiceglobal.com", "pankaj.kankar@shop2020.in", "chaitnaya.vats@shop2020.in"], "Low Inventory Cancelled Orders as on: " + datestr, "PFA attached xls files for the orders which has been cancelled.", [part])
|
| 157 |
finally:
|
159 |
finally:
|
| 158 |
os.remove(filename)
|
160 |
os.remove(filename)
|
| - |
|
161 |
|
| - |
|
162 |
def generate_expected_delivery_missed_orders_file():
|
| - |
|
163 |
to = ["sandeep.sachdeva@shop2020.in","suraj.sharma@shop2020.in","pankaj.jain@spiceglobal.com", "pankaj.kankar@shop2020.in", "chaitnaya.vats@shop2020.in"]
|
| - |
|
164 |
|
| - |
|
165 |
txn_client = TransactionClient().get_client()
|
| - |
|
166 |
orders_not_delivered = txn_client.getUndeliveredOrdersExpectedDeliveryDateNotMet()
|
| - |
|
167 |
|
| - |
|
168 |
print "orders_not_delivered"
|
| - |
|
169 |
print orders_not_delivered
|
| - |
|
170 |
|
| - |
|
171 |
logistics_client = LogisticsClient().get_client()
|
| - |
|
172 |
providers = logistics_client.getAllProviders()
|
| - |
|
173 |
providers_map = {}
|
| - |
|
174 |
for provider in providers:
|
| - |
|
175 |
providers_map[provider.id] = provider.name
|
| - |
|
176 |
|
| - |
|
177 |
catalog_client = CatalogClient().get_client()
|
| - |
|
178 |
warehouses = catalog_client.getAllWarehouses(True)
|
| - |
|
179 |
warehouses_map = {}
|
| - |
|
180 |
for warehouse in warehouses:
|
| - |
|
181 |
warehouses_map[warehouse.id] = warehouse.displayName
|
| - |
|
182 |
|
| - |
|
183 |
wbk = xlwt.Workbook()
|
| - |
|
184 |
sheet = wbk.add_sheet('main')
|
| - |
|
185 |
|
| - |
|
186 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
|
| - |
|
187 |
sheet.set_panes_frozen(True)
|
| - |
|
188 |
sheet.set_horz_split_pos(1)
|
| - |
|
189 |
sheet.set_remove_splits(True)
|
| - |
|
190 |
|
| - |
|
191 |
excel_integer_format = '0'
|
| - |
|
192 |
integer_style = xlwt.XFStyle()
|
| - |
|
193 |
integer_style.num_format_str = excel_integer_format
|
| - |
|
194 |
|
| - |
|
195 |
date_style = xlwt.XFStyle()
|
| - |
|
196 |
date_style.num_format_str = "M/D/YY"
|
| - |
|
197 |
|
| - |
|
198 |
sheet.write(0, 0, "Order ID", heading_xf)
|
| - |
|
199 |
sheet.write(0, 1, "Mode.", heading_xf)
|
| - |
|
200 |
sheet.write(0, 2, "Airway BillNo", heading_xf)
|
| - |
|
201 |
sheet.write(0, 3, "Current Status", heading_xf)
|
| - |
|
202 |
sheet.write(0, 4, "Shipping Date", heading_xf)
|
| - |
|
203 |
sheet.write(0, 5, "Pickup Date", heading_xf)
|
| - |
|
204 |
sheet.write(0, 6, "Expected Delivery Date", heading_xf)
|
| - |
|
205 |
sheet.write(0, 7, "Warehouse", heading_xf)
|
| - |
|
206 |
sheet.write(0, 8, "Warehouse ID", heading_xf)
|
| - |
|
207 |
sheet.write(0, 9, "Logistics Provider", heading_xf)
|
| - |
|
208 |
sheet.write(0, 10, "Logistics Provider ID", heading_xf)
|
| - |
|
209 |
sheet.write(0, 11, "Customer City", heading_xf)
|
| - |
|
210 |
sheet.write(0, 12, "Customer State", heading_xf)
|
| - |
|
211 |
sheet.write(0, 13, "Customer Pincode", heading_xf)
|
| - |
|
212 |
|
| - |
|
213 |
order = Order()
|
| - |
|
214 |
mode = {}
|
| - |
|
215 |
mode[0] = 'Prepaid'
|
| - |
|
216 |
mode[1] = 'COD'
|
| - |
|
217 |
|
| - |
|
218 |
i = 1
|
| - |
|
219 |
for order in orders_not_delivered:
|
| - |
|
220 |
sheet.write(i, 0, order.id)
|
| - |
|
221 |
sheet.write(i, 1, mode[order.cod])
|
| - |
|
222 |
sheet.write(i, 2, order.airwaybill_no)
|
| - |
|
223 |
sheet.write(i, 3, order.statusDescription)
|
| - |
|
224 |
sheet.write(i, 4, to_py_date(order.shipping_timestamp), date_style)
|
| - |
|
225 |
sheet.write(i, 5, to_py_date(order.pickup_timestamp), date_style)
|
| - |
|
226 |
sheet.write(i, 6, to_py_date(order.expected_delivery_time), date_style)
|
| - |
|
227 |
sheet.write(i, 7, warehouses_map.get(order.warehouse_id))
|
| - |
|
228 |
sheet.write(i, 8, order.warehouse_id)
|
| - |
|
229 |
sheet.write(i, 9, providers_map.get(order.logistics_provider_id))
|
| - |
|
230 |
sheet.write(i, 10, order.logistics_provider_id)
|
| - |
|
231 |
sheet.write(i, 11, order.customer_city)
|
| - |
|
232 |
sheet.write(i, 12, order.customer_state)
|
| - |
|
233 |
sheet.write(i, 13, order.customer_pincode)
|
| 159 |
|
234 |
|
| - |
|
235 |
i= i+1
|
| - |
|
236 |
|
| - |
|
237 |
today = datetime.date.today()
|
| - |
|
238 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
| - |
|
239 |
filename = "/tmp/UndeliveredOrders-" + datestr + ".xls"
|
| - |
|
240 |
wbk.save(filename)
|
| - |
|
241 |
|
| - |
|
242 |
try:
|
| - |
|
243 |
part = get_attachment_part(filename)
|
| - |
|
244 |
mail("cnc.center@shop2020.in", "5h0p2o2o", to, "Orders which missed Expected Delivery Date as on: " + datestr, "PFA attached xls files for the orders which missed the Expected Delivery Date.", [part])
|
| - |
|
245 |
finally:
|
| - |
|
246 |
os.remove(filename)
|
| - |
|
247 |
|
| 160 |
def main():
|
248 |
def main():
|
| 161 |
parser = OptionParser()
|
249 |
parser = OptionParser()
|
| 162 |
parser.add_option("-d", "--delayed", dest="delayed",
|
250 |
parser.add_option("-d", "--delayed", dest="delayed",
|
| 163 |
action="store_true",
|
251 |
action="store_true",
|
| 164 |
help="")
|
252 |
help="")
|
| 165 |
parser.add_option("-c", "--cancelled", dest="cancelled",
|
253 |
parser.add_option("-c", "--cancelled", dest="cancelled",
|
| 166 |
action="store_true",
|
254 |
action="store_true",
|
| 167 |
help="")
|
255 |
help="")
|
| - |
|
256 |
parser.add_option("-u", "--undelivered", dest="undelivered",
|
| - |
|
257 |
action="store_true",
|
| - |
|
258 |
help="")
|
| 168 |
|
259 |
|
| 169 |
(options, args) = parser.parse_args()
|
260 |
(options, args) = parser.parse_args()
|
| 170 |
if options.delayed:
|
261 |
if options.delayed:
|
| 171 |
generate_delayed_orders_file()
|
262 |
generate_delayed_orders_file()
|
| 172 |
if options.cancelled:
|
263 |
if options.cancelled:
|
| 173 |
generate_cancelled_orders_file()
|
264 |
generate_cancelled_orders_file()
|
| 174 |
|
265 |
if options.undelivered:
|
| - |
|
266 |
generate_expected_delivery_missed_orders_file()
|
| - |
|
267 |
|
| 175 |
if __name__ == '__main__':
|
268 |
if __name__ == '__main__':
|
| 176 |
main()
|
269 |
main()
|
| 177 |
|
270 |
|