| 14450 |
amit.gupta |
1 |
'''
|
|
|
2 |
Created on Mar 13, 2015
|
|
|
3 |
|
|
|
4 |
@author: amit
|
|
|
5 |
'''
|
|
|
6 |
from datetime import date, datetime, timedelta
|
| 14632 |
amit.gupta |
7 |
from dtr.main import Store, sourceMap
|
| 14650 |
amit.gupta |
8 |
from dtr.reports.amazonreco import generateAmazonReco
|
| 15445 |
amit.gupta |
9 |
from dtr.storage import Mysql, DataService
|
| 15932 |
amit.gupta |
10 |
from dtr.storage.DataService import Users, Clicks, FlipkartOrders,\
|
|
|
11 |
All_user_addresses
|
| 14613 |
amit.gupta |
12 |
from dtr.storage.Mysql import getOrdersAfterDate, getOrdersByTag
|
| 16947 |
amit.gupta |
13 |
from dtr.utils import utils
|
| 15423 |
amit.gupta |
14 |
from elixir import *
|
| 15440 |
amit.gupta |
15 |
from sqlalchemy.sql.expression import func, func, or_
|
| 14450 |
amit.gupta |
16 |
from email import encoders
|
|
|
17 |
from email.mime.base import MIMEBase
|
|
|
18 |
from email.mime.multipart import MIMEMultipart
|
|
|
19 |
from email.mime.text import MIMEText
|
|
|
20 |
from pymongo.mongo_client import MongoClient
|
| 14460 |
amit.gupta |
21 |
from xlrd import open_workbook
|
| 14524 |
amit.gupta |
22 |
from xlutils.copy import copy
|
| 14460 |
amit.gupta |
23 |
from xlwt.Workbook import Workbook
|
| 14450 |
amit.gupta |
24 |
import MySQLdb
|
|
|
25 |
import smtplib
|
|
|
26 |
import time
|
|
|
27 |
import xlwt
|
| 16317 |
amit.gupta |
28 |
from dtr.utils import utils
|
| 17001 |
amit.gupta |
29 |
from dtr.utils.utils import toTimeStamp
|
| 14460 |
amit.gupta |
30 |
#from xlwt import
|
| 14450 |
amit.gupta |
31 |
|
| 15445 |
amit.gupta |
32 |
DataService.initialize()
|
| 14450 |
amit.gupta |
33 |
client = MongoClient('mongodb://localhost:27017/')
|
|
|
34 |
|
|
|
35 |
SENDER = "cnc.center@shop2020.in"
|
|
|
36 |
PASSWORD = "5h0p2o2o"
|
|
|
37 |
SUBJECT = "DTR User Segmentation report for " + date.today().isoformat()
|
|
|
38 |
SMTP_SERVER = "smtp.gmail.com"
|
|
|
39 |
SMTP_PORT = 587
|
|
|
40 |
|
| 14647 |
amit.gupta |
41 |
XLS_FILENAME = "snapdealaffiliatereco.xls"
|
| 14632 |
amit.gupta |
42 |
XLS_O_FILENAME = "allorders.xls"
|
| 14647 |
amit.gupta |
43 |
XLS_F_FILENAME = "flipkartaffiliatereco.xls"
|
| 14650 |
amit.gupta |
44 |
XLS_A_FILENAME = "amazonaffiliatereco.xls"
|
| 15791 |
manish.sha |
45 |
XLS_SC_FILENAME = "shopcluesaffiliatereco.xls"
|
| 14460 |
amit.gupta |
46 |
boldStyle = xlwt.XFStyle()
|
|
|
47 |
f = xlwt.Font()
|
|
|
48 |
f.bold = True
|
|
|
49 |
boldStyle.font = f
|
|
|
50 |
i = -1
|
| 14616 |
amit.gupta |
51 |
|
|
|
52 |
datetime_format = xlwt.XFStyle()
|
|
|
53 |
datetime_format.num_format_str = 'dd/mm/yyyy HH:MM AM/PM'
|
| 15540 |
amit.gupta |
54 |
categoryMap = {3:"Mobiles", 5:"Tablets"}
|
| 14450 |
amit.gupta |
55 |
def generateFlipkartReco():
|
| 14508 |
amit.gupta |
56 |
global i
|
|
|
57 |
i = -1
|
| 14460 |
amit.gupta |
58 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 2)
|
|
|
59 |
db = client.Dtr
|
| 14647 |
amit.gupta |
60 |
wb = xlwt.Workbook()
|
|
|
61 |
#rb = open_workbook(XLS_F_FILENAME)
|
|
|
62 |
#wb = copy(rb)
|
| 14460 |
amit.gupta |
63 |
#wb = xlwt.Workbook()
|
|
|
64 |
row = 0
|
| 14647 |
amit.gupta |
65 |
row2 = 0
|
|
|
66 |
row3 = 0
|
|
|
67 |
row4 = 0
|
|
|
68 |
worksheet = wb.add_sheet("All Orders")
|
|
|
69 |
worksheet1 = wb.add_sheet("Orders Reconciled")
|
|
|
70 |
worksheet2 = wb.add_sheet("Orders not Reconciled")
|
|
|
71 |
worksheet3 = wb.add_sheet("Aff not Reconciled")
|
| 14460 |
amit.gupta |
72 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
| 14647 |
amit.gupta |
73 |
worksheet1.write(row, i, 'Order Id', boldStyle)
|
|
|
74 |
worksheet2.write(row, i, 'Order Id', boldStyle)
|
| 14460 |
amit.gupta |
75 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14647 |
amit.gupta |
76 |
worksheet1.write(row, i, 'User Id', boldStyle)
|
|
|
77 |
worksheet2.write(row, i, 'User Id', boldStyle)
|
| 14474 |
amit.gupta |
78 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
| 14647 |
amit.gupta |
79 |
worksheet1.write(row, i, 'Username', boldStyle)
|
|
|
80 |
worksheet2.write(row, i, 'Username', boldStyle)
|
| 14771 |
amit.gupta |
81 |
worksheet.write(row, inc(), 'Version code', boldStyle)
|
|
|
82 |
worksheet1.write(row, i, 'Version code', boldStyle)
|
|
|
83 |
worksheet2.write(row, i, 'Version code', boldStyle)
|
|
|
84 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
|
|
85 |
worksheet1.write(row, i, 'Device', boldStyle)
|
|
|
86 |
worksheet2.write(row, i, 'Device', boldStyle)
|
| 14460 |
amit.gupta |
87 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14647 |
amit.gupta |
88 |
worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
|
|
89 |
worksheet2.write(row, i, 'Merchant Order Id', boldStyle)
|
| 14460 |
amit.gupta |
90 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
| 14647 |
amit.gupta |
91 |
worksheet1.write(row, i, 'Product Title', boldStyle)
|
|
|
92 |
worksheet2.write(row, i, 'Product Title', boldStyle)
|
| 14460 |
amit.gupta |
93 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
| 14647 |
amit.gupta |
94 |
worksheet1.write(row, i, 'Price', boldStyle)
|
|
|
95 |
worksheet2.write(row, i, 'Price', boldStyle)
|
| 14460 |
amit.gupta |
96 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
| 14647 |
amit.gupta |
97 |
worksheet1.write(row, i, 'Quantity', boldStyle)
|
|
|
98 |
worksheet2.write(row, i, 'Quantity', boldStyle)
|
| 14460 |
amit.gupta |
99 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
| 14647 |
amit.gupta |
100 |
worksheet1.write(row, i, 'Status', boldStyle)
|
|
|
101 |
worksheet2.write(row, i, 'Status', boldStyle)
|
| 14460 |
amit.gupta |
102 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
| 14647 |
amit.gupta |
103 |
worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
|
|
104 |
worksheet2.write(row, i, 'Detailed Status', boldStyle)
|
| 14460 |
amit.gupta |
105 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
| 14647 |
amit.gupta |
106 |
worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
|
|
107 |
worksheet2.write(row, i, 'Cashback Status', boldStyle)
|
| 14460 |
amit.gupta |
108 |
worksheet.write(row, inc(), 'Our CashBack', boldStyle)
|
| 14647 |
amit.gupta |
109 |
worksheet1.write(row, i, 'Our CashBack', boldStyle)
|
|
|
110 |
worksheet2.write(row, i, 'Our CashBack', boldStyle)
|
|
|
111 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
112 |
worksheet1.write(row, i, 'Sale Date', boldStyle)
|
|
|
113 |
worksheet2.write(row, i, 'Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
114 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
| 14647 |
amit.gupta |
115 |
worksheet1.write(row, i, 'SubtagId', boldStyle)
|
|
|
116 |
worksheet2.write(row, i, 'SubtagId', boldStyle)
|
| 14460 |
amit.gupta |
117 |
worksheet.write(row, inc(), 'Category', boldStyle)
|
| 14647 |
amit.gupta |
118 |
worksheet1.write(row, i, 'Category', boldStyle)
|
| 14460 |
amit.gupta |
119 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14647 |
amit.gupta |
120 |
worksheet1.write(row, i, 'Aff PayOut', boldStyle)
|
| 14460 |
amit.gupta |
121 |
worksheet.write(row, inc(), 'Aff Sale Amount', boldStyle)
|
| 14647 |
amit.gupta |
122 |
worksheet1.write(row, i, 'Aff Sale Amount', boldStyle)
|
| 14460 |
amit.gupta |
123 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
| 14647 |
amit.gupta |
124 |
worksheet1.write(row, i, 'Aff Sale Date', boldStyle)
|
| 14460 |
amit.gupta |
125 |
for row1 in curs:
|
|
|
126 |
orderId = row1[0]
|
|
|
127 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
128 |
if order is None:
|
|
|
129 |
continue
|
|
|
130 |
saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%d %B, %Y %I:%M %p").replace(hour=0, minute=0, second=0, microsecond=0).timetuple()))
|
|
|
131 |
#saleTime1 = int(time.mktime((datetime.strptime(order['placedOn'], "%b %d, %Y %I:%M %p") + timedelta(seconds=-60)).timetuple()))
|
| 14647 |
amit.gupta |
132 |
reconciled_affiliates = []
|
| 14460 |
amit.gupta |
133 |
for subOrder in order['subOrders']:
|
| 14647 |
amit.gupta |
134 |
affs = list(db.flipkartOrderAffiliateInfo.find({"productCode":subOrder.get("productCode"), "saleDateInt":saleTime}))
|
| 14460 |
amit.gupta |
135 |
row += 1
|
|
|
136 |
i=-1
|
|
|
137 |
worksheet.write(row, inc(), orderId)
|
|
|
138 |
worksheet.write(row, inc(), row1[1])
|
| 14474 |
amit.gupta |
139 |
worksheet.write(row, inc(), row1[-1])
|
| 14771 |
amit.gupta |
140 |
worksheet.write(row, inc(), row1[-2])
|
|
|
141 |
worksheet.write(row, inc(), row1[-3])
|
| 14460 |
amit.gupta |
142 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
143 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
144 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
145 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
146 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
147 |
worksheet.write(row, inc(), subOrder['detailedStatus'])
|
|
|
148 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
149 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
150 |
worksheet.write(row, inc(), subOrder['placedOn'])
|
|
|
151 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
152 |
for aff in affs:
|
| 14647 |
amit.gupta |
153 |
if aff["_id"] not in reconciled_affiliates and aff['subTagId']== order['subTagId']:
|
|
|
154 |
reconciled_affiliates.append(aff["_id"])
|
|
|
155 |
row2 += 1
|
|
|
156 |
i = -1
|
|
|
157 |
worksheet1.write(row2, inc(), orderId)
|
|
|
158 |
worksheet1.write(row2, inc(), row1[1])
|
|
|
159 |
worksheet1.write(row2, inc(), row1[-1])
|
| 14771 |
amit.gupta |
160 |
worksheet1.write(row2, inc(), row1[-2])
|
|
|
161 |
worksheet1.write(row2, inc(), row1[-3])
|
| 14647 |
amit.gupta |
162 |
worksheet1.write(row2, inc(), order['merchantOrderId'])
|
|
|
163 |
worksheet1.write(row2, inc(), subOrder['productTitle'])
|
|
|
164 |
worksheet1.write(row2, inc(), subOrder['amountPaid'])
|
|
|
165 |
worksheet1.write(row2, inc(), subOrder['quantity'])
|
|
|
166 |
worksheet1.write(row2, inc(), subOrder['status'])
|
|
|
167 |
worksheet1.write(row2, inc(), subOrder['detailedStatus'])
|
|
|
168 |
worksheet1.write(row2, inc(), subOrder['cashBackStatus'])
|
|
|
169 |
worksheet1.write(row2, inc(), subOrder['cashBackAmount'])
|
|
|
170 |
worksheet1.write(row2, inc(), subOrder['placedOn'])
|
|
|
171 |
worksheet1.write(row2, inc(), order['subTagId'])
|
|
|
172 |
db.flipkartOrderAffiliateInfo.update(
|
|
|
173 |
{"productCode":subOrder.get("productCode"), "saleDateInt":saleTime, "subTagId":aff['subTagId']},
|
|
|
174 |
{"$set":{"reconciled":True}})
|
|
|
175 |
db.merchantOrder.update({"merchantOrderId":order["merchantOrderId"]},
|
|
|
176 |
{"$set":{"reconciled":True}})
|
| 14460 |
amit.gupta |
177 |
worksheet.write(row, inc(), aff['category'])
|
| 14647 |
amit.gupta |
178 |
worksheet1.write(row2, i, aff['category'])
|
| 14460 |
amit.gupta |
179 |
worksheet.write(row, inc(), aff['payOut'])
|
| 14647 |
amit.gupta |
180 |
worksheet1.write(row2, i, aff['payOut'])
|
| 14460 |
amit.gupta |
181 |
worksheet.write(row, inc(), aff['saleAmount'])
|
| 14647 |
amit.gupta |
182 |
worksheet1.write(row2, i, aff['saleAmount'])
|
| 14460 |
amit.gupta |
183 |
worksheet.write(row, inc(), aff['saleDate'])
|
| 14647 |
amit.gupta |
184 |
worksheet1.write(row2, i, aff['saleDate'])
|
| 14460 |
amit.gupta |
185 |
break
|
| 14647 |
amit.gupta |
186 |
row3 += 1
|
|
|
187 |
i=-1
|
|
|
188 |
worksheet2.write(row3, inc(), orderId)
|
|
|
189 |
worksheet2.write(row3, inc(), row1[1])
|
|
|
190 |
worksheet2.write(row3, inc(), row1[-1])
|
| 14771 |
amit.gupta |
191 |
worksheet2.write(row3, inc(), row1[-2])
|
|
|
192 |
worksheet2.write(row3, inc(), row1[-3])
|
| 14647 |
amit.gupta |
193 |
worksheet2.write(row3, inc(), order['merchantOrderId'])
|
|
|
194 |
worksheet2.write(row3, inc(), subOrder['productTitle'])
|
|
|
195 |
worksheet2.write(row3, inc(), subOrder['amountPaid'])
|
|
|
196 |
worksheet2.write(row3, inc(), subOrder['quantity'])
|
|
|
197 |
worksheet2.write(row3, inc(), subOrder['status'])
|
|
|
198 |
worksheet2.write(row3, inc(), subOrder['detailedStatus'])
|
|
|
199 |
worksheet2.write(row3, inc(), subOrder['cashBackStatus'])
|
|
|
200 |
worksheet2.write(row3, inc(), subOrder['cashBackAmount'])
|
|
|
201 |
worksheet2.write(row3, inc(), subOrder['placedOn'])
|
|
|
202 |
worksheet2.write(row3, inc(), order['subTagId'])
|
|
|
203 |
|
|
|
204 |
i=-1
|
|
|
205 |
worksheet3.write(0, inc(), "category",boldStyle)
|
|
|
206 |
worksheet3.write(0, inc(), "conversionStatus",boldStyle)
|
|
|
207 |
worksheet3.write(0, inc(), "Product Title",boldStyle)
|
|
|
208 |
worksheet3.write(0, inc(), "price",boldStyle)
|
|
|
209 |
worksheet3.write(0, inc(), "quantity",boldStyle)
|
|
|
210 |
worksheet3.write(0, inc(), "payOut",boldStyle)
|
|
|
211 |
worksheet3.write(0, inc(), "saleDate",boldStyle)
|
|
|
212 |
worksheet3.write(0, inc(), "subTagId",boldStyle)
|
|
|
213 |
for aff in db.flipkartOrderAffiliateInfo.find({"reconciled":{"$exists":False}}):
|
|
|
214 |
row4 += 1
|
|
|
215 |
i =-1
|
|
|
216 |
worksheet3.write(row4, inc(), aff["category"])
|
|
|
217 |
worksheet3.write(row4, inc(), aff["conversionStatus"])
|
|
|
218 |
skuData = getSkuData(2, aff["productCode"])
|
|
|
219 |
if skuData is None:
|
|
|
220 |
worksheet3.write(row4, inc(), aff["productTitle"])
|
|
|
221 |
else:
|
|
|
222 |
worksheet3.write(row4, inc(), skuData["product_name"])
|
|
|
223 |
worksheet3.write(row4, inc(), aff['price'])
|
|
|
224 |
worksheet3.write(row4, inc(), aff['quantity'])
|
|
|
225 |
worksheet3.write(row4, inc(), aff['payOut'])
|
|
|
226 |
worksheet3.write(row4, inc(), aff['saleDate'])
|
|
|
227 |
worksheet3.write(row4, inc(), aff['subTagId'])
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
wb.save(XLS_F_FILENAME)
|
| 14450 |
amit.gupta |
232 |
def generateSnapDealReco():
|
| 14524 |
amit.gupta |
233 |
global i
|
| 14460 |
amit.gupta |
234 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 3)
|
| 14450 |
amit.gupta |
235 |
db = client.Dtr
|
| 14524 |
amit.gupta |
236 |
notReconciled = {}
|
| 14487 |
amit.gupta |
237 |
matchedList = []
|
| 14450 |
amit.gupta |
238 |
workbook = xlwt.Workbook()
|
| 14501 |
amit.gupta |
239 |
worksheet = workbook.add_sheet("Snapdeal Reconciled")
|
|
|
240 |
worksheet1 = workbook.add_sheet("Snapdeal Reconciled All")
|
| 14508 |
amit.gupta |
241 |
worksheet2 = workbook.add_sheet("Snapdeal Orders not reconciled")
|
| 16947 |
amit.gupta |
242 |
worksheet3 = workbook.add_sheet("DateWise Sale Summary")
|
| 14508 |
amit.gupta |
243 |
affNotReconciledSheet = workbook.add_sheet("Snapdeal Aff not reconciled")
|
| 16947 |
amit.gupta |
244 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3)
|
| 14450 |
amit.gupta |
245 |
row = 0
|
| 14501 |
amit.gupta |
246 |
anotherrow = 0
|
| 15577 |
amit.gupta |
247 |
row5=0
|
| 16947 |
amit.gupta |
248 |
datemap={}
|
| 14450 |
amit.gupta |
249 |
for row1 in curs:
|
|
|
250 |
orderId = row1[0]
|
|
|
251 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
252 |
if order is None:
|
|
|
253 |
continue
|
| 14496 |
amit.gupta |
254 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
| 16949 |
amit.gupta |
255 |
try:
|
| 16951 |
amit.gupta |
256 |
saleTime = datetime.strptime(order['placedOn'], "%a, %d %b, %Y").strftime("%Y-%m-%d")
|
| 16949 |
amit.gupta |
257 |
except:
|
| 17001 |
amit.gupta |
258 |
saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").strftime("%Y-%m-%d")
|
| 16947 |
amit.gupta |
259 |
|
| 14450 |
amit.gupta |
260 |
aff = list(db.snapdealOrderAffiliateInfo.find({"subTagId":order["subTagId"]}))
|
| 16718 |
amit.gupta |
261 |
if len(aff) > 1:
|
|
|
262 |
aff = [f for f in aff if f.get("payOut")>0]
|
| 14501 |
amit.gupta |
263 |
anotherrow += 1
|
| 14988 |
amit.gupta |
264 |
try:
|
|
|
265 |
formattedTimestamp = order['placedOn']
|
|
|
266 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
|
|
267 |
except:
|
|
|
268 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
| 16947 |
amit.gupta |
269 |
formattedTimestamp = datetime.strftime(utils.fromTimeStamp(timestamp1), "%b %d, %Y, %I:%M %p")
|
| 16718 |
amit.gupta |
270 |
if len(aff) > 0 and order["subTagId"] not in matchedList and int(order["paidAmount"])==int(aff[0]["saleAmount"]):
|
|
|
271 |
|
| 14501 |
amit.gupta |
272 |
matchedList.append(order["subTagId"])
|
| 14610 |
amit.gupta |
273 |
db.snapdealOrderAffiliateInfo.update({"adId":aff[0].get("adId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 14501 |
amit.gupta |
274 |
order['reconciled'] = True
|
| 14610 |
amit.gupta |
275 |
order['adId'] = aff[0].get("adId")
|
| 14501 |
amit.gupta |
276 |
db.merchantOrder.save(order)
|
|
|
277 |
row += 1
|
|
|
278 |
i=-1
|
|
|
279 |
worksheet.write(row, inc(), orderId)
|
|
|
280 |
worksheet1.write(anotherrow, i, orderId)
|
|
|
281 |
worksheet.write(row, inc(), row1[1])
|
|
|
282 |
worksheet1.write(anotherrow, i, row1[1])
|
| 14850 |
amit.gupta |
283 |
worksheet.write(row, inc(), row1[-1])
|
|
|
284 |
worksheet1.write(anotherrow, i, row1[-1])
|
|
|
285 |
worksheet.write(row, inc(), row1[-2])
|
|
|
286 |
worksheet1.write(anotherrow, i, row1[-2])
|
| 14771 |
amit.gupta |
287 |
worksheet.write(row, inc(), row1[-3])
|
|
|
288 |
worksheet1.write(anotherrow, i, row1[-3])
|
| 14501 |
amit.gupta |
289 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
290 |
worksheet1.write(anotherrow, i, order['merchantOrderId'])
|
|
|
291 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
292 |
worksheet1.write(anotherrow, i, order['subTagId'])
|
|
|
293 |
worksheet.write(row, inc(), order['placedOn'])
|
|
|
294 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
| 14988 |
amit.gupta |
295 |
worksheet.write(row, inc(), formattedTimestamp)
|
|
|
296 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
| 14501 |
amit.gupta |
297 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
298 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
| 14524 |
amit.gupta |
299 |
worksheet.write(row, inc(), aff[0]['saleDate'])
|
|
|
300 |
worksheet1.write(anotherrow, i, aff[0]['saleDate'])
|
|
|
301 |
worksheet.write(row, inc(), aff[0]['saleAmount'])
|
|
|
302 |
worksheet1.write(anotherrow, i, aff[0]['saleAmount'])
|
|
|
303 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
|
|
304 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
| 14601 |
amit.gupta |
305 |
worksheet.write(row, inc(), aff[0]['ip'])
|
|
|
306 |
worksheet1.write(anotherrow, i, aff[0]['ip'])
|
| 16718 |
amit.gupta |
307 |
worksheet.write(row, inc(), aff[0]['conversionStatus'])
|
|
|
308 |
worksheet1.write(anotherrow, i, aff[0]['conversionStatus'])
|
| 14501 |
amit.gupta |
309 |
k = i
|
| 14504 |
amit.gupta |
310 |
row -= 1
|
|
|
311 |
anotherrow -= 1
|
| 14501 |
amit.gupta |
312 |
for subOrder in order['subOrders']:
|
|
|
313 |
i = k
|
| 14503 |
amit.gupta |
314 |
row += 1
|
|
|
315 |
anotherrow += 1
|
| 14501 |
amit.gupta |
316 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
317 |
worksheet1.write(anotherrow, i, subOrder['productTitle'])
|
|
|
318 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
319 |
worksheet1.write(anotherrow, i, subOrder['amountPaid'])
|
|
|
320 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
321 |
worksheet1.write(anotherrow, i, subOrder['quantity'])
|
|
|
322 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
323 |
worksheet1.write(anotherrow, i, subOrder['status'])
|
|
|
324 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
325 |
worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
|
|
|
326 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
327 |
worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
|
| 14504 |
amit.gupta |
328 |
|
| 14501 |
amit.gupta |
329 |
else:
|
| 14524 |
amit.gupta |
330 |
i=-1
|
| 14501 |
amit.gupta |
331 |
worksheet1.write(anotherrow, inc(), orderId)
|
|
|
332 |
worksheet1.write(anotherrow, inc(), row1[1])
|
| 14850 |
amit.gupta |
333 |
worksheet1.write(anotherrow, inc(), row1[-1])
|
|
|
334 |
worksheet1.write(anotherrow, inc(), row1[-2])
|
| 14771 |
amit.gupta |
335 |
worksheet1.write(anotherrow, inc(), row1[-3])
|
| 14501 |
amit.gupta |
336 |
worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
|
|
|
337 |
worksheet1.write(anotherrow, inc(), order['subTagId'])
|
|
|
338 |
worksheet1.write(anotherrow, inc(), order['placedOn'])
|
| 15576 |
amit.gupta |
339 |
worksheet1.write(anotherrow, inc(), formattedTimestamp)
|
| 14501 |
amit.gupta |
340 |
worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
|
| 14873 |
amit.gupta |
341 |
|
| 14524 |
amit.gupta |
342 |
notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"])
|
|
|
343 |
inc()
|
|
|
344 |
inc()
|
|
|
345 |
inc()
|
| 14771 |
amit.gupta |
346 |
inc()
|
| 16718 |
amit.gupta |
347 |
inc()
|
| 14501 |
amit.gupta |
348 |
k = i
|
| 14504 |
amit.gupta |
349 |
anotherrow -= 1
|
| 14501 |
amit.gupta |
350 |
for subOrder in order['subOrders']:
|
| 14503 |
amit.gupta |
351 |
anotherrow += 1
|
| 14501 |
amit.gupta |
352 |
i = k
|
| 14505 |
amit.gupta |
353 |
worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
|
|
|
354 |
worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
|
|
|
355 |
worksheet1.write(anotherrow, inc(), subOrder['quantity'])
|
|
|
356 |
worksheet1.write(anotherrow, inc(), subOrder['status'])
|
|
|
357 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
|
|
|
358 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
|
| 15577 |
amit.gupta |
359 |
row5 += 1
|
|
|
360 |
i=-1
|
|
|
361 |
worksheet2.write(row5, inc(), order["orderId"])
|
|
|
362 |
worksheet2.write(row5, inc(), row1[1])
|
|
|
363 |
worksheet2.write(row5, inc(), row1[-1])
|
|
|
364 |
worksheet2.write(row5, inc(), row1[-2])
|
|
|
365 |
worksheet2.write(row5, inc(), row1[-3])
|
|
|
366 |
worksheet2.write(row5, inc(), order['merchantOrderId'])
|
|
|
367 |
worksheet2.write(row5, inc(), order['subTagId'])
|
|
|
368 |
worksheet2.write(row5, inc(), order['placedOn'])
|
|
|
369 |
worksheet2.write(row5, inc(), formattedTimestamp)
|
|
|
370 |
worksheet2.write(row5, inc(), int(order['paidAmount']))
|
|
|
371 |
row5 -=1
|
|
|
372 |
k=i
|
|
|
373 |
for subOrder in order['subOrders']:
|
|
|
374 |
i = k
|
| 15578 |
amit.gupta |
375 |
row5 += 1
|
| 15577 |
amit.gupta |
376 |
worksheet2.write(row5, inc(), subOrder['productTitle'])
|
|
|
377 |
worksheet2.write(row5, inc(), subOrder['amountPaid'])
|
|
|
378 |
worksheet2.write(row5, inc(), subOrder['quantity'])
|
|
|
379 |
worksheet2.write(row5, inc(), subOrder['status'])
|
|
|
380 |
worksheet2.write(row5, inc(), subOrder['cashBackStatus'])
|
| 15578 |
amit.gupta |
381 |
worksheet2.write(row5, inc(), subOrder['cashBackAmount'])
|
| 14524 |
amit.gupta |
382 |
|
|
|
383 |
last30Days = date.today() - timedelta(days=30)
|
|
|
384 |
int(time.mktime(last30Days.timetuple()))
|
|
|
385 |
row = 0
|
|
|
386 |
for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
387 |
"saleTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
| 16953 |
amit.gupta |
388 |
"$lt":int(time.mktime(date.today().timetuple()))}}, timeout=False ):
|
| 14524 |
amit.gupta |
389 |
subTagId = offer.get("subTagId")
|
|
|
390 |
saleTime = offer.get("saleTime")
|
|
|
391 |
orders = getOrdersByTag(subTagId, 3)
|
|
|
392 |
for order in orders:
|
|
|
393 |
if notReconciled.has_key(order[0]):
|
|
|
394 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
|
|
395 |
if paidAmount==int(offer.get("saleAmount")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
|
|
396 |
i = column
|
| 14570 |
amit.gupta |
397 |
worksheet1.write(roww, inc(), offer.get("saleDate"))
|
| 14527 |
amit.gupta |
398 |
worksheet1.write(roww, inc(), offer.get("saleAmount"))
|
|
|
399 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
|
|
400 |
del notReconciled[order[0]]
|
| 14530 |
amit.gupta |
401 |
print "found match for user", order[1]
|
| 14610 |
amit.gupta |
402 |
db.snapdealOrderAffiliateInfo.update({"adId":offer.get("adId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
|
|
403 |
db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True, "adId":offer.get("adId")}}, multi=True)
|
| 14570 |
amit.gupta |
404 |
break
|
| 14530 |
amit.gupta |
405 |
|
| 14570 |
amit.gupta |
406 |
unreconciledOrders = notReconciled.keys()
|
| 15577 |
amit.gupta |
407 |
|
| 14570 |
amit.gupta |
408 |
|
|
|
409 |
|
|
|
410 |
for offer in db.snapdealOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
411 |
"saleTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
412 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
413 |
row += 1
|
|
|
414 |
i=-1
|
|
|
415 |
affNotReconciledSheet.write(row, inc(), offer.get("adId"))
|
|
|
416 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
|
|
417 |
affNotReconciledSheet.write(row, inc(), offer.get("saleDate"))
|
|
|
418 |
affNotReconciledSheet.write(row, inc(), offer.get("saleAmount"))
|
|
|
419 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
|
|
420 |
affNotReconciledSheet.write(row, inc(), offer.get("conversionStatus"))
|
| 14601 |
amit.gupta |
421 |
affNotReconciledSheet.write(row, inc(), offer.get("ip"))
|
| 16947 |
amit.gupta |
422 |
|
|
|
423 |
|
| 16995 |
amit.gupta |
424 |
message=""
|
| 17001 |
amit.gupta |
425 |
# mailBodyTemplate="""
|
|
|
426 |
# <html>
|
|
|
427 |
# <body>
|
|
|
428 |
# <table cellspacing="0" border="1" style="text-align:right">
|
|
|
429 |
# <thead>
|
|
|
430 |
# <tr>
|
|
|
431 |
# <th style="text-align:center">Date</th>
|
|
|
432 |
# <th style="text-align:center">Sale</th>
|
|
|
433 |
# <th style="text-align:center">Approved</th>
|
|
|
434 |
# <th style="text-align:center">Rejected</th>
|
|
|
435 |
# </tr>
|
|
|
436 |
# </thead>
|
|
|
437 |
# <tbody>
|
|
|
438 |
# {0}
|
|
|
439 |
# </tbody>
|
|
|
440 |
# </table>
|
|
|
441 |
# </body>
|
|
|
442 |
# </html>
|
|
|
443 |
# """
|
|
|
444 |
# tbody=[]
|
|
|
445 |
# rowtemplate="<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>"
|
|
|
446 |
# for offer in db.flSaleSnapshot.find({}):
|
|
|
447 |
# tbody.append(rowtemplate.format(offer.get("_id"), offer.get("paidAmount"), offer.get("saleAmount"), offer.get("rejectedAmount")))
|
|
|
448 |
# message = mailBodyTemplate.format("".join(tbody))
|
| 15540 |
amit.gupta |
449 |
workbook.save(XLS_FILENAME)
|
| 15791 |
manish.sha |
450 |
|
| 16995 |
amit.gupta |
451 |
return message
|
|
|
452 |
|
| 15791 |
manish.sha |
453 |
def generateShopcluesReco():
|
|
|
454 |
global i
|
| 16238 |
manish.sha |
455 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=30), 5)
|
| 15791 |
manish.sha |
456 |
db = client.Dtr
|
|
|
457 |
notReconciled = {}
|
|
|
458 |
matchedList = []
|
|
|
459 |
workbook = xlwt.Workbook()
|
|
|
460 |
worksheet = workbook.add_sheet("Shopclues Reconciled")
|
|
|
461 |
worksheet1 = workbook.add_sheet("Shopclues Reconciled All")
|
|
|
462 |
worksheet2 = workbook.add_sheet("Shopclues Orders not reconciled")
|
|
|
463 |
affNotReconciledSheet = workbook.add_sheet("Shopclues Aff not reconciled")
|
|
|
464 |
setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet)
|
|
|
465 |
row = 0
|
|
|
466 |
anotherrow = 0
|
|
|
467 |
row2 = 0
|
|
|
468 |
row5=0
|
|
|
469 |
|
|
|
470 |
for row1 in curs:
|
|
|
471 |
orderId = row1[0]
|
|
|
472 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
473 |
if order is None:
|
|
|
474 |
continue
|
|
|
475 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple())) 26 May 2015 02:12 PM
|
| 16204 |
manish.sha |
476 |
aff = list(db.shopcluesOrderAffiliateInfo.find({"merchantOrderId":order["merchantOrderId"]}))
|
| 15791 |
manish.sha |
477 |
anotherrow += 1
|
|
|
478 |
try:
|
|
|
479 |
formattedTimestamp = order['placedOn']
|
|
|
480 |
timestamp1 = int(time.mktime(datetime.strptime(order['placedOn'], "%d %b %Y %I:%M %p").timetuple()))
|
|
|
481 |
except:
|
|
|
482 |
timestamp1 = int(time.mktime(row1[-4].timetuple()))
|
| 16947 |
amit.gupta |
483 |
formattedTimestamp = datetime.strftime(utils.fromTimeStamp(timestamp1), "%d %b %Y %I:%M %p")
|
| 15791 |
manish.sha |
484 |
|
|
|
485 |
if len(aff) > 0 and order["subTagId"] not in matchedList and long(order["paidAmount"])==long(float(aff[0]["transactionValue"])):
|
|
|
486 |
matchedList.append(order["subTagId"])
|
| 16204 |
manish.sha |
487 |
db.shopcluesOrderAffiliateInfo.update({"merchantOrderId":aff[0].get("merchantOrderId")}, {"$set":{"reconciled":True, "orderId":orderId}}, multi=True)
|
| 15791 |
manish.sha |
488 |
order['reconciled'] = True
|
|
|
489 |
order['adId'] = aff[0].get("uniqueKey")
|
|
|
490 |
db.merchantOrder.save(order)
|
|
|
491 |
row += 1
|
|
|
492 |
i=-1
|
| 14450 |
amit.gupta |
493 |
|
| 15791 |
manish.sha |
494 |
worksheet.write(row, inc(), orderId)
|
|
|
495 |
worksheet1.write(anotherrow, i, orderId)
|
|
|
496 |
worksheet.write(row, inc(), row1[1])
|
|
|
497 |
worksheet1.write(anotherrow, i, row1[1])
|
|
|
498 |
worksheet.write(row, inc(), row1[-1])
|
|
|
499 |
worksheet1.write(anotherrow, i, row1[-1])
|
|
|
500 |
worksheet.write(row, inc(), row1[-2])
|
|
|
501 |
worksheet1.write(anotherrow, i, row1[-2])
|
|
|
502 |
worksheet.write(row, inc(), row1[-3])
|
|
|
503 |
worksheet1.write(anotherrow, i, row1[-3])
|
|
|
504 |
worksheet.write(row, inc(), order['merchantOrderId'])
|
|
|
505 |
worksheet1.write(anotherrow, i, order['merchantOrderId'])
|
|
|
506 |
worksheet.write(row, inc(), order['subTagId'])
|
|
|
507 |
worksheet1.write(anotherrow, i, order['subTagId'])
|
|
|
508 |
worksheet.write(row, inc(), order['placedOn'])
|
|
|
509 |
worksheet1.write(anotherrow, i, order['placedOn'])
|
|
|
510 |
worksheet.write(row, inc(), formattedTimestamp)
|
|
|
511 |
worksheet1.write(anotherrow, i, formattedTimestamp)
|
|
|
512 |
worksheet.write(row, inc(), int(order['paidAmount']))
|
|
|
513 |
worksheet1.write(anotherrow, i, int(order['paidAmount']))
|
| 16947 |
amit.gupta |
514 |
worksheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
|
|
515 |
worksheet1.write(anotherrow, i, datetime.strftime(utils.fromTimeStamp(aff[0]['transactionTime']), "%d %b %Y %I:%M %p"))
|
| 15791 |
manish.sha |
516 |
worksheet.write(row, inc(), aff[0]['transactionValue'])
|
|
|
517 |
worksheet1.write(anotherrow, i, aff[0]['transactionValue'])
|
|
|
518 |
worksheet.write(row, inc(), aff[0]['payOut'])
|
|
|
519 |
worksheet1.write(anotherrow, i, aff[0]['payOut'])
|
| 16238 |
manish.sha |
520 |
worksheet.write(row, inc(), "NA")
|
|
|
521 |
worksheet1.write(anotherrow, i, "NA")
|
| 15791 |
manish.sha |
522 |
k = i
|
|
|
523 |
row -= 1
|
|
|
524 |
anotherrow -= 1
|
|
|
525 |
for subOrder in order['subOrders']:
|
|
|
526 |
i = k
|
|
|
527 |
row += 1
|
|
|
528 |
anotherrow += 1
|
|
|
529 |
worksheet.write(row, inc(), subOrder['productTitle'])
|
|
|
530 |
worksheet1.write(anotherrow, i, subOrder['productTitle'])
|
|
|
531 |
worksheet.write(row, inc(), subOrder['amountPaid'])
|
|
|
532 |
worksheet1.write(anotherrow, i, subOrder['amountPaid'])
|
|
|
533 |
worksheet.write(row, inc(), subOrder['quantity'])
|
|
|
534 |
worksheet1.write(anotherrow, i, subOrder['quantity'])
|
|
|
535 |
worksheet.write(row, inc(), subOrder['status'])
|
|
|
536 |
worksheet1.write(anotherrow, i, subOrder['status'])
|
|
|
537 |
worksheet.write(row, inc(), subOrder['cashBackStatus'])
|
|
|
538 |
worksheet1.write(anotherrow, i, subOrder['cashBackStatus'])
|
|
|
539 |
worksheet.write(row, inc(), subOrder['cashBackAmount'])
|
|
|
540 |
worksheet1.write(anotherrow, i, subOrder['cashBackAmount'])
|
|
|
541 |
|
|
|
542 |
else:
|
|
|
543 |
i=-1
|
|
|
544 |
worksheet1.write(anotherrow, inc(), orderId)
|
|
|
545 |
worksheet1.write(anotherrow, inc(), row1[1])
|
|
|
546 |
worksheet1.write(anotherrow, inc(), row1[-1])
|
|
|
547 |
worksheet1.write(anotherrow, inc(), row1[-2])
|
|
|
548 |
worksheet1.write(anotherrow, inc(), row1[-3])
|
|
|
549 |
worksheet1.write(anotherrow, inc(), order['merchantOrderId'])
|
|
|
550 |
worksheet1.write(anotherrow, inc(), order['subTagId'])
|
|
|
551 |
worksheet1.write(anotherrow, inc(), order['placedOn'])
|
|
|
552 |
worksheet1.write(anotherrow, inc(), formattedTimestamp)
|
|
|
553 |
worksheet1.write(anotherrow, inc(), int(order['paidAmount']))
|
|
|
554 |
|
|
|
555 |
notReconciled[orderId] = (anotherrow, i, int(order['paidAmount']), timestamp1, order["subTagId"])
|
|
|
556 |
inc()
|
|
|
557 |
inc()
|
|
|
558 |
inc()
|
|
|
559 |
inc()
|
|
|
560 |
k = i
|
|
|
561 |
anotherrow -= 1
|
|
|
562 |
for subOrder in order['subOrders']:
|
|
|
563 |
anotherrow += 1
|
|
|
564 |
i = k
|
|
|
565 |
worksheet1.write(anotherrow, inc(), subOrder['productTitle'])
|
|
|
566 |
worksheet1.write(anotherrow, inc(), subOrder['amountPaid'])
|
|
|
567 |
worksheet1.write(anotherrow, inc(), subOrder['quantity'])
|
|
|
568 |
worksheet1.write(anotherrow, inc(), subOrder['status'])
|
|
|
569 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackStatus'])
|
|
|
570 |
worksheet1.write(anotherrow, inc(), subOrder['cashBackAmount'])
|
|
|
571 |
row5 += 1
|
|
|
572 |
i=-1
|
|
|
573 |
worksheet2.write(row5, inc(), order["orderId"])
|
|
|
574 |
worksheet2.write(row5, inc(), row1[1])
|
|
|
575 |
worksheet2.write(row5, inc(), row1[-1])
|
|
|
576 |
worksheet2.write(row5, inc(), row1[-2])
|
|
|
577 |
worksheet2.write(row5, inc(), row1[-3])
|
|
|
578 |
worksheet2.write(row5, inc(), order['merchantOrderId'])
|
|
|
579 |
worksheet2.write(row5, inc(), order['subTagId'])
|
|
|
580 |
worksheet2.write(row5, inc(), order['placedOn'])
|
|
|
581 |
worksheet2.write(row5, inc(), formattedTimestamp)
|
|
|
582 |
worksheet2.write(row5, inc(), int(order['paidAmount']))
|
|
|
583 |
row5 -=1
|
|
|
584 |
k=i
|
|
|
585 |
for subOrder in order['subOrders']:
|
|
|
586 |
i = k
|
|
|
587 |
row5 += 1
|
|
|
588 |
worksheet2.write(row5, inc(), subOrder['productTitle'])
|
|
|
589 |
worksheet2.write(row5, inc(), subOrder['amountPaid'])
|
|
|
590 |
worksheet2.write(row5, inc(), subOrder['quantity'])
|
|
|
591 |
worksheet2.write(row5, inc(), subOrder['status'])
|
|
|
592 |
worksheet2.write(row5, inc(), subOrder['cashBackStatus'])
|
|
|
593 |
worksheet2.write(row5, inc(), subOrder['cashBackAmount'])
|
|
|
594 |
|
|
|
595 |
last30Days = date.today() - timedelta(days=30)
|
|
|
596 |
int(time.mktime(last30Days.timetuple()))
|
|
|
597 |
row = 0
|
|
|
598 |
for offer in db.shopcluesOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
599 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
600 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
601 |
subTagId = offer.get("subTagId")
|
|
|
602 |
saleTime = offer.get("transactionTime")
|
| 15794 |
manish.sha |
603 |
orders = getOrdersByTag(subTagId, 5)
|
| 15791 |
manish.sha |
604 |
for order in orders:
|
|
|
605 |
if notReconciled.has_key(order[0]):
|
|
|
606 |
(roww, column, paidAmount, timestamp1, oSubTagId) = notReconciled[order[0]]
|
|
|
607 |
if paidAmount==int(offer.get("transactionValue")) and timestamp1 <= saleTime and timestamp1 + 120 >= saleTime:
|
|
|
608 |
i = column
|
| 16947 |
amit.gupta |
609 |
worksheet1.write(roww, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
| 15791 |
manish.sha |
610 |
worksheet1.write(roww, inc(), offer.get("transactionValue"))
|
|
|
611 |
worksheet1.write(roww, inc(), offer.get("payOut"))
|
|
|
612 |
del notReconciled[order[0]]
|
|
|
613 |
print "found match for user", order[1]
|
|
|
614 |
db.shopcluesOrderAffiliateInfo.update({"transactionId":offer.get("transactionId")}, {"$set":{"reconciled":True, "orderId":order[0]}}, multi=True)
|
|
|
615 |
db.merchantOrder.update({"orderId":order[0]}, {"$set":{"reconciled":True, "adId":offer.get("uniqueKey")}}, multi=True)
|
|
|
616 |
break
|
|
|
617 |
|
|
|
618 |
unreconciledOrders = notReconciled.keys()
|
|
|
619 |
|
|
|
620 |
for offer in db.shopcluesOrderAffiliateInfo.find({"reconciled":{"$exists":False},
|
|
|
621 |
"transactionTime":{"$gt":int(time.mktime(last30Days.timetuple())),
|
|
|
622 |
"$lt":int(time.mktime(date.today().timetuple()))}} ):
|
|
|
623 |
row += 1
|
|
|
624 |
i=-1
|
|
|
625 |
affNotReconciledSheet.write(row, inc(), offer.get("uniqueKey"))
|
|
|
626 |
affNotReconciledSheet.write(row, inc(), offer.get("subTagId"))
|
| 16947 |
amit.gupta |
627 |
affNotReconciledSheet.write(row, inc(), datetime.strftime(utils.fromTimeStamp(offer.get("transactionTime")), "%d %b %Y %I:%M %p"))
|
| 15791 |
manish.sha |
628 |
affNotReconciledSheet.write(row, inc(), offer.get("transactionValue"))
|
|
|
629 |
affNotReconciledSheet.write(row, inc(), offer.get("payOut"))
|
|
|
630 |
affNotReconciledSheet.write(row, inc(), offer.get("status"))
|
|
|
631 |
affNotReconciledSheet.write(row, inc(), 'NA')
|
|
|
632 |
|
|
|
633 |
workbook.save(XLS_SC_FILENAME)
|
|
|
634 |
|
| 14647 |
amit.gupta |
635 |
def sendmail(email, message, title, *varargs):
|
| 14450 |
amit.gupta |
636 |
if email == "":
|
|
|
637 |
return
|
|
|
638 |
mailServer = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
|
|
|
639 |
mailServer.ehlo()
|
|
|
640 |
mailServer.starttls()
|
|
|
641 |
mailServer.ehlo()
|
|
|
642 |
|
|
|
643 |
# Create the container (outer) email message.
|
|
|
644 |
msg = MIMEMultipart()
|
|
|
645 |
msg['Subject'] = title
|
|
|
646 |
msg.preamble = title
|
|
|
647 |
html_msg = MIMEText(message, 'html')
|
|
|
648 |
msg.attach(html_msg)
|
|
|
649 |
|
|
|
650 |
#snapdeal more to be added here
|
| 14647 |
amit.gupta |
651 |
for fileName in varargs:
|
|
|
652 |
snapdeal = MIMEBase('application', 'vnd.ms-excel')
|
|
|
653 |
snapdeal.set_payload(file(fileName).read())
|
|
|
654 |
encoders.encode_base64(snapdeal)
|
|
|
655 |
snapdeal.add_header('Content-Disposition', 'attachment;filename=' + fileName)
|
|
|
656 |
msg.attach(snapdeal)
|
| 14450 |
amit.gupta |
657 |
|
|
|
658 |
|
|
|
659 |
email.append('amit.gupta@shop2020.in')
|
|
|
660 |
MAILTO = email
|
|
|
661 |
mailServer.login(SENDER, PASSWORD)
|
|
|
662 |
mailServer.sendmail(PASSWORD, MAILTO, msg.as_string())
|
|
|
663 |
|
| 16958 |
amit.gupta |
664 |
def setHeaders(worksheet, worksheet1, worksheet2, affNotReconciledSheet, worksheet3=None):
|
| 14505 |
amit.gupta |
665 |
boldStyle = xlwt.XFStyle()
|
|
|
666 |
f = xlwt.Font()
|
|
|
667 |
f.bold = True
|
|
|
668 |
boldStyle.font = f
|
| 14501 |
amit.gupta |
669 |
row = 0
|
|
|
670 |
global i
|
|
|
671 |
i=-1
|
|
|
672 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
|
|
673 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
674 |
worksheet.write(row, inc(), 'Username', boldStyle)
|
| 14601 |
amit.gupta |
675 |
worksheet.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
676 |
worksheet.write(row, inc(), 'Device', boldStyle)
|
| 14501 |
amit.gupta |
677 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
678 |
worksheet.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
679 |
worksheet.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
680 |
worksheet.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14501 |
amit.gupta |
681 |
worksheet.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
682 |
worksheet.write(row, inc(), 'Aff Sale Date', boldStyle)
|
|
|
683 |
worksheet.write(row, inc(), 'Aff Sale Amt', boldStyle)
|
|
|
684 |
worksheet.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14601 |
amit.gupta |
685 |
worksheet.write(row, inc(), 'IP', boldStyle)
|
| 16718 |
amit.gupta |
686 |
worksheet.write(row, inc(), 'Aff Status', boldStyle)
|
| 14501 |
amit.gupta |
687 |
worksheet.write(row, inc(), 'Product Title', boldStyle)
|
|
|
688 |
worksheet.write(row, inc(), 'Price', boldStyle)
|
|
|
689 |
worksheet.write(row, inc(), 'Quantity', boldStyle)
|
|
|
690 |
worksheet.write(row, inc(), 'Status', boldStyle)
|
|
|
691 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
692 |
worksheet.write(row, inc(), 'CashBack', boldStyle)
|
|
|
693 |
|
| 14505 |
amit.gupta |
694 |
i = -1
|
| 14501 |
amit.gupta |
695 |
worksheet1.write(row, inc(), 'Order Id', boldStyle)
|
|
|
696 |
worksheet1.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
697 |
worksheet1.write(row, inc(), 'Username', boldStyle)
|
| 14601 |
amit.gupta |
698 |
worksheet1.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
699 |
worksheet1.write(row, inc(), 'Device', boldStyle)
|
| 14501 |
amit.gupta |
700 |
worksheet1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
701 |
worksheet1.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
702 |
worksheet1.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
703 |
worksheet1.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14501 |
amit.gupta |
704 |
worksheet1.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
705 |
worksheet1.write(row, inc(), 'Aff Sale Date', boldStyle)
|
|
|
706 |
worksheet1.write(row, inc(), 'Aff Sale Amt', boldStyle)
|
|
|
707 |
worksheet1.write(row, inc(), 'Aff PayOut', boldStyle)
|
| 14601 |
amit.gupta |
708 |
worksheet1.write(row, inc(), 'IP', boldStyle)
|
| 16718 |
amit.gupta |
709 |
worksheet1.write(row, inc(), 'Aff Status', boldStyle)
|
| 14501 |
amit.gupta |
710 |
worksheet1.write(row, inc(), 'Product Title', boldStyle)
|
|
|
711 |
worksheet1.write(row, inc(), 'Price', boldStyle)
|
|
|
712 |
worksheet1.write(row, inc(), 'Quantity', boldStyle)
|
|
|
713 |
worksheet1.write(row, inc(), 'Status', boldStyle)
|
|
|
714 |
worksheet1.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
715 |
worksheet1.write(row, inc(), 'CashBack', boldStyle)
|
| 14508 |
amit.gupta |
716 |
|
|
|
717 |
i = -1
|
|
|
718 |
worksheet2.write(row, inc(), 'Order Id', boldStyle)
|
|
|
719 |
worksheet2.write(row, inc(), 'User Id', boldStyle)
|
| 14850 |
amit.gupta |
720 |
worksheet2.write(row, inc(), 'Username', boldStyle)
|
| 14605 |
amit.gupta |
721 |
worksheet2.write(row, inc(), 'Version Code', boldStyle)
|
| 14771 |
amit.gupta |
722 |
worksheet2.write(row, inc(), 'Device', boldStyle)
|
| 14508 |
amit.gupta |
723 |
worksheet2.write(row, inc(), 'Merchant Order Id', boldStyle)
|
|
|
724 |
worksheet2.write(row, inc(), 'SubtagId', boldStyle)
|
|
|
725 |
worksheet2.write(row, inc(), 'Sale Date', boldStyle)
|
| 14988 |
amit.gupta |
726 |
worksheet2.write(row, inc(), 'Dtr Sale Date', boldStyle)
|
| 14508 |
amit.gupta |
727 |
worksheet2.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
728 |
worksheet2.write(row, inc(), 'Product Title', boldStyle)
|
|
|
729 |
worksheet2.write(row, inc(), 'Price', boldStyle)
|
|
|
730 |
worksheet2.write(row, inc(), 'Quantity', boldStyle)
|
|
|
731 |
worksheet2.write(row, inc(), 'Status', boldStyle)
|
|
|
732 |
worksheet2.write(row, inc(), 'Cashback Status', boldStyle)
|
|
|
733 |
worksheet2.write(row, inc(), 'CashBack', boldStyle)
|
| 14450 |
amit.gupta |
734 |
|
| 14508 |
amit.gupta |
735 |
i =-1
|
|
|
736 |
affNotReconciledSheet.write(row, inc(), 'AdId', boldStyle)
|
|
|
737 |
affNotReconciledSheet.write(row, inc(), 'subTagId', boldStyle)
|
|
|
738 |
affNotReconciledSheet.write(row, inc(), 'Sale Date', boldStyle)
|
|
|
739 |
affNotReconciledSheet.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
740 |
affNotReconciledSheet.write(row, inc(), 'Pay Out', boldStyle)
|
|
|
741 |
affNotReconciledSheet.write(row, inc(), 'Status', boldStyle)
|
| 14601 |
amit.gupta |
742 |
affNotReconciledSheet.write(row, inc(), 'IP', boldStyle)
|
| 14524 |
amit.gupta |
743 |
|
| 16958 |
amit.gupta |
744 |
if worksheet3:
|
|
|
745 |
i =-1
|
|
|
746 |
worksheet3.write(row, inc(), 'Date', boldStyle)
|
|
|
747 |
worksheet3.write(row, inc(), 'Sale Amount', boldStyle)
|
|
|
748 |
worksheet3.write(row, inc(), 'Approved Sales', boldStyle)
|
|
|
749 |
worksheet3.write(row, inc(), 'Rejected Sales', boldStyle)
|
| 16947 |
amit.gupta |
750 |
|
| 14524 |
amit.gupta |
751 |
def getUserAmountReconciled():
|
|
|
752 |
pass
|
|
|
753 |
|
| 14613 |
amit.gupta |
754 |
def getUserOrders():
|
|
|
755 |
global i
|
|
|
756 |
rb = open_workbook(XLS_FILENAME,formatting_info=True)
|
|
|
757 |
wb = copy(rb)
|
|
|
758 |
worksheet = wb.add_sheet("All Users")
|
| 16726 |
amit.gupta |
759 |
#worksheet1 = wb.add_sheet("Suspected Users")
|
| 14632 |
amit.gupta |
760 |
workbook = xlwt.Workbook()
|
|
|
761 |
sh1 = workbook.add_sheet("All Orders")
|
| 15423 |
amit.gupta |
762 |
sh2 = workbook.add_sheet("Flipkart Orders")
|
| 14632 |
amit.gupta |
763 |
|
| 14613 |
amit.gupta |
764 |
db=client.Dtr
|
|
|
765 |
results = Mysql.fetchResult('''
|
| 15932 |
amit.gupta |
766 |
select ow.*, u.username, crm1.order_count, u.referrer, aua.city,aua.state,aua.pincode from order_view ow
|
|
|
767 |
left join users u on u.id = ow.user_id
|
|
|
768 |
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
|
|
|
769 |
left join (select * from (select * from all_user_addresses order by source) s group by user_id)aua on aua.user_id=u.id
|
|
|
770 |
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');
|
| 14613 |
amit.gupta |
771 |
''',)
|
|
|
772 |
row = 0
|
|
|
773 |
i=-1
|
|
|
774 |
worksheet.write(row, inc(), 'User Id', boldStyle)
|
| 16726 |
amit.gupta |
775 |
#worksheet1.write(row, i, 'User Id', boldStyle)
|
| 14613 |
amit.gupta |
776 |
worksheet.write(row, inc(), 'User name', boldStyle)
|
| 16726 |
amit.gupta |
777 |
#worksheet1.write(row, i, 'User name', boldStyle)
|
| 14613 |
amit.gupta |
778 |
worksheet.write(row, inc(), 'Order Id', boldStyle)
|
| 16726 |
amit.gupta |
779 |
#worksheet1.write(row, i, 'Order Id', boldStyle)
|
| 14613 |
amit.gupta |
780 |
worksheet.write(row, inc(), 'Created On', boldStyle)
|
| 16726 |
amit.gupta |
781 |
#worksheet1.write(row, i, 'Created On', boldStyle)
|
| 14613 |
amit.gupta |
782 |
worksheet.write(row, inc(), 'Store Id', boldStyle)
|
| 16726 |
amit.gupta |
783 |
#worksheet1.write(row, i, 'Store Id', boldStyle)
|
| 14613 |
amit.gupta |
784 |
worksheet.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 16785 |
amit.gupta |
785 |
worksheet.write(row, inc(), 'SubOrder Id', boldStyle)
|
| 16726 |
amit.gupta |
786 |
#worksheet1.write(row, i, 'Merchant Order Id', boldStyle)
|
| 14616 |
amit.gupta |
787 |
worksheet.write(row, inc(), 'Product title', boldStyle)
|
| 16726 |
amit.gupta |
788 |
#worksheet1.write(row, i, 'Product title', boldStyle)
|
| 14613 |
amit.gupta |
789 |
worksheet.write(row, inc(), 'Amount Paid', boldStyle)
|
| 16726 |
amit.gupta |
790 |
#worksheet1.write(row, i, 'Amount Paid', boldStyle)
|
| 14613 |
amit.gupta |
791 |
worksheet.write(row, inc(), 'Cashback', boldStyle)
|
| 16726 |
amit.gupta |
792 |
#worksheet1.write(row, i, 'Cashback', boldStyle)
|
| 14613 |
amit.gupta |
793 |
worksheet.write(row, inc(), 'Order Status', boldStyle)
|
| 16726 |
amit.gupta |
794 |
#worksheet1.write(row, i, 'Order Status', boldStyle)
|
| 14613 |
amit.gupta |
795 |
worksheet.write(row, inc(), 'Detailed Status', boldStyle)
|
| 16726 |
amit.gupta |
796 |
#worksheet1.write(row, i, 'Detailed Status', boldStyle)
|
| 14613 |
amit.gupta |
797 |
worksheet.write(row, inc(), 'Cashback Status', boldStyle)
|
| 16726 |
amit.gupta |
798 |
#worksheet1.write(row, i, 'Cashback Status', boldStyle)
|
| 14613 |
amit.gupta |
799 |
worksheet.write(row, inc(), 'Reconciled', boldStyle)
|
| 16726 |
amit.gupta |
800 |
#worksheet1.write(row, i, 'Reconciled', boldStyle)
|
| 14613 |
amit.gupta |
801 |
worksheet.write(row, inc(), 'IP', boldStyle)
|
| 16726 |
amit.gupta |
802 |
#worksheet1.write(row, i, 'IP', boldStyle)
|
| 16718 |
amit.gupta |
803 |
worksheet.write(row, inc(), 'Aff Status', boldStyle)
|
| 16726 |
amit.gupta |
804 |
#worksheet1.write(row, i, 'Aff Status', boldStyle)
|
| 14693 |
amit.gupta |
805 |
i=-1
|
|
|
806 |
sh1.write(row, inc(), 'User Id', boldStyle)
|
|
|
807 |
sh1.write(row, inc(), 'User name', boldStyle)
|
|
|
808 |
sh1.write(row, inc(), 'Order Id', boldStyle)
|
|
|
809 |
sh1.write(row, inc(), 'Created On', boldStyle)
|
|
|
810 |
sh1.write(row, inc(), 'Store Id', boldStyle)
|
|
|
811 |
sh1.write(row, inc(), 'Merchant Order Id', boldStyle)
|
| 14771 |
amit.gupta |
812 |
sh1.write(row, inc(), 'Status', boldStyle)
|
| 15932 |
amit.gupta |
813 |
sh1.write(row, inc(), 'Detailed Status', boldStyle)
|
| 14693 |
amit.gupta |
814 |
sh1.write(row, inc(), 'Product title', boldStyle)
|
|
|
815 |
sh1.write(row, inc(), 'Referrer', boldStyle)
|
|
|
816 |
sh1.write(row, inc(), 'Amount Paid', boldStyle)
|
| 14771 |
amit.gupta |
817 |
sh1.write(row, inc(), 'Catalog Id', boldStyle)
|
| 14693 |
amit.gupta |
818 |
sh1.write(row, inc(), 'Brand', boldStyle)
|
|
|
819 |
sh1.write(row, inc(), 'Model', boldStyle)
|
|
|
820 |
sh1.write(row, inc(), 'Category', boldStyle)
|
| 15932 |
amit.gupta |
821 |
sh1.write(row, inc(), 'Deal Rank', boldStyle)
|
| 16286 |
amit.gupta |
822 |
sh1.write(row, inc(), 'Max Nlc', boldStyle)
|
|
|
823 |
sh1.write(row, inc(), 'Min Nlc', boldStyle)
|
|
|
824 |
sh1.write(row, inc(), 'DP', boldStyle)
|
|
|
825 |
sh1.write(row, inc(), 'Item status', boldStyle)
|
| 15932 |
amit.gupta |
826 |
sh1.write(row, inc(), 'City', boldStyle)
|
|
|
827 |
sh1.write(row, inc(), 'State', boldStyle)
|
|
|
828 |
sh1.write(row, inc(), 'Pincode', boldStyle)
|
| 15423 |
amit.gupta |
829 |
i =-1
|
|
|
830 |
sh2.write(row, inc(), 'User Id', boldStyle)
|
|
|
831 |
sh2.write(row, inc(), 'User name', boldStyle)
|
|
|
832 |
sh2.write(row, inc(), 'Created On', boldStyle)
|
|
|
833 |
sh2.write(row, inc(), 'Store', boldStyle)
|
|
|
834 |
sh2.write(row, inc(), 'Status', boldStyle)
|
|
|
835 |
sh2.write(row, inc(), 'Product title', boldStyle)
|
|
|
836 |
sh2.write(row, inc(), 'Price', boldStyle)
|
|
|
837 |
sh2.write(row, inc(), 'Quantity', boldStyle)
|
|
|
838 |
sh2.write(row, inc(), 'Catalog Id', boldStyle)
|
|
|
839 |
sh2.write(row, inc(), 'Brand', boldStyle)
|
|
|
840 |
sh2.write(row, inc(), 'Model', boldStyle)
|
|
|
841 |
sh2.write(row, inc(), 'Category', boldStyle)
|
| 14613 |
amit.gupta |
842 |
|
|
|
843 |
row=0
|
|
|
844 |
row2=0
|
| 14632 |
amit.gupta |
845 |
row3=0
|
|
|
846 |
db1 = client.Catalog
|
| 14613 |
amit.gupta |
847 |
for result in results:
|
|
|
848 |
morder = db.merchantOrder.find_one({"orderId":result[0]})
|
|
|
849 |
if morder is not None:
|
|
|
850 |
subOrders = morder.get("subOrders")
|
|
|
851 |
if subOrders is not None:
|
|
|
852 |
for subOrder in subOrders:
|
| 14632 |
amit.gupta |
853 |
row3+=1
|
|
|
854 |
i=-1
|
| 14699 |
amit.gupta |
855 |
sh1.write(row3, inc(), result[1])
|
| 15932 |
amit.gupta |
856 |
sh1.write(row3, inc(), result[7])
|
| 14632 |
amit.gupta |
857 |
sh1.write(row3, inc(), result[0])
|
| 15932 |
amit.gupta |
858 |
sh1.write(row3, inc(), result[6], datetime_format)
|
| 14632 |
amit.gupta |
859 |
sh1.write(row3, inc(), sourceMap.get(result[2]))
|
|
|
860 |
sh1.write(row3, inc(), morder.get("merchantOrderId"))
|
| 14771 |
amit.gupta |
861 |
sh1.write(row3, inc(), subOrder.get("status"))
|
| 15932 |
amit.gupta |
862 |
sh1.write(row3, inc(), subOrder.get("detailedStatus"))
|
| 14632 |
amit.gupta |
863 |
sh1.write(row3, inc(), subOrder.get("productTitle"))
|
| 15932 |
amit.gupta |
864 |
sh1.write(row3, inc(), result[9])
|
| 14632 |
amit.gupta |
865 |
inc()
|
|
|
866 |
if int(subOrder.get("quantity")) > 0:
|
|
|
867 |
sh1.write(row3, i, int(subOrder.get("amountPaid"))/int(subOrder.get("quantity")))
|
| 14647 |
amit.gupta |
868 |
skuData = getSkuData(morder.get("storeId"), subOrder.get("productCode"))
|
| 16492 |
amit.gupta |
869 |
if morder.get("storeId") in (1,2,4,5,6):
|
| 14647 |
amit.gupta |
870 |
skuData = db1.MasterData.find_one({'identifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
|
|
|
871 |
elif morder.get("storeId") == 3:
|
|
|
872 |
skuData = db1.MasterData.find_one({'secondaryIdentifier':subOrder.get("productCode").strip(), 'source_id':morder.get("storeId")})
|
| 14634 |
amit.gupta |
873 |
if skuData is not None:
|
| 14771 |
amit.gupta |
874 |
sh1.write(row3, inc(), skuData.get("skuBundleId"))
|
| 14634 |
amit.gupta |
875 |
sh1.write(row3, inc(), skuData.get("brand"))
|
|
|
876 |
sh1.write(row3, inc(), skuData.get("model_name"))
|
|
|
877 |
sh1.write(row3, inc(), skuData.get("category"))
|
| 16213 |
amit.gupta |
878 |
sh1.write(row3, inc(), subOrder.get("dealRank"))
|
| 16286 |
amit.gupta |
879 |
sh1.write(row3, inc(), subOrder.get("maxNlc"))
|
|
|
880 |
sh1.write(row3, inc(), subOrder.get("minNlc"))
|
| 16317 |
amit.gupta |
881 |
sh1.write(row3, inc(), utils.statusMap.get(subOrder.get("db")))
|
|
|
882 |
|
| 16286 |
amit.gupta |
883 |
sh1.write(row3, inc(), subOrder.get("itemStatus"))
|
| 15932 |
amit.gupta |
884 |
else:
|
|
|
885 |
sh1.write(row3, inc(), None)
|
|
|
886 |
sh1.write(row3, inc(), None)
|
|
|
887 |
sh1.write(row3, inc(), None)
|
|
|
888 |
sh1.write(row3, inc(), None)
|
|
|
889 |
sh1.write(row3, inc(), None)
|
| 16286 |
amit.gupta |
890 |
sh1.write(row3, inc(), None)
|
|
|
891 |
sh1.write(row3, inc(), None)
|
|
|
892 |
sh1.write(row3, inc(), None)
|
|
|
893 |
sh1.write(row3, inc(), None)
|
| 15932 |
amit.gupta |
894 |
sh1.write(row3, inc(), result[10])
|
|
|
895 |
sh1.write(row3, inc(), result[11])
|
|
|
896 |
sh1.write(row3, inc(), result[12])
|
|
|
897 |
|
| 14881 |
amit.gupta |
898 |
#removed filter as requested by Rajneesh
|
|
|
899 |
#if subOrder.get("cashBackStatus") == Store.CB_APPROVED or subOrder.get("cashBackStatus") == Store.CB_PENDING:
|
|
|
900 |
row +=1
|
|
|
901 |
i=-1
|
|
|
902 |
worksheet.write(row, inc(), result[0])
|
| 15932 |
amit.gupta |
903 |
worksheet.write(row, inc(), result[7])
|
| 14881 |
amit.gupta |
904 |
worksheet.write(row, inc(), result[1])
|
| 15932 |
amit.gupta |
905 |
worksheet.write(row, inc(), result[6], datetime_format)
|
| 14881 |
amit.gupta |
906 |
worksheet.write(row, inc(), result[2])
|
|
|
907 |
worksheet.write(row, inc(), morder.get("merchantOrderId"))
|
| 16785 |
amit.gupta |
908 |
worksheet.write(row, inc(), subOrder.get("merchantSubOrderId"))
|
| 14881 |
amit.gupta |
909 |
worksheet.write(row, inc(), subOrder.get("productTitle"))
|
|
|
910 |
worksheet.write(row, inc(), subOrder.get("amountPaid"))
|
|
|
911 |
worksheet.write(row, inc(), subOrder.get("cashBackAmount"))
|
|
|
912 |
worksheet.write(row, inc(), subOrder.get("status"))
|
|
|
913 |
worksheet.write(row, inc(), subOrder.get("detailedStatus"))
|
|
|
914 |
worksheet.write(row, inc(), subOrder.get("cashBackStatus"))
|
|
|
915 |
worksheet.write(row, inc(), False if morder.get("reconciled") is None else True)
|
|
|
916 |
if morder.get("reconciled") and morder.get("storeId")==3:
|
|
|
917 |
try:
|
| 16718 |
amit.gupta |
918 |
snapdealafinfo = db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True})
|
|
|
919 |
worksheet.write(row, inc(), snapdealafinfo.get("ip"))
|
|
|
920 |
worksheet.write(row, inc(), snapdealafinfo.get("conversionStatus"))
|
| 14881 |
amit.gupta |
921 |
except:
|
| 16718 |
amit.gupta |
922 |
print "Could not find", morder.get("adId"), "that is reconciled for order", morder.get("orderId")
|
| 16726 |
amit.gupta |
923 |
#if result[8] >= 10:
|
|
|
924 |
# row2 +=1
|
|
|
925 |
# i=-1
|
|
|
926 |
#worksheet1.write(row2, inc(), result[0])
|
|
|
927 |
#worksheet1.write(row2, inc(), result[7])
|
|
|
928 |
#worksheet1.write(row2, inc(), result[1])
|
|
|
929 |
#worksheet1.write(row2, inc(), result[6], datetime_format)
|
|
|
930 |
#worksheet1.write(row2, inc(), result[2])
|
|
|
931 |
#worksheet1.write(row2, inc(), morder.get("merchantOrderId"))
|
|
|
932 |
#worksheet1.write(row2, inc(), subOrder.get("productTitle"))
|
|
|
933 |
#worksheet1.write(row2, inc(), subOrder.get("amountPaid"))
|
|
|
934 |
#worksheet1.write(row2, inc(), subOrder.get("cashBackAmount"))
|
|
|
935 |
#worksheet1.write(row2, inc(), subOrder.get("status"))
|
|
|
936 |
#worksheet1.write(row2, inc(), subOrder.get("detailedStatus"))
|
|
|
937 |
#worksheet1.write(row2, inc(), subOrder.get("cashBackStatus"))
|
|
|
938 |
#worksheet1.write(row2, inc(), False if morder.get("reconciled") is None else True)
|
|
|
939 |
#worksheet1.write(row2, inc(), )
|
|
|
940 |
#if morder.get("reconciled") and morder.get("storeId")==3:
|
|
|
941 |
# try:
|
|
|
942 |
# snapdealafinfo = db.snapdealOrderAffiliateInfo.find_one({"adId":morder.get("adId"), "reconciled":True})
|
|
|
943 |
# worksheet1.write(row2, inc(), snapdealafinfo.get("ip"))
|
|
|
944 |
# worksheet1.write(row2, inc(), snapdealafinfo.get("conversionStatus"))
|
|
|
945 |
# except:
|
|
|
946 |
# print "Could not find", morder.get("adId"), "that is reconcired for order", morder.get("orderId")
|
| 15423 |
amit.gupta |
947 |
|
| 15542 |
amit.gupta |
948 |
flipkartOrders = session.query(FlipkartOrders).order_by(FlipkartOrders.created.desc()).all()
|
| 15540 |
amit.gupta |
949 |
flipkartOrders.reverse()
|
| 15423 |
amit.gupta |
950 |
row3=0
|
| 15430 |
amit.gupta |
951 |
#try:
|
| 15540 |
amit.gupta |
952 |
for order in flipkartOrders:
|
| 15423 |
amit.gupta |
953 |
row3 += 1
|
|
|
954 |
i=-1
|
| 15540 |
amit.gupta |
955 |
sh2.write(row3, inc(), order.user_id)
|
|
|
956 |
sh2.write(row3, inc(), order.email)
|
|
|
957 |
sh2.write(row3, inc(), order.created, datetime_format)
|
| 15423 |
amit.gupta |
958 |
sh2.write(row3, inc(), "Flipkart")
|
| 15540 |
amit.gupta |
959 |
sh2.write(row3, inc(), order.status)
|
|
|
960 |
sh2.write(row3, inc(), order.title)
|
|
|
961 |
sh2.write(row3, inc(), order.price)
|
|
|
962 |
sh2.write(row3, inc(), order.quantity)
|
|
|
963 |
sh2.write(row3, inc(), order.catalogId)
|
|
|
964 |
sh2.write(row3, inc(), order.brand)
|
|
|
965 |
sh2.write(row3, inc(), order.model)
|
|
|
966 |
sh2.write(row3, inc(), order.category)
|
| 14632 |
amit.gupta |
967 |
|
| 14613 |
amit.gupta |
968 |
wb.save(XLS_FILENAME)
|
| 14632 |
amit.gupta |
969 |
workbook.save(XLS_O_FILENAME)
|
| 14647 |
amit.gupta |
970 |
|
|
|
971 |
def getSkuData(storeId, identifier):
|
| 16492 |
amit.gupta |
972 |
if storeId in (1,2,4,5,6):
|
| 14647 |
amit.gupta |
973 |
skuData = client.Catalog.MasterData.find_one({'identifier':identifier, 'source_id':storeId})
|
|
|
974 |
elif storeId == 3:
|
|
|
975 |
skuData = client.Catalog.MasterData.find_one({'secondaryIdentifier':identifier, 'source_id':storeId})
|
|
|
976 |
return skuData
|
|
|
977 |
|
| 14460 |
amit.gupta |
978 |
def inc():
|
|
|
979 |
global i
|
|
|
980 |
i+=1
|
|
|
981 |
return i
|
| 15540 |
amit.gupta |
982 |
|
|
|
983 |
def migrateFlipkartOrders():
|
|
|
984 |
db = client.Dtr
|
|
|
985 |
info = reversed(list(db.flipkartOrderAffiliateInfo.find()))
|
|
|
986 |
#try:
|
|
|
987 |
for order in info:
|
|
|
988 |
userId = None
|
|
|
989 |
subTagId = None
|
|
|
990 |
email = None
|
|
|
991 |
subTagId = order.get("subTagId")
|
|
|
992 |
if subTagId:
|
|
|
993 |
click = session.query(Clicks).filter_by(tag = subTagId).first()
|
|
|
994 |
if click is not None:
|
|
|
995 |
userId= click.user_id
|
|
|
996 |
user = session.query(Users.email).filter_by(id = userId).first()
|
|
|
997 |
if user is not None:
|
|
|
998 |
email = user.email
|
|
|
999 |
|
|
|
1000 |
flipkartOrder = FlipkartOrders()
|
|
|
1001 |
flipkartOrder.user_id = userId
|
|
|
1002 |
flipkartOrder.identifier = order.get("identifier")
|
|
|
1003 |
flipkartOrder.email = email
|
|
|
1004 |
flipkartOrder.subtagId = order.get("subTagId")
|
|
|
1005 |
flipkartOrder.created = datetime.strptime(order.get("saleDate"), "%Y-%m-%d")
|
|
|
1006 |
flipkartOrder.status = order.get("conversionStatus")
|
|
|
1007 |
flipkartOrder.title = order.get("productTitle")
|
|
|
1008 |
flipkartOrder.price = order.get("price")
|
|
|
1009 |
flipkartOrder.quantity = order.get("quantity")
|
|
|
1010 |
flipkartOrder.productCode = order.get("productCode")
|
|
|
1011 |
skuData = getSkuData(2, order.get("productCode"))
|
|
|
1012 |
if skuData is not None:
|
|
|
1013 |
flipkartOrder.catalogId = skuData.get("skuBundleId")
|
|
|
1014 |
flipkartOrder.brand = skuData.get("brand")
|
|
|
1015 |
flipkartOrder.model = skuData.get("model_name")
|
|
|
1016 |
flipkartOrder.category =categoryMap.get(skuData.get("category_id"))
|
|
|
1017 |
flipkartOrder.title =skuData.get("source_product_name")
|
|
|
1018 |
|
|
|
1019 |
session.commit()
|
| 16947 |
amit.gupta |
1020 |
|
|
|
1021 |
|
|
|
1022 |
def main1():
|
|
|
1023 |
db = client.Dtr
|
|
|
1024 |
for offer in db.snapdealOrderAffiliateInfo.find({}):
|
|
|
1025 |
print offer.get("adId"), offer.get("saleAmount"), type(offer.get("saleAmount"))
|
|
|
1026 |
#obj = offer.get(saleTime)
|
|
|
1027 |
#obj['paidAmount'] += order["paidAmount"]
|
| 14632 |
amit.gupta |
1028 |
def addHeaders(sheet):
|
|
|
1029 |
global i
|
|
|
1030 |
i = 0
|
|
|
1031 |
sheet.write(0, inc(), )
|
| 14450 |
amit.gupta |
1032 |
def main():
|
| 14647 |
amit.gupta |
1033 |
|
| 16995 |
amit.gupta |
1034 |
message = generateSnapDealReco()
|
| 14647 |
amit.gupta |
1035 |
generateFlipkartReco()
|
| 15791 |
manish.sha |
1036 |
generateShopcluesReco()
|
| 14650 |
amit.gupta |
1037 |
generateAmazonReco(XLS_A_FILENAME)
|
| 14613 |
amit.gupta |
1038 |
getUserOrders()
|
| 16995 |
amit.gupta |
1039 |
sendmail(["amit.gupta@shop2020.in","rajneesh.arora@saholic.com","manish.sharma@shop2020.in"], message, "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
|
| 17001 |
amit.gupta |
1040 |
#sendmail(["amit.gupta@shop2020.in"], "", "Affiliate Reco", XLS_FILENAME, XLS_F_FILENAME, XLS_A_FILENAME, XLS_SC_FILENAME)
|
| 16266 |
manish.sha |
1041 |
sendmail(["amit.gupta@shop2020.in", "rajneesh.arora@saholic.com", "chaitnaya.vats@saholic.com", "manoj.kumar@saholic.com", "manish.sharma@shop2020.in"], "", "All DTR Orders", XLS_O_FILENAME)
|
| 17001 |
amit.gupta |
1042 |
|
|
|
1043 |
|
|
|
1044 |
def main2():
|
|
|
1045 |
db = client.Dtr
|
|
|
1046 |
curs = getOrdersAfterDate(datetime.now() - timedelta(days=1), 3)
|
|
|
1047 |
datemap={}
|
|
|
1048 |
for row1 in curs:
|
|
|
1049 |
orderId = row1[0]
|
|
|
1050 |
order = db.merchantOrder.find_one({"orderId":orderId})
|
|
|
1051 |
if order is None:
|
|
|
1052 |
continue
|
|
|
1053 |
#saleTime = int(time.mktime(datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").timetuple()))
|
|
|
1054 |
try:
|
|
|
1055 |
saleTime = datetime.strptime(order['placedOn'], "%a, %d %b, %Y").strftime("%Y-%m-%d")
|
|
|
1056 |
except:
|
|
|
1057 |
saleTime = datetime.strptime(order['placedOn'], "%b %d, %Y, %I:%M %p").strftime("%Y-%m-%d")
|
|
|
1058 |
print "%s\t%s\t%s\t%s"%(orderId, order['placedOn'], saleTime, order['paidAmount'])
|
|
|
1059 |
if not datemap.has_key(saleTime):
|
|
|
1060 |
datemap[saleTime] = {"totalAmount":0, "paidAmount":0, "rejectedAmount":0, "approvedAmount":0, "count":0}
|
|
|
1061 |
|
|
|
1062 |
obj = datemap.get(saleTime)
|
|
|
1063 |
obj['paidAmount'] += order["paidAmount"]
|
|
|
1064 |
obj['count'] += 1
|
|
|
1065 |
|
|
|
1066 |
for offer in db.snapdealOrderAffiliateInfo1.find({"saleDate":{"$gte":toTimeStamp(datetime.now() - timedelta(days=1))}}):
|
|
|
1067 |
saleTime = utils.fromTimeStamp(offer.get('saleDate')).strftime("%Y-%m-%d")
|
|
|
1068 |
obj = datemap.get(saleTime)
|
|
|
1069 |
if obj is not None:
|
|
|
1070 |
try:
|
|
|
1071 |
if offer.get("payOut"):
|
|
|
1072 |
obj['approvedAmount'] += offer["saleAmount"]
|
|
|
1073 |
else:
|
|
|
1074 |
obj['rejectedAmount'] += offer["saleAmount"]
|
|
|
1075 |
except:
|
|
|
1076 |
print "Exception for orderId" , offer.get("orderId")
|
|
|
1077 |
else:
|
|
|
1078 |
print "Could not find sale date", saleTime
|
|
|
1079 |
continue
|
|
|
1080 |
|
|
|
1081 |
for key,valmap in datemap.iteritems():
|
|
|
1082 |
valmap['_id'] = key
|
|
|
1083 |
db.flSaleSnapshot.save(valmap)
|
| 14450 |
amit.gupta |
1084 |
|
|
|
1085 |
if __name__ == '__main__':
|
| 15440 |
amit.gupta |
1086 |
#info = client.Dtr.flipkartOrderAffiliateInfo.find()
|
|
|
1087 |
#print info
|
| 17008 |
amit.gupta |
1088 |
main()
|
| 14460 |
amit.gupta |
1089 |
|