Rev 9876 | 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.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(encoding="UTF-8")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, "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)sheet.write(0, 32, "PANNO", heading_xf)sheet.write(0, 33, "Relationship", heading_xf)sheet.write(0, 34, "Secondary Cust First Name", heading_xf)sheet.write(0, 35, "Middle Name", heading_xf)sheet.write(0, 36, "Last Name", heading_xf)sheet.write(0, 37, "DOB", heading_xf)sheet.write(0, 38, "Gender", heading_xf)sheet.write(0, 39, "email id", heading_xf)sheet.write(0, 40, "mobile 1", heading_xf)sheet.write(0, 41, "mobile 2", heading_xf)sheet.write(0, 42, "OS", heading_xf)sheet.write(0, 43, "PANNO", heading_xf)sheet.write(0, 44, "A/c No", heading_xf)sheet.write(0, 45, "A/c Type", heading_xf)sheet.write(0, 46, "A/c holder name", heading_xf)sheet.write(0, 47, "Branch name", heading_xf)sheet.write(0, 48, "MICR Code", heading_xf)sheet.write(0, 49, "IFSC Code", heading_xf)sheet.write(0, 50, "Cheque No", heading_xf)sheet.write(0, 51, "Cheque Date", heading_xf)sheet.write(0, 52, "Bank Name", heading_xf)sheet.write(0, 53, "Cheque Status", heading_xf)sheet.write(0, 54, "A/c No", heading_xf)sheet.write(0, 55, "A/c Type", heading_xf)sheet.write(0, 56, "A/c holder name", heading_xf)sheet.write(0, 57, "Branch name", heading_xf)sheet.write(0, 58, "MICR Code", heading_xf)sheet.write(0, 59, "IFSC Code", heading_xf)sheet.write(0, 60, "Cheque No.", heading_xf)sheet.write(0, 61, "Cheque Date", heading_xf)sheet.write(0, 62, "Bank Name", heading_xf)sheet.write(0, 63, "Cheque Status", heading_xf)sheet.write(0, 64, "ECS Start Date", heading_xf)sheet.write(0, 65, "ECS End Date", heading_xf)for dataInsurance in dataInsurances:order = dataInsurance.orderif order.status != OrderStatus.DELIVERY_SUCCESS:continuedataInsurance.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, '57')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, order.customer_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/mobile-assist-" + datestr + ".xls"wbk.save(filename)EmailAttachmentSender.mail("build@shop2020.in", "cafe@nes", ["retail-ops@oneassist.in", "abhay.chandak@oneassist.in"], "Mobile Assist data for date " + datestr, "Please find attached details for today.", [get_attachment_part(filename)], ["rajneesh.arora@saholic.com","khushal.bhatia@saholic.com","rajveer.singh@saholic.com","kshitij.sood@saholic.com","pramit.singh@saholic.com"], [])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():continuedataInsurance.expiryDate = order.received_return_timestampsheet.write(i, 0,order.customer_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/mobile-assist-return" + datestr + ".xls"wbk.save(filename)def main():deliveredOrders()#returnOrders()if __name__ == '__main__':main()