Subversion Repositories SmartDukaan

Rev

Rev 17141 | Rev 17161 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 17141 Rev 17159
Line 941... Line 941...
941
def getUserAmountReconciled():
941
def getUserAmountReconciled():
942
    pass
942
    pass
943
 
943
 
944
def getUserOrders():
944
def getUserOrders():
945
    global i
945
    global i
946
    rb = open_workbook(XLS_FILENAME,formatting_info=True)
-
 
947
    wb = copy(rb)
-
 
948
    worksheet = wb.add_sheet("All Users")
-
 
949
    #worksheet1 = wb.add_sheet("Suspected Users")
946
    #worksheet1 = wb.add_sheet("Suspected Users")
950
    workbook = xlwt.Workbook("utf8")
947
    workbook = xlwt.Workbook("ISO8859-1")
951
    sh1 = workbook.add_sheet("All Orders")
948
    sh1 = workbook.add_sheet("All Orders")
952
    sh2 = workbook.add_sheet("Flipkart Orders")
949
    sh2 = workbook.add_sheet("Flipkart Orders")
-
 
950
    worksheet = workbook.add_sheet("All Users")
953
    
951
    
954
    db=client.Dtr
952
    db=client.Dtr
955
#     results = Mysql.fetchResult('''
-
 
956
#         select ow.*, u.username, crm1.order_count, u.referrer, aua.city,aua.state,aua.pincode from order_view ow 
-
 
957
#         left join users u on u.id = ow.user_id 
-
 
958
#         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
-
 
959
#         left join (select * from (select * from all_user_addresses order by source) s group by user_id)aua on aua.user_id=u.id 
-
 
960
#         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'); 
-
 
961
#         
-
 
962
#         ''',)
-
 
963
#     con = MySQLdb.connect('localhost','root','shop2020','dtr')
-
 
964
#     cur = con.cursor()
-
 
965
#     cur.execute("select * from allorder")
953
    prevDate = date.today() - timedelta(days=61)
966
#     results = cur.fetchall()
-
 
967
    results = Mysql.fetchResult("select * from allorder")
954
    results = Mysql.fetchResult("select * from allorder where created_on > %s", prevDate)
968
    row = 0
955
    row = 0
969
    i=-1
956
    i=-1
970
    worksheet.write(row, inc(), 'User Id', boldStyle)
957
    worksheet.write(row, inc(), 'User Id', boldStyle)
971
    #worksheet1.write(row, i, 'User Id', boldStyle)
-
 
972
    worksheet.write(row, inc(), 'User name', boldStyle)
958
    worksheet.write(row, inc(), 'User name', boldStyle)
973
    #worksheet1.write(row, i, 'User name', boldStyle)
-
 
974
    worksheet.write(row, inc(), 'Order Id', boldStyle)
959
    worksheet.write(row, inc(), 'Order Id', boldStyle)
975
    #worksheet1.write(row, i, 'Order Id', boldStyle)
-
 
976
    worksheet.write(row, inc(), 'Created On', boldStyle)
960
    worksheet.write(row, inc(), 'Created On', boldStyle)
977
    #worksheet1.write(row, i, 'Created On', boldStyle)
-
 
978
    worksheet.write(row, inc(), 'Store Id', boldStyle)
961
    worksheet.write(row, inc(), 'Store Id', boldStyle)
979
    #worksheet1.write(row, i, 'Store Id', boldStyle)
-
 
980
    worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
962
    worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
981
    worksheet.write(row, inc(), 'SubOrder Id', boldStyle)
963
    worksheet.write(row, inc(), 'SubOrder Id', boldStyle)
982
    #worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
-
 
983
    worksheet.write(row, inc(), 'Product title', boldStyle)
964
    worksheet.write(row, inc(), 'Product title', boldStyle)
984
    #worksheet1.write(row, i, 'Product title', boldStyle)
-
 
985
    worksheet.write(row, inc(), 'Amount Paid', boldStyle)
965
    worksheet.write(row, inc(), 'Amount Paid', boldStyle)
986
    #worksheet1.write(row, i, 'Amount Paid', boldStyle)
-
 
987
    worksheet.write(row, inc(), 'Cashback', boldStyle)
966
    worksheet.write(row, inc(), 'Cashback', boldStyle)
988
    #worksheet1.write(row, i, 'Cashback', boldStyle)
-
 
989
    worksheet.write(row, inc(), 'Order Status', boldStyle)
967
    worksheet.write(row, inc(), 'Order Status', boldStyle)
990
    #worksheet1.write(row, i, 'Order Status', boldStyle)
-
 
991
    worksheet.write(row, inc(), 'Detailed Status', boldStyle)
968
    worksheet.write(row, inc(), 'Detailed Status', boldStyle)
992
    #worksheet1.write(row, i, 'Detailed Status', boldStyle)
-
 
993
    worksheet.write(row, inc(), 'Cashback Status', boldStyle)
969
    worksheet.write(row, inc(), 'Cashback Status', boldStyle)
994
    #worksheet1.write(row, i, 'Cashback Status', boldStyle)
-
 
995
    worksheet.write(row, inc(), 'Reconciled', boldStyle)
970
    worksheet.write(row, inc(), 'Reconciled', boldStyle)
996
    #worksheet1.write(row, i, 'Reconciled', boldStyle)
-
 
997
    worksheet.write(row, inc(), 'IP', boldStyle)
971
    worksheet.write(row, inc(), 'IP', boldStyle)
998
    #worksheet1.write(row, i, 'IP', boldStyle)
-
 
999
    worksheet.write(row, inc(), 'Aff Status', boldStyle)
972
    worksheet.write(row, inc(), 'Aff Status', boldStyle)
1000
    #worksheet1.write(row, i, 'Aff Status', boldStyle)
-
 
1001
    i=-1
973
    i=-1
1002
    sh1.write(row, inc(), 'User Id', boldStyle)
974
    sh1.write(row, inc(), 'User Id', boldStyle)
1003
    sh1.write(row, inc(), 'User name', boldStyle)
975
    sh1.write(row, inc(), 'User name', boldStyle)
1004
    sh1.write(row, inc(), 'Order Id', boldStyle)
976
    sh1.write(row, inc(), 'Order Id', boldStyle)
1005
    sh1.write(row, inc(), 'Created On', boldStyle)
977
    sh1.write(row, inc(), 'Created On', boldStyle)
Line 1020... Line 992...
1020
    sh1.write(row, inc(), 'DP', boldStyle)
992
    sh1.write(row, inc(), 'DP', boldStyle)
1021
    sh1.write(row, inc(), 'Item status', boldStyle)
993
    sh1.write(row, inc(), 'Item status', boldStyle)
1022
    sh1.write(row, inc(), 'City', boldStyle)
994
    sh1.write(row, inc(), 'City', boldStyle)
1023
    sh1.write(row, inc(), 'State', boldStyle)
995
    sh1.write(row, inc(), 'State', boldStyle)
1024
    sh1.write(row, inc(), 'Pincode', boldStyle)
996
    sh1.write(row, inc(), 'Pincode', boldStyle)
-
 
997
    sh1.write(row, inc(), 'SubOrder Id', boldStyle)
-
 
998
    sh1.write(row, inc(), 'Cashback Status', boldStyle)
-
 
999
    sh1.write(row, inc(), 'Cashback Amount', boldStyle)
1025
    i =-1
1000
    i =-1
1026
    sh2.write(row, inc(), 'User Id', boldStyle)
1001
    sh2.write(row, inc(), 'User Id', boldStyle)
1027
    sh2.write(row, inc(), 'User name', boldStyle)
1002
    sh2.write(row, inc(), 'User name', boldStyle)
1028
    sh2.write(row, inc(), 'Created On', boldStyle)
1003
    sh2.write(row, inc(), 'Created On', boldStyle)
1029
    sh2.write(row, inc(), 'Store', boldStyle)
1004
    sh2.write(row, inc(), 'Store', boldStyle)
Line 1034... Line 1009...
1034
    sh2.write(row, inc(), 'Catalog Id', boldStyle)
1009
    sh2.write(row, inc(), 'Catalog Id', boldStyle)
1035
    sh2.write(row, inc(), 'Brand', boldStyle)
1010
    sh2.write(row, inc(), 'Brand', boldStyle)
1036
    sh2.write(row, inc(), 'Model', boldStyle)
1011
    sh2.write(row, inc(), 'Model', boldStyle)
1037
    sh2.write(row, inc(), 'Category', boldStyle)
1012
    sh2.write(row, inc(), 'Category', boldStyle)
1038
    
1013
    
1039
    row=0
-
 
1040
    row2=0
-
 
1041
    row3=0
-
 
1042
    db1 = client.Catalog
1014
    default_format = xlwt.XFStyle()
1043
    for result in results:
-
 
1044
        morder = db.merchantOrder.find_one({"orderId":result[2]})
-
 
1045
        if morder is not None:
1015
    date_format = xlwt.XFStyle()
1046
            subOrders = morder.get("subOrders")
-
 
1047
            if subOrders is not None:
-
 
1048
                for  subOrder in subOrders:
1016
    date_format.num_format_str = 'dd/mm/yyyy'
1049
                    row3+=1
-
 
1050
                    i=-1
1017
    
1051
#                     sh1.write(row3, inc(), result[1])
-
 
1052
#                     sh1.write(row3, inc(), result[7])
-
 
1053
#                     sh1.write(row3, inc(), result[0])
-
 
1054
#                     sh1.write(row3, inc(), result[6], datetime_format)
-
 
1055
#                     sh1.write(row3, inc(), sourceMap.get(result[2]))
-
 
1056
#                     sh1.write(row3, inc(), morder.get("merchantOrderId"))
-
 
1057
#                     sh1.write(row3, inc(), subOrder.get("status"))
-
 
1058
#                     sh1.write(row3, inc(), subOrder.get("detailedStatus"))
-
 
1059
#                     sh1.write(row3, inc(), subOrder.get("productTitle"))
-
 
1060
#                     sh1.write(row3, inc(), result[9])
-
 
1061
                    sh1.write(row3, inc(), result[0])
-
 
1062
                    sh1.write(row3, inc(), result[1])
-
 
1063
                    sh1.write(row3, inc(), result[2])
-
 
1064
                    sh1.write(row3, inc(), result[3])
-
 
1065
                    sh1.write(row3, inc(), result[4])
-
 
1066
                    sh1.write(row3, inc(), result[5])
-
 
1067
                    sh1.write(row3, inc(), result[6])
-
 
1068
                    sh1.write(row3, inc(), result[7])
-
 
1069
                    sh1.write(row3, inc(), result[8])
-
 
1070
                    sh1.write(row3, inc(), result[9])
-
 
1071
                    sh1.write(row3, inc(), result[10])
-
 
1072
                    inc()
-
 
1073
#                     if int(subOrder.get("quantity")) > 0:
-
 
1074
#                         sh1.write(row3, i, int(subOrder.get("amountPaid"))/int(subOrder.get("quantity")))
-
 
1075
#                     skuData = getSkuData(morder.get("storeId"), subOrder.get("productCode"))
-
 
1076
#                     if morder.get("storeId") in (1,2,4,5,6):
-
 
1077
#                         skuData = db1.MasterData.find_one({'identifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
-
 
1078
#                     elif morder.get("storeId") == 3:
-
 
1079
#                         skuData = db1.MasterData.find_one({'secondaryIdentifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
-
 
1080
#                     if skuData is not None:
-
 
1081
#                         sh1.write(row3, inc(), skuData.get("skuBundleId"))
-
 
1082
#                         sh1.write(row3, inc(), skuData.get("brand"))
-
 
1083
#                         sh1.write(row3, inc(), skuData.get("model_name"))
-
 
1084
#                         sh1.write(row3, inc(), skuData.get("category"))
-
 
1085
#                         sh1.write(row3, inc(), subOrder.get("dealRank"))
-
 
1086
#                         sh1.write(row3, inc(), subOrder.get("maxNlc"))
-
 
1087
#                         sh1.write(row3, inc(), subOrder.get("minNlc"))
-
 
1088
#                         sh1.write(row3, inc(), utils.statusMap.get(subOrder.get("db")))
-
 
1089
#                                   
1018
    datetime_format = xlwt.XFStyle()
1090
#                         sh1.write(row3, inc(), subOrder.get("itemStatus"))
-
 
1091
#                     else:
-
 
1092
#                         sh1.write(row3, inc(), None)
-
 
1093
#                         sh1.write(row3, inc(), None)
-
 
1094
#                         sh1.write(row3, inc(), None)
-
 
1095
#                         sh1.write(row3, inc(), None)
-
 
1096
#                         sh1.write(row3, inc(), None)
-
 
1097
#                         sh1.write(row3, inc(), None)
-
 
1098
#                         sh1.write(row3, inc(), None)
-
 
1099
#                         sh1.write(row3, inc(), None)
-
 
1100
#                         sh1.write(row3, inc(), None)
-
 
1101
                    sh1.write(row3, inc(), result[11])
-
 
1102
                    sh1.write(row3, inc(), result[12])
-
 
1103
                    sh1.write(row3, inc(), result[13])
-
 
1104
                    sh1.write(row3, inc(), result[14])
-
 
1105
                    sh1.write(row3, inc(), result[15])
-
 
1106
                    sh1.write(row3, inc(), result[16])
-
 
1107
                    sh1.write(row3, inc(), result[17])
-
 
1108
                    sh1.write(row3, inc(), result[18])
-
 
1109
                    sh1.write(row3, inc(), result[19])
1019
    datetime_format.num_format_str = 'dd/mm/yyyy HH:MM AM/PM'
1110
#                     print result[10]
-
 
1111
#                     sh1.write(row3, inc(), unicode(result[10], errors='ignore') if result[10] else None)
-
 
1112
#                     sh1.write(row3, inc(), result[11])
-
 
1113
#                     sh1.write(row3, inc(), result[12])
-
 
1114
 
1020
    
1115
                    sh1.write(row3, inc(), unicode(result[20], errors='ignore') if result[20] else None)
-
 
1116
                    sh1.write(row3, inc(), result[21])
-
 
1117
                    sh1.write(row3, inc(), result[22])
-
 
1118
                        
-
 
1119
                    #removed filter as requested by Rajneesh
-
 
1120
                    #if subOrder.get("cashBackStatus") == Store.CB_APPROVED or subOrder.get("cashBackStatus") == Store.CB_PENDING:
-
 
1121
                    row +=1
1021
    number_format = xlwt.XFStyle()
1122
                    i=-1
-
 
1123
#                     worksheet.write(row, inc(), result[0])
1022
    number_format.num_format_str = '#,##0'
1124
#                     worksheet.write(row, inc(), result[7])
-
 
1125
#                     worksheet.write(row, inc(), result[1])
-
 
1126
#                     worksheet.write(row, inc(), result[6], datetime_format)
-
 
1127
#                     worksheet.write(row, inc(), result[2])
-
 
1128
#                     worksheet.write(row, inc(), morder.get("merchantOrderId"))
-
 
1129
#                     worksheet.write(row, inc(), subOrder.get("merchantSubOrderId"))                    
-
 
1130
#                     worksheet.write(row, inc(), subOrder.get("productTitle"))
-
 
1131
#                     worksheet.write(row, inc(), subOrder.get("amountPaid"))
-
 
1132
#                     worksheet.write(row, inc(), subOrder.get("cashBackAmount"))
-
 
1133
#                     worksheet.write(row, inc(), subOrder.get("status"))
-
 
1134
#                     worksheet.write(row, inc(), subOrder.get("detailedStatus"))
-
 
1135
#                     worksheet.write(row, inc(), subOrder.get("cashBackStatus"))
-
 
1136
 
1023
 
1137
                    worksheet.write(row, inc(), result[2])
-
 
1138
                    worksheet.write(row, inc(), result[1])
-
 
1139
                    worksheet.write(row, inc(), result[0])
-
 
1140
                    worksheet.write(row, inc(), result[3])
-
 
1141
                    worksheet.write(row, inc(), result[4])
-
 
1142
                    worksheet.write(row, inc(), result[5])
-
 
1143
                    worksheet.write(row, inc(), result[23])
-
 
1144
                    worksheet.write(row, inc(), result[8])
-
 
1145
                    worksheet.write(row, inc(), result[10])
-
 
1146
                    worksheet.write(row, inc(), result[25])
-
 
1147
                    worksheet.write(row, inc(), result[6])
-
 
1148
                    worksheet.write(row, inc(), result[7])
-
 
1149
                    worksheet.write(row, inc(), result[24])
-
 
1150
                    worksheet.write(row, inc(), result[8])
-
 
1151
 
1024
 
1152
                    #worksheet.write(row, inc(), False if morder.get("reconciled") is None else True)
-
 
-
 
1025
    row=0
-
 
1026
    row3=0
1153
                    #if morder.get("reconciled") and morder.get("storeId")==3:
1027
    for r in results:
1154
                    #    try:
1028
        row += 1
1155
                    #        snapdealafinfo = db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True})
-
 
1156
                    #        worksheet.write(row, inc(), snapdealafinfo.get("ip"))
1029
        column = 0
1157
                    #        worksheet.write(row, inc(), snapdealafinfo.get("conversionStatus"))
-
 
1158
                    #    except:
1030
        for data in r :
1159
                    #        print "Could not find", morder.get("adId"), "that is reconciled for order", morder.get("orderId")
1031
            sh1.write(row, column, int(data) if type(data) is float else data, datetime_format if type(data) is datetime else default_format)
1160
                    #if result[8] >= 10:
-
 
1161
                    #    row2 +=1 
1032
            column += 1
1162
                    #    i=-1
1033
        i=-1
1163
                        #worksheet1.write(row2, inc(), result[0])
1034
        worksheet.write(row, inc(), r[0])
1164
                        #worksheet1.write(row2, inc(), result[7])
1035
        worksheet.write(row, inc(), r[1])
1165
                        #worksheet1.write(row2, inc(), result[1])
1036
        worksheet.write(row, inc(), r[2])
1166
                        #worksheet1.write(row2, inc(), result[6], datetime_format)
1037
        worksheet.write(row, inc(), r[3], datetime_format)
1167
                        #worksheet1.write(row2, inc(), result[2])
1038
        worksheet.write(row, inc(), r[4])
1168
                        #worksheet1.write(row2, inc(), morder.get("merchantOrderId"))
1039
        worksheet.write(row, inc(), r[5])
1169
                        #worksheet1.write(row2, inc(), subOrder.get("productTitle"))
1040
        worksheet.write(row, inc(), r[23])
1170
                        #worksheet1.write(row2, inc(), subOrder.get("amountPaid"))
1041
        worksheet.write(row, inc(), r[8])
1171
                        #worksheet1.write(row2, inc(), subOrder.get("cashBackAmount"))
1042
        worksheet.write(row, inc(), r[10])
1172
                        #worksheet1.write(row2, inc(), subOrder.get("status"))
1043
        worksheet.write(row, inc(), r[25])
1173
                        #worksheet1.write(row2, inc(), subOrder.get("detailedStatus"))
1044
        worksheet.write(row, inc(), r[6])
1174
                        #worksheet1.write(row2, inc(), subOrder.get("cashBackStatus"))
1045
        worksheet.write(row, inc(), r[7])
1175
                        #worksheet1.write(row2, inc(), False if morder.get("reconciled") is None else True)
-
 
1176
                        #worksheet1.write(row2, inc(), )
1046
        worksheet.write(row, inc(), r[24])
1177
                        #if morder.get("reconciled") and morder.get("storeId")==3:
-
 
1178
                        #    try:
-
 
1179
                        #        snapdealafinfo = db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True})
-
 
1180
                        #        worksheet1.write(row2, inc(), snapdealafinfo.get("ip"))
-
 
1181
                        #        worksheet1.write(row2, inc(), snapdealafinfo.get("conversionStatus"))
-
 
1182
                        #    except:
-
 
1183
                        #        print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
-
 
1184
                                
1047
                                
1185
    flipkartOrders = session.query(FlipkartOrders).order_by(FlipkartOrders.created.desc()).all()
1048
    flipkartOrders = session.query(FlipkartOrders).order_by(FlipkartOrders.created.desc()).all()
1186
    flipkartOrders.reverse()
1049
    flipkartOrders.reverse()
1187
    row3=0
1050
    row3=0
1188
    #try:
1051
    #try:
Line 1200... Line 1063...
1200
        sh2.write(row3, inc(), order.catalogId)
1063
        sh2.write(row3, inc(), order.catalogId)
1201
        sh2.write(row3, inc(), order.brand)
1064
        sh2.write(row3, inc(), order.brand)
1202
        sh2.write(row3, inc(), order.model)
1065
        sh2.write(row3, inc(), order.model)
1203
        sh2.write(row3, inc(), order.category)
1066
        sh2.write(row3, inc(), order.category)
1204
                    
1067
                    
1205
    wb.save(XLS_FILENAME)
-
 
1206
    workbook.save(XLS_O_FILENAME)
1068
    workbook.save(XLS_O_FILENAME)
1207
    
1069
    
1208
def getSkuData(storeId, identifier):
1070
def getSkuData(storeId, identifier):
1209
    if storeId in (1,2,4,5,6):
1071
    if storeId in (1,2,4,5,6):
1210
        skuData = client.Catalog.MasterData.find_one({'identifier':identifier, 'source_id':storeId})
1072
        skuData = client.Catalog.MasterData.find_one({'identifier':identifier, 'source_id':storeId})
Line 1265... Line 1127...
1265
def addHeaders(sheet):
1127
def addHeaders(sheet):
1266
    global i
1128
    global i
1267
    i = 0
1129
    i = 0
1268
    sheet.write(0, inc(), )
1130
    sheet.write(0, inc(), )
1269
def main():
1131
def main():
1270
    
-
 
1271
    message = generateSnapDealReco()
1132
    #message = generateSnapDealReco()
1272
#     message ="Kuch nahi"
-
 
1273
    generateFlipkartReco()
1133
    #generateFlipkartReco()
1274
    generateShopcluesReco()
1134
    #generateShopcluesReco()
1275
    generateAmazonReco(XLS_A_FILENAME)
1135
    #generateAmazonReco(XLS_A_FILENAME)
1276
    message1 = getdata.summaryByBrandAndStore()
1136
    message1 = getdata.summaryByBrandAndStore()
1277
    getUserOrders()
1137
    getUserOrders()
1278
    #getdata.sendmail(["naman.kumar@shop2020.in"], message1, "Summary by brand and store")
1138
    #getdata.sendmail(["naman.kumar@shop2020.in"], message1, "Summary by brand and store")
1279
    #sendmail(["naman.kumar@shop2020.in"], message, "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
1139
    #sendmail(["naman.kumar@shop2020.in"], message, "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
1280
    #sendmail(["naman.kumar@shop2020.in"], message1, "All DTR Orders", XLS_O_FILENAME)
1140
    #sendmail(["naman.kumar@shop2020.in"], message1, "All DTR Orders", XLS_O_FILENAME)
Line 1360... Line 1220...
1360
    for key,valmap in  datemap.iteritems():
1220
    for key,valmap in  datemap.iteritems():
1361
        valmap['_id'] = key
1221
        valmap['_id'] = key
1362
        db.flSaleSnapshot.save(valmap)
1222
        db.flSaleSnapshot.save(valmap)
1363
 
1223
 
1364
if __name__ == '__main__':
1224
if __name__ == '__main__':
1365
#     getdata.addToAllOrders(date.today()-timedelta(days=30))
1225
    getdata.addToAllOrders(date.today()-timedelta(days=30))
1366
#     main2()
1226
    main2()
1367
    main()
1227
    main()