Rev 7018 | Rev 7177 | 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 InsuranceDetailForOrder,\Orderimport xlwtfrom shop2020.utils import EmailAttachmentSenderfrom shop2020.utils.EmailAttachmentSender import get_attachment_partfrom shop2020.thriftpy.model.v1.order.ttypes import OrderStatusfrom shop2020.clients.CatalogClient import CatalogClientdef delivered_orders():DataService.initialize(db_hostname="192.168.190.114")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')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, "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 ""declaredAmount= 0.0i = 1for insurance in insurances:order = insurance.orderif order.status != OrderStatus.DELIVERY_SUCCESS:continueline = order.lineitems[0]insurance.isDeclared = TruedeclaredAmount += line.total_pricesheet.write(i, 0, insurance.startDate, date_style)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, date_style)sheet.write(i, 15, order.id)sheet.write(i, 16, '')i = i + 1session.commit()client = CatalogClient().get_client()client.updateInsuranceDeclaredAmount(1, declaredAmount)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", ["ab@universalinsurance.co.in", "urmila.phadke@universalinsurace.co.in"], "Insurance Details for date " + datestr, "Please find attached insurance details for today.", [get_attachment_part(filename)], ["pramit.singh@shop2020.in","rbuniversal@gmail.com","rajveer.singh@shop2020.in","anupam.singh@shop2020.in","rajneesh.arora@shop2020.in"], [])def returned_orders():DataService.initialize(db_hostname="192.168.190.114")todate = datetime.now()todate = todate-timedelta(days = 2)orders = Order.query.filter(Order.insurer > 0).filter(Order.received_return_timestamp >= todate).all()if not orders:returnwbk = xlwt.Workbook()sheet = wbk.add_sheet('main')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, "SalesReturnDate", heading_xf)sheet.write(0, 1, "SalesReturnNumber", heading_xf)sheet.write(0, 2, "CustomerName", heading_xf)sheet.write(0, 3, "EquipmentIdentificationNumber", heading_xf)sheet.write(0, 4, "SystemInvoiceNumber", heading_xf)sheet.write(0, 5, "Rate", heading_xf)sheet.write(0, 6, "Amount", heading_xf)sheet.write(0, 7, "OrderId", heading_xf)xstr = lambda s: s or ""declaredAmount= 0.0i = 1for order in orders:insurance = order.insuranceDetails[0]if not (insurance.startDate or insurance.expiryDate) or insurance.expiryDate < datetime.now():continueline = order.lineitems[0]insurance.expiryDate = order.received_return_timestampinsured_days = ((order.received_return_timestamp).date() - ((insurance.startDate).date())).daysdeclaredAmount += line.total_price/365*(365-insured_days)sheet.write(i, 0, insurance.startDate, date_style)sheet.write(i, 1, order.invoice_number)sheet.write(i, 2, order.customer_name)sheet.write(i, 3, line.serial_number)sheet.write(i, 4, order.invoice_number)sheet.write(i, 5, line.unit_price)sheet.write(i, 6, line.unit_price)sheet.write(i, 7, order.id)i = i + 1session.commit()client = CatalogClient().get_client()client.updateInsuranceDeclaredAmount(1, -declaredAmount)today = date.today()datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)filename = "/tmp/insurance-return-" + datestr + ".xls"wbk.save(filename)EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["ab@universalinsurance.co.in", "urmila.phadke@universalinsurace.co.in"], "Cancelled Insurance Policy Details for date " + datestr, "Please find attached orders which insurance need to be cancelled for today.", [get_attachment_part(filename)], ["pramit.singh@shop2020.in","rbuniversal@gmail.com","rajveer.singh@shop2020.in","anupam.singh@shop2020.in","rajneesh.arora@shop2020.in"], [])def main():delivered_orders()returned_orders()if __name__ == '__main__':main()