| Line 2... |
Line 2... |
| 2 |
Created on Mar 13, 2015
|
2 |
Created on Mar 13, 2015
|
| 3 |
|
3 |
|
| 4 |
@author: amit
|
4 |
@author: amit
|
| 5 |
'''
|
5 |
'''
|
| 6 |
from datetime import date, datetime, timedelta
|
6 |
from datetime import date, datetime, timedelta
|
| - |
|
7 |
from dtr.main import Store
|
| 7 |
from dtr.storage.Mysql import getOrdersAfterDate, \
|
8 |
from dtr.reports.allorders import getUserOrders
|
| 8 |
getOrdersByTag
|
9 |
from dtr.storage import Mysql
|
| - |
|
10 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
| 9 |
from email import encoders
|
11 |
from email import encoders
|
| 10 |
from email.mime.base import MIMEBase
|
12 |
from email.mime.base import MIMEBase
|
| 11 |
from email.mime.multipart import MIMEMultipart
|
13 |
from email.mime.multipart import MIMEMultipart
|
| 12 |
from email.mime.text import MIMEText
|
14 |
from email.mime.text import MIMEText
|
| 13 |
from pymongo.mongo_client import MongoClient
|
15 |
from pymongo.mongo_client import MongoClient
|
| Line 366... |
Line 368... |
| 366 |
affNotReconciledSheet.write(row, inc(), 'IP', boldStyle)
|
368 |
affNotReconciledSheet.write(row, inc(), 'IP', boldStyle)
|
| 367 |
|
369 |
|
| 368 |
def getUserAmountReconciled():
|
370 |
def getUserAmountReconciled():
|
| 369 |
pass
|
371 |
pass
|
| 370 |
|
372 |
|
| - |
|
373 |
def getUserOrders():
|
| - |
|
374 |
global i
|
| - |
|
375 |
rb = open_workbook(XLS_FILENAME,formatting_info=True)
|
| - |
|
376 |
wb = copy(rb)
|
| - |
|
377 |
worksheet = wb.add_sheet("All Users")
|
| - |
|
378 |
worksheet1 = wb.add_sheet("Suspected Users")
|
| - |
|
379 |
|
| - |
|
380 |
db=client.Dtr
|
| - |
|
381 |
results = Mysql.fetchResult('''
|
| - |
|
382 |
select ow.*, u.username, crm1.order_count, u.referrer from order_view ow left join users u on u.id = ow.user_id left join (select user_id, count(*) as order_count from order_view where status = 'ORDER_CREATED' group by user_id) as crm1 on ow.user_id = crm1.user_id where lower(u.referrer) not like 'emp%'
|
| - |
|
383 |
''',)
|
| - |
|
384 |
orders = []
|
| - |
|
385 |
orders.append("")
|
| - |
|
386 |
orderH = []
|
| - |
|
387 |
row = 0
|
| - |
|
388 |
i=-1
|
| - |
|
389 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| - |
|
390 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
| - |
|
391 |
worksheet.write(row, inc(), 'User name', boldStyle)
|
| - |
|
392 |
worksheet1.write(row, i, 'User name', boldStyle)
|
| - |
|
393 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
| - |
|
394 |
worksheet1.write(row, i, 'Order Id', boldStyle)
|
| - |
|
395 |
worksheet.write(row, inc(), 'Created On', boldStyle)
|
| - |
|
396 |
worksheet1.write(row, i, 'Created On', boldStyle)
|
| - |
|
397 |
worksheet.write(row, inc(), 'Store Id', boldStyle)
|
| - |
|
398 |
worksheet1.write(row, i, 'Store Id', boldStyle)
|
| - |
|
399 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| - |
|
400 |
worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
| - |
|
401 |
worksheet.write(row, inc(), 'Amount Paid', boldStyle)
|
| - |
|
402 |
worksheet1.write(row, i, 'Amount Paid', boldStyle)
|
| - |
|
403 |
worksheet.write(row, inc(), 'Cashback', boldStyle)
|
| - |
|
404 |
worksheet1.write(row, i, 'Cashback', boldStyle)
|
| - |
|
405 |
worksheet.write(row, inc(), 'Order Status', boldStyle)
|
| - |
|
406 |
worksheet1.write(row, i, 'Order Status', boldStyle)
|
| - |
|
407 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
| - |
|
408 |
worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
| - |
|
409 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
| - |
|
410 |
worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
| - |
|
411 |
worksheet.write(row, inc(), 'Reconciled', boldStyle)
|
| - |
|
412 |
worksheet1.write(row, i, 'Reconciled', boldStyle)
|
| - |
|
413 |
worksheet.write(row, inc(), 'IP', boldStyle)
|
| - |
|
414 |
worksheet1.write(row, i, 'IP', boldStyle)
|
| - |
|
415 |
|
| - |
|
416 |
row=0
|
| - |
|
417 |
row2=0
|
| - |
|
418 |
for result in results:
|
| - |
|
419 |
morder = db.merchantOrder.find_one({"orderId":result[0]})
|
| - |
|
420 |
if morder is not None:
|
| - |
|
421 |
subOrders = morder.get("subOrders")
|
| - |
|
422 |
if subOrders is not None:
|
| - |
|
423 |
for subOrder in subOrders:
|
| - |
|
424 |
if subOrder.get("cashBackStatus") == Store.CB_APPROVED or subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
425 |
row +=1
|
| - |
|
426 |
i=-1
|
| - |
|
427 |
worksheet.write(row, inc(), result[0])
|
| - |
|
428 |
worksheet.write(row, inc(), result[-3])
|
| - |
|
429 |
worksheet.write(row, inc(), result[1])
|
| - |
|
430 |
worksheet.write(row, inc(), result[-4])
|
| - |
|
431 |
worksheet.write(row, inc(), result[2])
|
| - |
|
432 |
worksheet.write(row, inc(), morder.get("merchantOrderId"))
|
| - |
|
433 |
#order.append(subOrder.get("merchantSubOrderId"))
|
| - |
|
434 |
worksheet.write(row, inc(), subOrder.get("amountPaid"))
|
| - |
|
435 |
worksheet.write(row, inc(), subOrder.get("cashBackAmount"))
|
| - |
|
436 |
worksheet.write(row, inc(), subOrder.get("status"))
|
| - |
|
437 |
worksheet.write(row, inc(), subOrder.get("detailedStatus"))
|
| - |
|
438 |
worksheet.write(row, inc(), subOrder.get("cashBackStatus"))
|
| - |
|
439 |
worksheet.write(row, inc(), False if morder.get("reconciled") is None else True)
|
| - |
|
440 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
| - |
|
441 |
try:
|
| - |
|
442 |
worksheet.write(row, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
| - |
|
443 |
except:
|
| - |
|
444 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| - |
|
445 |
|
| - |
|
446 |
if result[-2] >= 10 and result[-1].lower().startswith("crm"):
|
| - |
|
447 |
row2 +=1
|
| - |
|
448 |
i=-1
|
| - |
|
449 |
worksheet1.write(row2, inc(), result[0])
|
| - |
|
450 |
worksheet1.write(row2, inc(), result[-3])
|
| - |
|
451 |
worksheet1.write(row2, inc(), result[1])
|
| - |
|
452 |
worksheet1.write(row2, inc(), result[-4])
|
| - |
|
453 |
worksheet1.write(row2, inc(), result[2])
|
| - |
|
454 |
worksheet1.write(row2, inc(), morder.get("merchantOrderId"))
|
| - |
|
455 |
worksheet1.write(row2, inc(), subOrder.get("amountPaid"))
|
| - |
|
456 |
worksheet1.write(row2, inc(), subOrder.get("cashBackAmount"))
|
| - |
|
457 |
worksheet1.write(row2, inc(), subOrder.get("status"))
|
| - |
|
458 |
worksheet1.write(row2, inc(), subOrder.get("detailedStatus"))
|
| - |
|
459 |
worksheet1.write(row2, inc(), subOrder.get("cashBackStatus"))
|
| - |
|
460 |
worksheet1.write(row2, inc(), False if morder.get("reconciled") is None else True)
|
| - |
|
461 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
| - |
|
462 |
try:
|
| - |
|
463 |
worksheet1.write(row2, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
| - |
|
464 |
except:
|
| - |
|
465 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| - |
|
466 |
wb.save(XLS_FILENAME)
|
| 371 |
|
467 |
|
| 372 |
def inc():
|
468 |
def inc():
|
| 373 |
global i
|
469 |
global i
|
| 374 |
i+=1
|
470 |
i+=1
|
| 375 |
return i
|
471 |
return i
|
| 376 |
|
472 |
|
| 377 |
def main():
|
473 |
def main():
|
| 378 |
generateSnapDealReco()
|
474 |
generateSnapDealReco()
|
| 379 |
#generateFlipkartReco()
|
475 |
getUserOrders()
|
| 380 |
sendmail(["amit.gupta@shop2020.in"], "", "DTR Affiliate Reco")
|
476 |
sendmail(["amit.gupta@shop2020.in"], "", "DTR Affiliate Reco")
|
| 381 |
|
477 |
|
| 382 |
if __name__ == '__main__':
|
478 |
if __name__ == '__main__':
|
| 383 |
main()
|
479 |
main()
|
| 384 |
|
480 |
|
| 385 |
|
481 |
|