| Line 10... |
Line 10... |
| 10 |
import xlwt
|
10 |
import xlwt
|
| 11 |
from shop2020.utils import EmailAttachmentSender
|
11 |
from shop2020.utils import EmailAttachmentSender
|
| 12 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
12 |
from shop2020.utils.EmailAttachmentSender import get_attachment_part
|
| 13 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
13 |
from shop2020.thriftpy.model.v1.order.ttypes import OrderStatus
|
| 14 |
from shop2020.clients.CatalogClient import CatalogClient
|
14 |
from shop2020.clients.CatalogClient import CatalogClient
|
| - |
|
15 |
from suds.client import Client
|
| - |
|
16 |
from xml.dom.minidom import parseString
|
| - |
|
17 |
import logging
|
| 15 |
|
18 |
|
| 16 |
def delivered_orders():
|
19 |
def delivered_orders():
|
| 17 |
DataService.initialize(db_hostname="192.168.190.114")
|
20 |
DataService.initialize(db_hostname="192.168.190.114")
|
| 18 |
todate = datetime.now()
|
21 |
todate = datetime.now()
|
| 19 |
todate = todate-timedelta(days = 10)
|
22 |
todate = todate-timedelta(days = 10)
|
| Line 164... |
Line 167... |
| 164 |
today = date.today()
|
167 |
today = date.today()
|
| 165 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
168 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
| 166 |
filename = "/tmp/insurance-return-" + datestr + ".xls"
|
169 |
filename = "/tmp/insurance-return-" + datestr + ".xls"
|
| 167 |
wbk.save(filename)
|
170 |
wbk.save(filename)
|
| 168 |
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"], [])
|
171 |
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"], [])
|
| - |
|
172 |
|
| - |
|
173 |
def submitDeliveredOrdersDetails():
|
| - |
|
174 |
DataService.initialize(db_hostname="192.168.190.114")
|
| - |
|
175 |
todate = datetime.now()
|
| - |
|
176 |
todate = todate-timedelta(days = 10)
|
| - |
|
177 |
xstr = lambda s: s or ""
|
| - |
|
178 |
|
| - |
|
179 |
declaredAmount= 0.0
|
| - |
|
180 |
successful= []
|
| - |
|
181 |
duplicateRecord = []
|
| - |
|
182 |
serverSide = []
|
| - |
|
183 |
dataFormat = []
|
| - |
|
184 |
client = Client('http://www.insuregadget.ae/SSSWebService/SSSWebService.asmx?wsdl')
|
| - |
|
185 |
header=client.factory.create('AuthHeader')
|
| - |
|
186 |
header.Username = 'saholic'
|
| - |
|
187 |
header.Password = '1Dfgh4@#'
|
| - |
|
188 |
client.set_options(soapheaders=header)
|
| - |
|
189 |
|
| - |
|
190 |
insurances = InsuranceDetailForOrder.query.filter(InsuranceDetailForOrder.isDeclared == False).filter(InsuranceDetailForOrder.startDate >= todate).all()
|
| - |
|
191 |
if not insurances:
|
| - |
|
192 |
return
|
| - |
|
193 |
for insurance in insurances:
|
| - |
|
194 |
order = insurance.order
|
| - |
|
195 |
if order.status != OrderStatus.DELIVERY_SUCCESS:
|
| - |
|
196 |
continue
|
| - |
|
197 |
try:
|
| - |
|
198 |
dateOfBirth = getDateFormatForDob(insurance.dob)
|
| - |
|
199 |
except:
|
| - |
|
200 |
try:
|
| - |
|
201 |
dateOfBirth = getDateFormatForDob2(insurance.dob)
|
| - |
|
202 |
except:
|
| - |
|
203 |
dataFormat.append(order.id)
|
| - |
|
204 |
continue
|
| - |
|
205 |
line = order.lineitems[0]
|
| - |
|
206 |
Connected =False
|
| - |
|
207 |
Attempt = 1
|
| - |
|
208 |
while not Connected:
|
| - |
|
209 |
try:
|
| - |
|
210 |
response = client.service.InsertSalesRecord('SAHOLIC',line.serial_number,getValidDateFormat(order.billing_timestamp.date()),order.invoice_number,\
|
| - |
|
211 |
'Mobile Phones',line.brand,xstr(line.model_name) + " " + xstr(line.model_number),line.unit_price,\
|
| - |
|
212 |
'0',line.total_price,order.customer_name,insurance.guardianName,dateOfBirth,str(order.id),\
|
| - |
|
213 |
order.customer_mobilenumber,'')
|
| - |
|
214 |
|
| - |
|
215 |
Connected=True
|
| - |
|
216 |
except:
|
| - |
|
217 |
print "Unable to insert sale record.Attempting again...."
|
| - |
|
218 |
Attempt = Attempt+1
|
| - |
|
219 |
if Attempt ==3:
|
| - |
|
220 |
break
|
| - |
|
221 |
if not Connected:
|
| - |
|
222 |
serverSide.append(order.id)
|
| - |
|
223 |
continue
|
| - |
|
224 |
|
| - |
|
225 |
dom = parseString("<dom>" + response + "</dom>")
|
| - |
|
226 |
sssResponse = dom.getElementsByTagName('SSSResponse')[0]
|
| - |
|
227 |
status = sssResponse.getElementsByTagName('Status')
|
| - |
|
228 |
statusStr = status[0].childNodes[0].data
|
| - |
|
229 |
if (statusStr == 'Failure'):
|
| - |
|
230 |
error = sssResponse.getElementsByTagName('ErrorCode')
|
| - |
|
231 |
errorCode = int(error[0].childNodes[0].data)
|
| - |
|
232 |
if (errorCode == 999):
|
| - |
|
233 |
duplicateRecord.append(order.id)
|
| - |
|
234 |
elif (errorCode ==9999 or errorCode==99999):
|
| - |
|
235 |
serverSide.append(order.id)
|
| - |
|
236 |
else:
|
| - |
|
237 |
dataFormat.append(order.id)
|
| - |
|
238 |
|
| - |
|
239 |
elif (statusStr == 'Success'):
|
| - |
|
240 |
insurance.isDeclared = True
|
| - |
|
241 |
declaredAmount += line.total_price
|
| - |
|
242 |
successful.append(order.id)
|
| - |
|
243 |
print "Insurance details successfully inserted.Order Id ",order.id
|
| - |
|
244 |
|
| - |
|
245 |
else:
|
| - |
|
246 |
serverSide.append(order.id)
|
| - |
|
247 |
|
| - |
|
248 |
session.commit()
|
| - |
|
249 |
client = CatalogClient().get_client()
|
| - |
|
250 |
client.updateInsuranceDeclaredAmount(1, declaredAmount)
|
| - |
|
251 |
today = date.today()
|
| - |
|
252 |
datestr = str(today.year) + "-" + str(today.month) + "-" + str(today.day)
|
| - |
|
253 |
insurer = client.getInsurer(1)
|
| - |
|
254 |
EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["pramit.singh@shop2020.in","rajveer.singh@shop2020.in","anupam.singh@shop2020.in","rajneesh.arora@shop2020.in", "amit.tyagi@spiceretail.co.in", "pardeep.panwar@spiceretail.co.in", "j.p.gupta@shop2020.in"], "Declaration Status for insurer " + insurer.name + " as on " + datestr + " : (Declared Amount - " + str(insurer.declaredAmount) + ") (Total Amount - " + str(insurer.creditedAmount), "", [], [], [])
|
| - |
|
255 |
mail_body = "Number of records successfully inserted :"+str(len(successful))+"\nFollowing order id's were not processed because\nServer Side Error: "+', '.join(map(str, serverSide))+"\n"+"Data Format Error: "+', '.join(map(str, dataFormat))+"\n"+"Duplicate entry IMEI: "+', '.join(map(str, duplicateRecord))
|
| - |
|
256 |
print mail_body
|
| - |
|
257 |
EmailAttachmentSender.mail("cnc.center@shop2020.in", "5h0p2o2o", ["rajveer.singh@shop2020.in","kshitij.sood@shop2020.in"], "Insurance submission result for date " + datestr, mail_body, [], [], [])
|
| - |
|
258 |
|
| - |
|
259 |
|
| - |
|
260 |
|
| - |
|
261 |
def getValidDateFormat(dateToFormat):
|
| - |
|
262 |
return str(dateToFormat).replace('-','')
|
| - |
|
263 |
|
| - |
|
264 |
def getDateFormatForDob(dateToFormat):
|
| - |
|
265 |
return str(datetime.strptime(dateToFormat,"%b %d %Y").date()).replace('-','')
|
| - |
|
266 |
|
| - |
|
267 |
def getDateFormatForDob2(dateToFormat):
|
| - |
|
268 |
return str(datetime.strptime(dateToFormat,"%d %b %Y").date()).replace('-','')
|
| 169 |
|
269 |
|
| 170 |
def main():
|
270 |
def main():
|
| - |
|
271 |
submitDeliveredOrdersDetails()
|
| 171 |
delivered_orders()
|
272 |
#delivered_orders()
|
| 172 |
returned_orders()
|
273 |
returned_orders()
|
| 173 |
|
274 |
|
| 174 |
if __name__ == '__main__':
|
275 |
if __name__ == '__main__':
|
| 175 |
main()
|
276 |
main()
|
| 176 |
|
277 |
|