Rev 9575 | Rev 9803 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/pythonfrom elixir import *from datetime import datetime, timedelta, dateimport sysfrom shop2020.model.v1.order.impl import DataServicefrom shop2020.model.v1.order.impl.DataService import Order, DataInsuranceDetailForOrderimport xlwtfrom shop2020.utils import EmailAttachmentSenderfrom shop2020.utils.EmailAttachmentSender import get_attachment_partfrom shop2020.thriftpy.model.v1.order.ttypes import OrderStatusfrom shop2020.config.client.ConfigClient import ConfigClientfrom shop2020.clients.UserClient import UserClientconfig_client = ConfigClient()host = config_client.get_property('transaction_service_db_hostname')DataService.initialize(db_hostname=host)def deliveredOrders():todate = datetime.datetime.now()-timedelta(days = 10)dataInsurances = DataInsuranceDetailForOrder.query.filter(DataInsuranceDetailForOrder.isDeclared==False).filter(DataInsuranceDetailForOrder.startDate >= todate).all()if not dataInsurances:returnxstr = lambda s: s or ""i=1wbk = xlwt.Workbook()sheet = wbk.add_sheet('OneAssist Data')date_style = xlwt.XFStyle()date_style.num_format_str = "D/M/YY"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, "Record Type", heading_xf)sheet.write(0, 1, "account no", heading_xf)sheet.write(0, 2, "Mem Start Date", heading_xf)sheet.write(0, 3, "Membership Type", heading_xf)sheet.write(0, 4, "Level 1", heading_xf)sheet.write(0, 5, "Level 2", heading_xf)sheet.write(0, 6, "Level 3", heading_xf)sheet.write(0, 7, "Plan_id", heading_xf)sheet.write(0, 8, "PROMOCODE", heading_xf)sheet.write(0, 9, "Payment Mode", heading_xf)sheet.write(0, 10, "Credit Card No", heading_xf)sheet.write(0, 11, "Expiry Month", heading_xf)sheet.write(0, 12, "Expiry Year", heading_xf)sheet.write(0, 13, "Name on Card", heading_xf)sheet.write(0, 14, "Card Level", heading_xf)sheet.write(0, 15, "Issuer Bank", heading_xf)sheet.write(0, 16, "Card Brand", heading_xf)sheet.write(0, 17, "Address Line 1", heading_xf)sheet.write(0, 18, "Address Line 2", heading_xf)sheet.write(0, 19, "landmark", heading_xf)sheet.write(0, 20, "City", heading_xf)sheet.write(0, 21, "State", heading_xf)sheet.write(0, 22, "Pincode", heading_xf)sheet.write(0, 23, "Primary Cust First Name", heading_xf)sheet.write(0, 24, "Middle Name", heading_xf)sheet.write(0, 25, "Last Name", heading_xf)sheet.write(0, 26, "DOB", heading_xf)sheet.write(0, 27, "Gender", heading_xf)sheet.write(0, 28, "email id", heading_xf)sheet.write(0, 29, "mobile 1", heading_xf)sheet.write(0, 30, "mobile 2", heading_xf)sheet.write(0, 31, "OS", heading_xf)for dataInsurance in dataInsurances:order = dataInsurance.orderif order.status != OrderStatus.DELIVERY_SUCCESS:continueclient = UserClient().get_client()user = client.getUserById(order.customer_id)dataInsurance.isDeclared = Truesheet.write(i, 0, 'D')sheet.write(i, 1, '1')sheet.write(i, 2, dataInsurance.startDate, date_style)sheet.write(i, 3, 'S')sheet.write(i, 7, '3')sheet.write(i, 17, xstr(order.customer_address1))sheet.write(i, 18, xstr(order.customer_address2))sheet.write(i, 20, order.customer_city)sheet.write(i, 21, order.customer_state)sheet.write(i, 22, order.customer_pincode)sheet.write(i, 23, user.name)sheet.write(i, 28, order.customer_email)sheet.write(i, 29, order.customer_mobilenumber)sheet.write(i, 31, 'android')i+=1session.commit()today = date.today()datestr = str(today.day) + "-" + str(today.month) + "-" + str(today.year)filename = "/tmp/data-insurance-" + datestr + ".xls"wbk.save(filename)def returnOrders():todate = datetime.now()-timedelta(days = 2)orders = Order.query.filter(Order.dataProtectionInsurer > 0).filter(Order.received_return_timestamp >= todate).all()if not orders:returnwbk = xlwt.Workbook()sheet = wbk.add_sheet('OneAssist Return')date_style = xlwt.XFStyle()date_style.num_format_str = "D/M/YY"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, "Customer Name", heading_xf)sheet.write(0, 1, "Mobile Number", heading_xf)sheet.write(0, 2, "Reason", heading_xf)i=1for order in orders:dataInsurance = order.dataInsuranceDetails[0]if not (dataInsurance.startDate or dataInsurance.expiryDate) or dataInsurance.expiryDate < datetime.now():continueclient = UserClient.get_client()user = client.getUserById(order.customer_id)dataInsurance.expiryDate = order.received_return_timestampsheet.write(i, 0,user.name)sheet.write(i, 1, order.customer_mobilenumber)sheet.write(i, 2, '')i+=1session.commit()today = date.today()datestr = str(today.day) + "-" + str(today.month) + "-" + str(today.year)filename = "/tmp/data-insurance-return" + datestr + ".xls"wbk.save(filename)def main():deliveredOrders()returnOrders()if __name__ == '__main__':main()