| Line 7... |
Line 7... |
| 7 |
|
7 |
|
| 8 |
@author: Rajveer
|
8 |
@author: Rajveer
|
| 9 |
'''
|
9 |
'''
|
| 10 |
import xlwt
|
10 |
import xlwt
|
| 11 |
import datetime
|
11 |
import datetime
|
| - |
|
12 |
from optparse import OptionParser
|
| 12 |
|
13 |
|
| 13 |
|
14 |
|
| 14 |
|
15 |
|
| 15 |
if __name__ == '__main__' and __package__ is None:
|
16 |
if __name__ == '__main__' and __package__ is None:
|
| 16 |
import sys
|
17 |
import sys
|
| 17 |
import os
|
18 |
import os
|
| 18 |
sys.path.insert(0, os.getcwd())
|
19 |
sys.path.insert(0, os.getcwd())
|
| 19 |
|
20 |
|
| 20 |
from shop2020.utils.Utils import to_py_date
|
21 |
from shop2020.utils.Utils import to_py_date, to_java_date
|
| 21 |
from shop2020.clients.TransactionClient import TransactionClient
|
22 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 22 |
from shop2020.thriftpy.model.v1.order.ttypes import Order, DelayReason
|
23 |
from shop2020.thriftpy.model.v1.order.ttypes import Order, DelayReason
|
| 23 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
24 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| 24 |
|
25 |
|
| 25 |
def main():
|
26 |
def generate_delayed_orders_file():
|
| 26 |
txn_client = TransactionClient().get_client()
|
27 |
txn_client = TransactionClient().get_client()
|
| 27 |
slipped_orders = txn_client.getSlippedSippingDateOrders()
|
28 |
slipped_orders = txn_client.getSlippedSippingDateOrders()
|
| 28 |
|
29 |
|
| 29 |
wbk = xlwt.Workbook()
|
30 |
wbk = xlwt.Workbook()
|
| 30 |
sheet = wbk.add_sheet('main')
|
31 |
sheet = wbk.add_sheet('main')
|
| Line 87... |
Line 88... |
| 87 |
part = get_attachment_part(filename)
|
88 |
part = get_attachment_part(filename)
|
| 88 |
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"], "Slipped Orders as on: " + datestr, "PFA attached xls files for the orders which missed the shipping date.", [part])
|
89 |
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"], "Slipped Orders as on: " + datestr, "PFA attached xls files for the orders which missed the shipping date.", [part])
|
| 89 |
finally:
|
90 |
finally:
|
| 90 |
os.remove(filename)
|
91 |
os.remove(filename)
|
| 91 |
|
92 |
|
| - |
|
93 |
def generate_cancelled_orders_file():
|
| - |
|
94 |
txn_client = TransactionClient().get_client()
|
| - |
|
95 |
#cancelled_orders = txn_client.getAllOrders(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY, to_java_date(datetime.datetime.now() - datetime.timedelta(hours = 24)), to_java_date(datetime.datetime.now()), -1)
|
| - |
|
96 |
cancelled_orders = txn_client.getCancelledOrders(to_java_date(datetime.datetime.now() - datetime.timedelta(hours = 24)), to_java_date(datetime.datetime.now()))
|
| - |
|
97 |
|
| - |
|
98 |
wbk = xlwt.Workbook()
|
| - |
|
99 |
sheet = wbk.add_sheet('main')
|
| - |
|
100 |
|
| - |
|
101 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
|
| - |
|
102 |
sheet.set_panes_frozen(True)
|
| - |
|
103 |
sheet.set_horz_split_pos(1)
|
| - |
|
104 |
sheet.set_remove_splits(True)
|
| - |
|
105 |
|
| - |
|
106 |
excel_integer_format = '0'
|
| - |
|
107 |
integer_style = xlwt.XFStyle()
|
| - |
|
108 |
integer_style.num_format_str = excel_integer_format
|
| - |
|
109 |
|
| - |
|
110 |
date_style = xlwt.XFStyle()
|
| - |
|
111 |
date_style.num_format_str = "M/D/YY"
|
| - |
|
112 |
|
| - |
|
113 |
sheet.write(0, 0, "Order ID", heading_xf)
|
| - |
|
114 |
sheet.write(0, 1, "Mode.", heading_xf)
|
| - |
|
115 |
sheet.write(0, 2, "Brand", heading_xf)
|
| - |
|
116 |
sheet.write(0, 3, "Model Name", heading_xf)
|
| - |
|
117 |
sheet.write(0, 4, "Model Number", heading_xf)
|
| - |
|
118 |
sheet.write(0, 5, "Color", heading_xf)
|
| - |
|
119 |
sheet.write(0, 6, "Creation Date", heading_xf)
|
| - |
|
120 |
sheet.write(0, 7, "Promised Shipping Date", heading_xf)
|
| - |
|
121 |
sheet.write(0, 8, "Expected Shipping Date", heading_xf)
|
| - |
|
122 |
sheet.write(0, 9, "Cancellation Reason", heading_xf)
|
| - |
|
123 |
sheet.write(0, 10, "Cancellation Date", heading_xf)
|
| - |
|
124 |
|
| - |
|
125 |
order = Order()
|
| - |
|
126 |
mode = {}
|
| - |
|
127 |
mode[0] = 'Prepaid'
|
| - |
|
128 |
mode[1] = 'COD'
|
| - |
|
129 |
|
| - |
|
130 |
i = 1
|
| - |
|
131 |
for order in cancelled_orders:
|
| - |
|
132 |
sheet.write(i, 0, order.id)
|
| - |
|
133 |
sheet.write(i, 1, mode[order.cod])
|
| - |
|
134 |
|
| - |
|
135 |
lineitem = order.lineitems[0]
|
| - |
|
136 |
sheet.write(i, 2, lineitem.brand)
|
| - |
|
137 |
sheet.write(i, 3, lineitem.model_name)
|
| - |
|
138 |
sheet.write(i, 4, lineitem.model_number)
|
| - |
|
139 |
sheet.write(i, 5, lineitem.color)
|
| - |
|
140 |
|
| - |
|
141 |
sheet.write(i, 6, to_py_date(order.created_timestamp), date_style)
|
| - |
|
142 |
sheet.write(i, 7, to_py_date(order.promised_shipping_time), date_style)
|
| - |
|
143 |
sheet.write(i, 8, to_py_date(order.expected_shipping_time), date_style)
|
| - |
|
144 |
sheet.write(i, 9, order.refundReason)
|
| - |
|
145 |
sheet.write(i, 10, to_py_date(order.refund_timestamp), date_style)
|
| - |
|
146 |
|
| - |
|
147 |
i= i+1
|
| - |
|
148 |
|
| - |
|
149 |
today = datetime.date.today()
|
| - |
|
150 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
| - |
|
151 |
filename = "/tmp/CancelledOrders-" + datestr + ".xls"
|
| - |
|
152 |
wbk.save(filename)
|
| - |
|
153 |
|
| - |
|
154 |
try:
|
| - |
|
155 |
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])
|
| - |
|
157 |
finally:
|
| - |
|
158 |
os.remove(filename)
|
| - |
|
159 |
|
| - |
|
160 |
def main():
|
| - |
|
161 |
parser = OptionParser()
|
| - |
|
162 |
parser.add_option("-d", "--delayed", dest="delayed",
|
| - |
|
163 |
action="store_true",
|
| - |
|
164 |
help="")
|
| - |
|
165 |
parser.add_option("-c", "--cancelled", dest="cancelled",
|
| - |
|
166 |
action="store_true",
|
| - |
|
167 |
help="")
|
| - |
|
168 |
|
| - |
|
169 |
(options, args) = parser.parse_args()
|
| - |
|
170 |
if options.delayed:
|
| - |
|
171 |
generate_delayed_orders_file()
|
| - |
|
172 |
if options.cancelled:
|
| - |
|
173 |
generate_cancelled_orders_file()
|
| - |
|
174 |
|
| 92 |
if __name__ == '__main__':
|
175 |
if __name__ == '__main__':
|
| 93 |
main()
|
176 |
main()
|
| 94 |
|
177 |
|