Rev 4597 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''Creates a CSV report of all the shipped orders and send mail to Sandeep.Created on 20-Feb-2012@author: Rajveer'''import xlwtimport datetimeif __name__ == '__main__' and __package__ is None:import sysimport ossys.path.insert(0, os.getcwd())from shop2020.utils.Utils import to_py_datefrom shop2020.clients.TransactionClient import TransactionClientfrom shop2020.thriftpy.model.v1.order.ttypes import OrderStatus, Orderfrom shop2020.utils.EmailAttachmentSender import mail, get_attachment_partdef main():txn_client = TransactionClient().get_client()shipped_orders = txn_client.getOrdersInBatch([OrderStatus.SHIPPED_FROM_WH, OrderStatus.SHIPPED_TO_LOGST, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.REACHED_DESTINATION_CITY, OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE], 0, 0, 0)wbk = xlwt.Workbook()sheet = wbk.add_sheet('main')heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')sheet.set_panes_frozen(True)sheet.set_horz_split_pos(1)sheet.set_remove_splits(True)excel_integer_format = '0'integer_style = xlwt.XFStyle()integer_style.num_format_str = excel_integer_formatsheet.write(0, 0, "Order ID", heading_xf)sheet.write(0, 1, "Airway Bill No.", heading_xf)sheet.write(0, 2, "Provider Id", heading_xf)sheet.write(0, 3, "Shipping Date", heading_xf)sheet.write(0, 4, "Item Id", heading_xf)sheet.write(0, 5, "Brand", heading_xf)sheet.write(0, 6, "Model Name", heading_xf)sheet.write(0, 7, "Model Number", heading_xf)sheet.write(0, 8, "Color", heading_xf)order = Order()i = 1for order in shipped_orders:sheet.write(i, 0, order.id)sheet.write(i, 1, order.airwaybill_no)sheet.write(i, 2, order.logistics_provider_id)sheet.write(i, 3, to_py_date(order.shipping_timestamp))lineitem = order.lineitems[0]sheet.write(i, 4, lineitem.item_id)sheet.write(i, 5, lineitem.brand)sheet.write(i, 6, lineitem.model_name)sheet.write(i, 7, lineitem.model_number)sheet.write(i, 8, lineitem.color)i= i+1today = datetime.date.today()datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)filename = "/tmp/ShippedOrders-" + datestr + ".xls"wbk.save(filename)try:part = get_attachment_part(filename)mail("cnc.center@shop2020.in", "5h0p2o2o", "sandeep.sachdeva@shop2020.in", "Shipped Orders as on: " + datestr, "PFA attached xls files for the shipped orders.", [part])finally:os.remove(filename)if __name__ == '__main__':main()