| 4607 |
rajveer |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
'''
|
|
|
4 |
Creates a CSV report of all the shipped orders and send mail to Sandeep.
|
|
|
5 |
|
|
|
6 |
Created on 20-Feb-2012
|
|
|
7 |
|
|
|
8 |
@author: Rajveer
|
|
|
9 |
'''
|
|
|
10 |
import xlwt
|
|
|
11 |
import datetime
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
if __name__ == '__main__' and __package__ is None:
|
|
|
16 |
import sys
|
|
|
17 |
import os
|
|
|
18 |
sys.path.insert(0, os.getcwd())
|
|
|
19 |
|
|
|
20 |
from shop2020.utils.Utils import to_py_date
|
|
|
21 |
from shop2020.clients.TransactionClient import TransactionClient
|
|
|
22 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus, Order
|
|
|
23 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
|
|
24 |
|
|
|
25 |
def main():
|
|
|
26 |
txn_client = TransactionClient().get_client()
|
|
|
27 |
slipped_orders = txn_client.getSlippedSippingDateOrders()
|
|
|
28 |
|
|
|
29 |
wbk = xlwt.Workbook()
|
|
|
30 |
sheet = wbk.add_sheet('main')
|
|
|
31 |
|
|
|
32 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
|
|
|
33 |
sheet.set_panes_frozen(True)
|
|
|
34 |
sheet.set_horz_split_pos(1)
|
|
|
35 |
sheet.set_remove_splits(True)
|
|
|
36 |
|
|
|
37 |
excel_integer_format = '0'
|
|
|
38 |
integer_style = xlwt.XFStyle()
|
|
|
39 |
integer_style.num_format_str = excel_integer_format
|
|
|
40 |
|
|
|
41 |
date_style = xlwt.XFStyle()
|
|
|
42 |
date_style.num_format_str = "M/D/YY"
|
|
|
43 |
|
|
|
44 |
sheet.write(0, 0, "Order ID", heading_xf)
|
|
|
45 |
sheet.write(0, 1, "Mode.", heading_xf)
|
|
|
46 |
sheet.write(0, 2, "Brand", heading_xf)
|
|
|
47 |
sheet.write(0, 3, "Model Name", heading_xf)
|
|
|
48 |
sheet.write(0, 4, "Model Number", heading_xf)
|
|
|
49 |
sheet.write(0, 5, "Color", heading_xf)
|
|
|
50 |
sheet.write(0, 6, "Creation Date", heading_xf)
|
|
|
51 |
sheet.write(0, 7, "Promised Shipping Date", heading_xf)
|
|
|
52 |
sheet.write(0, 8, "Expected Shipping Date", heading_xf)
|
|
|
53 |
sheet.write(0, 9, "Delay Reason", heading_xf)
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
order = Order()
|
|
|
57 |
mode = {}
|
|
|
58 |
mode[0] = 'Prepaid'
|
|
|
59 |
mode[1] = 'COD'
|
|
|
60 |
|
|
|
61 |
i = 1
|
|
|
62 |
for order in slipped_orders:
|
|
|
63 |
sheet.write(i, 0, order.id)
|
|
|
64 |
sheet.write(i, 1, mode[order.cod])
|
|
|
65 |
|
|
|
66 |
lineitem = order.lineitems[0]
|
|
|
67 |
sheet.write(i, 2, lineitem.brand)
|
|
|
68 |
sheet.write(i, 3, lineitem.model_name)
|
|
|
69 |
sheet.write(i, 4, lineitem.model_number)
|
|
|
70 |
sheet.write(i, 5, lineitem.color)
|
|
|
71 |
|
|
|
72 |
sheet.write(i, 6, to_py_date(order.created_timestamp), date_style)
|
|
|
73 |
sheet.write(i, 7, to_py_date(order.promised_shipping_time), date_style)
|
|
|
74 |
sheet.write(i, 8, to_py_date(order.expected_shipping_time), date_style)
|
|
|
75 |
sheet.write(i, 9, order.delayReason)
|
|
|
76 |
|
|
|
77 |
i= i+1
|
|
|
78 |
|
|
|
79 |
today = datetime.date.today()
|
|
|
80 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
|
|
81 |
filename = "/tmp/SlippedOrders-" + datestr + ".xls"
|
|
|
82 |
wbk.save(filename)
|
|
|
83 |
|
|
|
84 |
try:
|
|
|
85 |
part = get_attachment_part(filename)
|
|
|
86 |
mail("cnc.center@shop2020.in", "5h0p2o2o", ["sandeep.sachdeva@shop2020.in","suraj.sharma@shop2020.in","pankaj.jain@spiceglobal.com", "pankaj.kankar@shop2020.in"], "Slipped Orders as on: " + datestr, "PFA attached xls files for the orders which missed the shipping date.", [part])
|
|
|
87 |
finally:
|
|
|
88 |
os.remove(filename)
|
|
|
89 |
|
|
|
90 |
if __name__ == '__main__':
|
|
|
91 |
main()
|