| Line 5... |
Line 5... |
| 5 |
'''
|
5 |
'''
|
| 6 |
from datetime import date, datetime, timedelta
|
6 |
from datetime import date, datetime, timedelta
|
| 7 |
from dtr.main import Store, sourceMap
|
7 |
from dtr.main import Store, sourceMap
|
| 8 |
from dtr.reports.amazonreco import generateAmazonReco
|
8 |
from dtr.reports.amazonreco import generateAmazonReco
|
| 9 |
from dtr.storage import Mysql, DataService
|
9 |
from dtr.storage import Mysql, DataService
|
| 10 |
from dtr.storage.DataService import Users, Clicks, FlipkartOrders
|
10 |
from dtr.storage.DataService import Users, Clicks, FlipkartOrders,\
|
| - |
|
11 |
All_user_addresses
|
| 11 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
12 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
| 12 |
from dtr.utils.utils import fromTimeStamp
|
13 |
from dtr.utils.utils import fromTimeStamp
|
| 13 |
from elixir import *
|
14 |
from elixir import *
|
| 14 |
from sqlalchemy.sql.expression import func, func, or_
|
15 |
from sqlalchemy.sql.expression import func, func, or_
|
| 15 |
from email import encoders
|
16 |
from email import encoders
|
| Line 709... |
Line 710... |
| 709 |
sh1 = workbook.add_sheet("All Orders")
|
710 |
sh1 = workbook.add_sheet("All Orders")
|
| 710 |
sh2 = workbook.add_sheet("Flipkart Orders")
|
711 |
sh2 = workbook.add_sheet("Flipkart Orders")
|
| 711 |
|
712 |
|
| 712 |
db=client.Dtr
|
713 |
db=client.Dtr
|
| 713 |
results = Mysql.fetchResult('''
|
714 |
results = Mysql.fetchResult('''
|
| - |
|
715 |
select ow.*, u.username, crm1.order_count, u.referrer, aua.city,aua.state,aua.pincode from order_view ow
|
| - |
|
716 |
left join users u on u.id = ow.user_id
|
| 714 |
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%' or u.referrer is null;
|
717 |
left join (select user_id, count(*) as order_count from order_view where status in ('ORDER_CREATED','DETAIL_CREATED') group by user_id)as crm1 on ow.user_id = crm1.user_id
|
| - |
|
718 |
left join (select * from (select * from all_user_addresses order by source) s group by user_id)aua on aua.user_id=u.id
|
| - |
|
719 |
where (lower(u.referrer) not like 'emp%' or u.utm_campaign is not null) and u.activated = 1 and ow.status in ('ORDER_CREATED','DETAIL_CREATED');
|
| 715 |
''',)
|
720 |
''',)
|
| 716 |
row = 0
|
721 |
row = 0
|
| 717 |
i=-1
|
722 |
i=-1
|
| 718 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
723 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 719 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
724 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
| Line 749... |
Line 754... |
| 749 |
sh1.write(row, inc(), 'Order Id', boldStyle)
|
754 |
sh1.write(row, inc(), 'Order Id', boldStyle)
|
| 750 |
sh1.write(row, inc(), 'Created On', boldStyle)
|
755 |
sh1.write(row, inc(), 'Created On', boldStyle)
|
| 751 |
sh1.write(row, inc(), 'Store Id', boldStyle)
|
756 |
sh1.write(row, inc(), 'Store Id', boldStyle)
|
| 752 |
sh1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
757 |
sh1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 753 |
sh1.write(row, inc(), 'Status', boldStyle)
|
758 |
sh1.write(row, inc(), 'Status', boldStyle)
|
| - |
|
759 |
sh1.write(row, inc(), 'Detailed Status', boldStyle)
|
| 754 |
sh1.write(row, inc(), 'Product title', boldStyle)
|
760 |
sh1.write(row, inc(), 'Product title', boldStyle)
|
| 755 |
sh1.write(row, inc(), 'Referrer', boldStyle)
|
761 |
sh1.write(row, inc(), 'Referrer', boldStyle)
|
| 756 |
sh1.write(row, inc(), 'Amount Paid', boldStyle)
|
762 |
sh1.write(row, inc(), 'Amount Paid', boldStyle)
|
| 757 |
sh1.write(row, inc(), 'Catalog Id', boldStyle)
|
763 |
sh1.write(row, inc(), 'Catalog Id', boldStyle)
|
| 758 |
sh1.write(row, inc(), 'Brand', boldStyle)
|
764 |
sh1.write(row, inc(), 'Brand', boldStyle)
|
| 759 |
sh1.write(row, inc(), 'Model', boldStyle)
|
765 |
sh1.write(row, inc(), 'Model', boldStyle)
|
| 760 |
sh1.write(row, inc(), 'Category', boldStyle)
|
766 |
sh1.write(row, inc(), 'Category', boldStyle)
|
| - |
|
767 |
sh1.write(row, inc(), 'Deal Rank', boldStyle)
|
| - |
|
768 |
sh1.write(row, inc(), 'City', boldStyle)
|
| - |
|
769 |
sh1.write(row, inc(), 'State', boldStyle)
|
| - |
|
770 |
sh1.write(row, inc(), 'Pincode', boldStyle)
|
| 761 |
i =-1
|
771 |
i =-1
|
| 762 |
sh2.write(row, inc(), 'User Id', boldStyle)
|
772 |
sh2.write(row, inc(), 'User Id', boldStyle)
|
| 763 |
sh2.write(row, inc(), 'User name', boldStyle)
|
773 |
sh2.write(row, inc(), 'User name', boldStyle)
|
| 764 |
sh2.write(row, inc(), 'Created On', boldStyle)
|
774 |
sh2.write(row, inc(), 'Created On', boldStyle)
|
| 765 |
sh2.write(row, inc(), 'Store', boldStyle)
|
775 |
sh2.write(row, inc(), 'Store', boldStyle)
|
| Line 783... |
Line 793... |
| 783 |
if subOrders is not None:
|
793 |
if subOrders is not None:
|
| 784 |
for subOrder in subOrders:
|
794 |
for subOrder in subOrders:
|
| 785 |
row3+=1
|
795 |
row3+=1
|
| 786 |
i=-1
|
796 |
i=-1
|
| 787 |
sh1.write(row3, inc(), result[1])
|
797 |
sh1.write(row3, inc(), result[1])
|
| 788 |
sh1.write(row3, inc(), result[-3])
|
798 |
sh1.write(row3, inc(), result[7])
|
| 789 |
sh1.write(row3, inc(), result[0])
|
799 |
sh1.write(row3, inc(), result[0])
|
| 790 |
sh1.write(row3, inc(), result[-4], datetime_format)
|
800 |
sh1.write(row3, inc(), result[6], datetime_format)
|
| 791 |
sh1.write(row3, inc(), sourceMap.get(result[2]))
|
801 |
sh1.write(row3, inc(), sourceMap.get(result[2]))
|
| 792 |
sh1.write(row3, inc(), morder.get("merchantOrderId"))
|
802 |
sh1.write(row3, inc(), morder.get("merchantOrderId"))
|
| 793 |
sh1.write(row3, inc(), subOrder.get("status"))
|
803 |
sh1.write(row3, inc(), subOrder.get("status"))
|
| - |
|
804 |
sh1.write(row3, inc(), subOrder.get("detailedStatus"))
|
| 794 |
sh1.write(row3, inc(), subOrder.get("productTitle"))
|
805 |
sh1.write(row3, inc(), subOrder.get("productTitle"))
|
| 795 |
sh1.write(row3, inc(), result[-1])
|
806 |
sh1.write(row3, inc(), result[9])
|
| 796 |
inc()
|
807 |
inc()
|
| 797 |
if int(subOrder.get("quantity")) > 0:
|
808 |
if int(subOrder.get("quantity")) > 0:
|
| 798 |
sh1.write(row3, i, int(subOrder.get("amountPaid"))/int(subOrder.get("quantity")))
|
809 |
sh1.write(row3, i, int(subOrder.get("amountPaid"))/int(subOrder.get("quantity")))
|
| 799 |
skuData = getSkuData(morder.get("storeId"), subOrder.get("productCode"))
|
810 |
skuData = getSkuData(morder.get("storeId"), subOrder.get("productCode"))
|
| 800 |
if morder.get("storeId") in (1,2,4,5):
|
811 |
if morder.get("storeId") in (1,2,4,5):
|
| Line 804... |
Line 815... |
| 804 |
if skuData is not None:
|
815 |
if skuData is not None:
|
| 805 |
sh1.write(row3, inc(), skuData.get("skuBundleId"))
|
816 |
sh1.write(row3, inc(), skuData.get("skuBundleId"))
|
| 806 |
sh1.write(row3, inc(), skuData.get("brand"))
|
817 |
sh1.write(row3, inc(), skuData.get("brand"))
|
| 807 |
sh1.write(row3, inc(), skuData.get("model_name"))
|
818 |
sh1.write(row3, inc(), skuData.get("model_name"))
|
| 808 |
sh1.write(row3, inc(), skuData.get("category"))
|
819 |
sh1.write(row3, inc(), skuData.get("category"))
|
| - |
|
820 |
sh1.write(row3, inc(), subOrder.get("rank"))
|
| - |
|
821 |
else:
|
| - |
|
822 |
sh1.write(row3, inc(), None)
|
| - |
|
823 |
sh1.write(row3, inc(), None)
|
| - |
|
824 |
sh1.write(row3, inc(), None)
|
| - |
|
825 |
sh1.write(row3, inc(), None)
|
| - |
|
826 |
sh1.write(row3, inc(), None)
|
| - |
|
827 |
sh1.write(row3, inc(), result[10])
|
| - |
|
828 |
sh1.write(row3, inc(), result[11])
|
| - |
|
829 |
sh1.write(row3, inc(), result[12])
|
| - |
|
830 |
|
| 809 |
#removed filter as requested by Rajneesh
|
831 |
#removed filter as requested by Rajneesh
|
| 810 |
#if subOrder.get("cashBackStatus") == Store.CB_APPROVED or subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
832 |
#if subOrder.get("cashBackStatus") == Store.CB_APPROVED or subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
| 811 |
row +=1
|
833 |
row +=1
|
| 812 |
i=-1
|
834 |
i=-1
|
| 813 |
worksheet.write(row, inc(), result[0])
|
835 |
worksheet.write(row, inc(), result[0])
|
| 814 |
worksheet.write(row, inc(), result[-3])
|
836 |
worksheet.write(row, inc(), result[7])
|
| 815 |
worksheet.write(row, inc(), result[1])
|
837 |
worksheet.write(row, inc(), result[1])
|
| 816 |
worksheet.write(row, inc(), result[-4], datetime_format)
|
838 |
worksheet.write(row, inc(), result[6], datetime_format)
|
| 817 |
worksheet.write(row, inc(), result[2])
|
839 |
worksheet.write(row, inc(), result[2])
|
| 818 |
worksheet.write(row, inc(), morder.get("merchantOrderId"))
|
840 |
worksheet.write(row, inc(), morder.get("merchantOrderId"))
|
| 819 |
worksheet.write(row, inc(), subOrder.get("productTitle"))
|
841 |
worksheet.write(row, inc(), subOrder.get("productTitle"))
|
| 820 |
worksheet.write(row, inc(), subOrder.get("amountPaid"))
|
842 |
worksheet.write(row, inc(), subOrder.get("amountPaid"))
|
| 821 |
worksheet.write(row, inc(), subOrder.get("cashBackAmount"))
|
843 |
worksheet.write(row, inc(), subOrder.get("cashBackAmount"))
|
| Line 826... |
Line 848... |
| 826 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
848 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
| 827 |
try:
|
849 |
try:
|
| 828 |
worksheet.write(row, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
850 |
worksheet.write(row, inc(), db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True}).get("ip"))
|
| 829 |
except:
|
851 |
except:
|
| 830 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
852 |
print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| 831 |
if result[-2] >= 10:
|
853 |
if result[8] >= 10:
|
| 832 |
row2 +=1
|
854 |
row2 +=1
|
| 833 |
i=-1
|
855 |
i=-1
|
| 834 |
worksheet1.write(row2, inc(), result[0])
|
856 |
worksheet1.write(row2, inc(), result[0])
|
| 835 |
worksheet1.write(row2, inc(), result[-3])
|
857 |
worksheet1.write(row2, inc(), result[7])
|
| 836 |
worksheet1.write(row2, inc(), result[1])
|
858 |
worksheet1.write(row2, inc(), result[1])
|
| 837 |
worksheet1.write(row2, inc(), result[-4], datetime_format)
|
859 |
worksheet1.write(row2, inc(), result[6], datetime_format)
|
| 838 |
worksheet1.write(row2, inc(), result[2])
|
860 |
worksheet1.write(row2, inc(), result[2])
|
| 839 |
worksheet1.write(row2, inc(), morder.get("merchantOrderId"))
|
861 |
worksheet1.write(row2, inc(), morder.get("merchantOrderId"))
|
| 840 |
worksheet1.write(row2, inc(), subOrder.get("productTitle"))
|
862 |
worksheet1.write(row2, inc(), subOrder.get("productTitle"))
|
| 841 |
worksheet1.write(row2, inc(), subOrder.get("amountPaid"))
|
863 |
worksheet1.write(row2, inc(), subOrder.get("amountPaid"))
|
| 842 |
worksheet1.write(row2, inc(), subOrder.get("cashBackAmount"))
|
864 |
worksheet1.write(row2, inc(), subOrder.get("cashBackAmount"))
|