Rev 6908 | Rev 6941 | 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.DataAccessors import move_orders_to_correct_warehousefrom shop2020.model.v1.order.impl.DataService import InsuranceDetailForOrderimport xlwtfrom shop2020.utils import EmailAttachmentSenderfrom shop2020.utils.EmailAttachmentSender import get_attachment_partfrom shop2020.thriftpy.model.v1.order.ttypes import OrderStatusdef main():DataService.initialize()todate = datetime.now()todate = todate-timedelta(days = 10)insurances = InsuranceDetailForOrder.query.filter(InsuranceDetailForOrder.isDeclared == False).filter(InsuranceDetailForOrder.startDate >= todate).all()if not insurances:returnwbk = 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, "Riskstartdate", heading_xf)sheet.write(0, 1, "StoreId", heading_xf)sheet.write(0, 2, "SystemInvoiceNumber", heading_xf)sheet.write(0, 3, "CustomerName", heading_xf)sheet.write(0, 4, "Type", heading_xf)sheet.write(0, 5, "Make", heading_xf)sheet.write(0, 6, "Model", heading_xf)sheet.write(0, 7, "EquipmentIdentificationNumber", heading_xf)sheet.write(0, 8, "Qty", heading_xf)sheet.write(0, 9, "Rate", heading_xf)sheet.write(0, 10, "TaxAmount", heading_xf)sheet.write(0, 11, "NetSales", heading_xf)sheet.write(0, 12, "FatherName", heading_xf)sheet.write(0, 13, "Birthdate", heading_xf)sheet.write(0, 14, "SystemInvoiceDate.", heading_xf)sheet.write(0, 15, "OrderId", heading_xf)sheet.write(0, 16, "OtherDetails3", heading_xf)xstr = lambda s: s or ""i = 1for insurance in insurances:order = insurance.orderif order.status != OrderStatus.DELIVERY_SUCCESS:continueline = order.lineitems[0]insurance.isDeclared = Truesheet.write(i, 0, insurance.startDate)sheet.write(i, 1, '')sheet.write(i, 2, order.invoice_number)sheet.write(i, 3, order.customer_name)sheet.write(i, 4, 'Mobile Phones')sheet.write(i, 5, line.brand)sheet.write(i, 6, xstr(line.model_name) + " " + xstr(line.model_number))sheet.write(i, 7, line.serial_number)sheet.write(i, 8, line.quantity)sheet.write(i, 9, line.unit_price)sheet.write(i, 10, "0")sheet.write(i, 11, line.total_price)sheet.write(i, 12, insurance.guardianName)sheet.write(i, 13, insurance.dob)sheet.write(i, 14, order.billing_timestamp)sheet.write(i, 15, order.id)sheet.write(i, 16, '')i = i + 1session.commit()today = date.today()datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)filename = "/tmp/insurance-" + datestr + ".xls"wbk.save(filename)EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["rajveer.singh@shop2020.in","anupam.singh@shop2020.in"], "Insurance Details for date ", "Please find attached insurance details for today.", [get_attachment_part(filename)], [], [])if __name__ == '__main__':main()