| Line 3... |
Line 3... |
| 3 |
from elixir import *
|
3 |
from elixir import *
|
| 4 |
from datetime import datetime, timedelta, date
|
4 |
from datetime import datetime, timedelta, date
|
| 5 |
import sys
|
5 |
import sys
|
| 6 |
from shop2020.model.v1.order.impl import DataService
|
6 |
from shop2020.model.v1.order.impl import DataService
|
| 7 |
from shop2020.model.v1.order.impl.DataAccessors import move_orders_to_correct_warehouse
|
7 |
from shop2020.model.v1.order.impl.DataAccessors import move_orders_to_correct_warehouse
|
| 8 |
from shop2020.model.v1.order.impl.DataService import InsuranceDetailForOrder
|
8 |
from shop2020.model.v1.order.impl.DataService import InsuranceDetailForOrder,\
|
| - |
|
9 |
Order
|
| 9 |
import xlwt
|
10 |
import xlwt
|
| 10 |
from shop2020.utils import EmailAttachmentSender
|
11 |
from shop2020.utils import EmailAttachmentSender
|
| 11 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
12 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
| 12 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
13 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
| 13 |
from shop2020.clients.CatalogClient import CatalogClient
|
14 |
from shop2020.clients.CatalogClient import CatalogClient
|
| 14 |
|
15 |
|
| 15 |
def main():
|
16 |
def delivered_orders():
|
| 16 |
DataService.initialize()
|
17 |
DataService.initialize()
|
| 17 |
todate = datetime.now()
|
18 |
todate = datetime.now()
|
| 18 |
todate = todate-timedelta(days = 10)
|
19 |
todate = todate-timedelta(days = 10)
|
| 19 |
insurances = InsuranceDetailForOrder.query.filter(InsuranceDetailForOrder.isDeclared == False).filter(InsuranceDetailForOrder.startDate >= todate).all()
|
20 |
insurances = InsuranceDetailForOrder.query.filter(InsuranceDetailForOrder.isDeclared == False).filter(InsuranceDetailForOrder.startDate >= todate).all()
|
| 20 |
if not insurances:
|
21 |
if not insurances:
|
| Line 91... |
Line 92... |
| 91 |
today = date.today()
|
92 |
today = date.today()
|
| 92 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
93 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
| 93 |
filename = "/tmp/insurance-" + datestr + ".xls"
|
94 |
filename = "/tmp/insurance-" + datestr + ".xls"
|
| 94 |
wbk.save(filename)
|
95 |
wbk.save(filename)
|
| 95 |
EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["ab@universalinsurance.co.in", "urmila.phadke@universalinsurace.co.in"], "Insurance Details for date ", "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"], [])
|
96 |
EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["ab@universalinsurance.co.in", "urmila.phadke@universalinsurace.co.in"], "Insurance Details for date ", "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"], [])
|
| - |
|
97 |
|
| - |
|
98 |
def returned_orders():
|
| - |
|
99 |
DataService.initialize()
|
| - |
|
100 |
todate = datetime.now()
|
| - |
|
101 |
todate = todate-timedelta(days = 2)
|
| - |
|
102 |
orders = Order.query.filter(Order.insurer > 0).filter(Order.received_return_timestamp >= todate).all()
|
| - |
|
103 |
|
| - |
|
104 |
if not orders:
|
| - |
|
105 |
return
|
| - |
|
106 |
|
| - |
|
107 |
wbk = xlwt.Workbook()
|
| - |
|
108 |
sheet = wbk.add_sheet('main')
|
| - |
|
109 |
|
| - |
|
110 |
date_style = xlwt.XFStyle()
|
| - |
|
111 |
date_style.num_format_str = "D/M/YY"
|
| - |
|
112 |
|
| - |
|
113 |
heading_xf = xlwt.easyxf('font: bold on; align: wrap on, vert centre, horiz center')
|
| - |
|
114 |
sheet.set_panes_frozen(True)
|
| - |
|
115 |
sheet.set_horz_split_pos(1)
|
| - |
|
116 |
sheet.set_remove_splits(True)
|
| - |
|
117 |
|
| - |
|
118 |
excel_integer_format = '0'
|
| - |
|
119 |
integer_style = xlwt.XFStyle()
|
| - |
|
120 |
integer_style.num_format_str = excel_integer_format
|
| - |
|
121 |
|
| - |
|
122 |
sheet.write(0, 0, "SalesReturnDate", heading_xf)
|
| - |
|
123 |
sheet.write(0, 1, "SalesReturnNumber", heading_xf)
|
| - |
|
124 |
sheet.write(0, 2, "CustomerName", heading_xf)
|
| - |
|
125 |
sheet.write(0, 3, "EquipmentIdentificationNumber", heading_xf)
|
| - |
|
126 |
sheet.write(0, 4, "SystemInvoiceNumber", heading_xf)
|
| - |
|
127 |
sheet.write(0, 5, "Rate", heading_xf)
|
| - |
|
128 |
sheet.write(0, 6, "Amount", heading_xf)
|
| - |
|
129 |
|
| - |
|
130 |
xstr = lambda s: s or ""
|
| - |
|
131 |
|
| - |
|
132 |
declaredAmount= 0.0
|
| - |
|
133 |
i = 1
|
| - |
|
134 |
for order in orders:
|
| - |
|
135 |
insurance = order.insuranceDetails[0]
|
| - |
|
136 |
if insurance.expiryDate < datetime.now():
|
| - |
|
137 |
continue
|
| - |
|
138 |
|
| - |
|
139 |
line = order.lineitems[0]
|
| - |
|
140 |
insurance.expiryDate = order.received_return_timestamp
|
| - |
|
141 |
|
| - |
|
142 |
insured_days = ((order.received_return_timestamp).date() - ((insurance.startDate).date())).days
|
| - |
|
143 |
|
| - |
|
144 |
declaredAmount += line.total_price/365*(365-insured_days)
|
| - |
|
145 |
|
| - |
|
146 |
sheet.write(i, 0, insurance.startDate, date_style)
|
| - |
|
147 |
sheet.write(i, 1, order.invoice_number)
|
| - |
|
148 |
sheet.write(i, 2, order.customer_name)
|
| - |
|
149 |
sheet.write(i, 3, line.serial_number)
|
| - |
|
150 |
sheet.write(i, 4, order.invoice_number)
|
| - |
|
151 |
sheet.write(i, 5, line.unit_price)
|
| - |
|
152 |
sheet.write(i, 6, line.unit_price)
|
| - |
|
153 |
i = i + 1
|
| - |
|
154 |
|
| - |
|
155 |
session.commit()
|
| - |
|
156 |
client = CatalogClient().get_client()
|
| - |
|
157 |
client.updateInsuranceDeclaredAmount(1, -declaredAmount)
|
| - |
|
158 |
|
| - |
|
159 |
today = date.today()
|
| - |
|
160 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
| - |
|
161 |
filename = "/tmp/insurance-return-" + datestr + ".xls"
|
| - |
|
162 |
wbk.save(filename)
|
| - |
|
163 |
EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["ab@universalinsurance.co.in", "urmila.phadke@universalinsurace.co.in"], "Insurance Details for date ", "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"], [])
|
| 96 |
|
164 |
|
| - |
|
165 |
def main():
|
| - |
|
166 |
delivered_orders()
|
| - |
|
167 |
returned_orders()
|
| - |
|
168 |
|
| 97 |
if __name__ == '__main__':
|
169 |
if __name__ == '__main__':
|
| 98 |
main()
|
170 |
main()
|
| 99 |
|
171 |
|