| Line 214... |
Line 214... |
| 214 |
print response
|
214 |
print response
|
| 215 |
response = json.loads(response)['response']
|
215 |
response = json.loads(response)['response']
|
| 216 |
items = response['itemsMap']
|
216 |
items = response['itemsMap']
|
| 217 |
orders = response['orders']
|
217 |
orders = response['orders']
|
| 218 |
closed = True
|
218 |
closed = True
|
| - |
|
219 |
splitSubOrdersMap={}
|
| - |
|
220 |
ordersToClone = {}
|
| 219 |
for order in orders:
|
221 |
for order in orders:
|
| 220 |
print "orderid---", order['id']
|
222 |
print "orderid---", order['id']
|
| 221 |
orderId = str(order['id'])
|
223 |
orderId = str(order['id'])
|
| 222 |
subOrder = self._isSubOrderActive(tr, orderId)
|
224 |
subOrder = self._isSubOrderActive(tr, orderId)
|
| - |
|
225 |
currentQty = int(order['lineitems'][0]['quantity'])
|
| 223 |
if subOrder:
|
226 |
if subOrder:
|
| 224 |
if subOrder['closed']:
|
227 |
if subOrder['closed']:
|
| 225 |
continue
|
228 |
continue
|
| 226 |
else:
|
229 |
else:
|
| - |
|
230 |
quantity = int(subOrder['quantity'])
|
| 227 |
findMap = {"orderId": tr['orderId'], "subOrders.merchantSubOrderId": orderId}
|
231 |
findMap = {"orderId": tr['orderId'], "subOrders.merchantSubOrderId": orderId}
|
| 228 |
updateMap = {}
|
232 |
updateMap = {}
|
| 229 |
updateMap["subOrders.$.detailedStatus"] = order['statusDescription']
|
233 |
updateMap["subOrders.$.detailedStatus"] = order['statusDescription']
|
| 230 |
status = self._getStatusFromDetailedStatus(ORDERSTATUS[order['status']])
|
234 |
status = self._getStatusFromDetailedStatus(ORDERSTATUS[order['status']])
|
| 231 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
235 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
| 232 |
print "status---", status, order['status']
|
236 |
print "status---", status, order['status']
|
| 233 |
updateMap["subOrders.$.status"] = status
|
237 |
updateMap["subOrders.$.status"] = status
|
| - |
|
238 |
#Check if split
|
| - |
|
239 |
if quantity != currentQty:
|
| - |
|
240 |
updateMap["subOrders.$.quantity"] = currentQty
|
| - |
|
241 |
updateMap["subOrders.$.amount"] = int((subOrder['amount']*currentQty)/quantity)
|
| - |
|
242 |
updateMap["subOrders.$.cashBackAmount"] = int((subOrder['cashBackAmount']*currentQty)/quantity)
|
| - |
|
243 |
updateMap["subOrders.$.amountPaid"] = int((subOrder['amountPaid']*currentQty)/quantity)
|
| - |
|
244 |
splitSubOrdersMap[order['id']]=subOrder
|
| 234 |
if closedStatus:
|
245 |
if closedStatus:
|
| 235 |
#if status is closed then change the paybackStatus accordingly
|
246 |
#if status is closed then change the paybackStatus accordingly
|
| 236 |
updateMap["subOrders.$.closed"] = True
|
247 |
updateMap["subOrders.$.closed"] = True
|
| 237 |
if status == Store.ORDER_DELIVERED:
|
248 |
if status == Store.ORDER_DELIVERED:
|
| 238 |
deliveredOn = datetime.strftime(datetime.fromtimestamp(order['delivery_timestamp']/1000),"%A %d %B %Y")
|
249 |
deliveredOn = datetime.strftime(datetime.fromtimestamp(order['delivery_timestamp']/1000),"%A %d %B %Y")
|
| Line 246... |
Line 257... |
| 246 |
expectedDelivery = datetime.strftime(datetime.fromtimestamp(order['promised_delivery_time']/1000),"%A %d %B %Y")
|
257 |
expectedDelivery = datetime.strftime(datetime.fromtimestamp(order['promised_delivery_time']/1000),"%A %d %B %Y")
|
| 247 |
updateMap["subOrders.$.estimatedDeliveryDate"] = expectedDelivery
|
258 |
updateMap["subOrders.$.estimatedDeliveryDate"] = expectedDelivery
|
| 248 |
closed = False
|
259 |
closed = False
|
| 249 |
bulk.find(findMap).update({'$set' : updateMap})
|
260 |
bulk.find(findMap).update({'$set' : updateMap})
|
| 250 |
else:
|
261 |
else:
|
| - |
|
262 |
if order['originalOrderId']:
|
| - |
|
263 |
ordersToClone[order['id']] = order
|
| - |
|
264 |
else:
|
| 251 |
subOrder = self.createSubOrder(order, items)
|
265 |
subOrder = self.createSubOrder(order, items)
|
| 252 |
self.db.merchantOrder.update({"orderId":tr['orderId']},{'$push':{"subOrders":todict(subOrder)}})
|
266 |
self.db.merchantOrder.update({"orderId":tr['orderId']},{'$push':{"subOrders":todict(subOrder)}})
|
| 253 |
print "Added new suborder with subOrder Id:", subOrder.merchantSubOrderId
|
267 |
print "Added new suborder with subOrder Id:", subOrder.merchantSubOrderId
|
| - |
|
268 |
closed = False
|
| - |
|
269 |
|
| - |
|
270 |
for order in ordersToClone.values():
|
| - |
|
271 |
originalOrderId = self.getOriginalOrderId(order['id'], ordersToClone, splitSubOrdersMap)
|
| - |
|
272 |
subOrderToClone = splitSubOrdersMap[originalOrderId].copy()
|
| - |
|
273 |
subOrderToClone["merchantSubOrderId"] = order['id']
|
| - |
|
274 |
currentQty = int(order['lineitems'][0]['quantity'])
|
| - |
|
275 |
quantity = int(subOrderToClone['quantity'])
|
| - |
|
276 |
subOrderToClone["detailedStatus"] = order['statusDescription']
|
| - |
|
277 |
status = self._getStatusFromDetailedStatus(ORDERSTATUS[order['status']])
|
| - |
|
278 |
closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
|
| - |
|
279 |
print "status---", status, order['status']
|
| - |
|
280 |
subOrderToClone["status"] = status
|
| - |
|
281 |
subOrderToClone["quantity"] = currentQty
|
| - |
|
282 |
subOrderToClone["amount"] = int((subOrderToClone['amount']*currentQty)/quantity)
|
| - |
|
283 |
subOrderToClone["cashBackAmount"] = int((subOrderToClone['cashBackAmount']*currentQty)/quantity)
|
| - |
|
284 |
subOrderToClone["amountPaid"] = int((subOrderToClone['amountPaid']*currentQty)/quantity)
|
| - |
|
285 |
if closedStatus:
|
| - |
|
286 |
#if status is closed then change the paybackStatus accordingly
|
| - |
|
287 |
subOrderToClone["closed"] = True
|
| - |
|
288 |
if status == Store.ORDER_DELIVERED:
|
| - |
|
289 |
deliveredOn = datetime.strftime(datetime.fromtimestamp(order['delivery_timestamp']/1000),"%A %d %B %Y")
|
| - |
|
290 |
subOrderToClone['deliveredOn'] = deliveredOn
|
| - |
|
291 |
if subOrderToClone.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
292 |
subOrderToClone["cashBackStatus"] = Store.CB_APPROVED
|
| - |
|
293 |
elif status == Store.ORDER_CANCELLED:
|
| - |
|
294 |
if subOrderToClone.get("cashBackStatus") == Store.CB_PENDING:
|
| - |
|
295 |
subOrderToClone["cashBackStatus"] = Store.CB_CANCELLED
|
| - |
|
296 |
else:
|
| - |
|
297 |
expectedDelivery = datetime.strftime(datetime.fromtimestamp(order['promised_delivery_time']/1000),"%A %d %B %Y")
|
| - |
|
298 |
subOrderToClone["estimatedDeliveryDate"] = expectedDelivery
|
| 254 |
closed = False
|
299 |
closed = False
|
| - |
|
300 |
|
| - |
|
301 |
self.db.merchantOrder.update({"orderId":tr['orderId']},{'$push':{"subOrders":subOrderToClone}})
|
| - |
|
302 |
|
| - |
|
303 |
|
| 255 |
bulk.find({"orderId":tr['orderId']}).update({'$set' : {'closed':closed}})
|
304 |
bulk.find({"orderId":tr['orderId']}).update({'$set' : {'closed':closed}})
|
| 256 |
except:
|
305 |
except:
|
| 257 |
traceback.print_exc()
|
306 |
traceback.print_exc()
|
| 258 |
try:
|
307 |
try:
|
| 259 |
bulk.execute()
|
308 |
bulk.execute()
|
| Line 261... |
Line 310... |
| 261 |
traceback.print_exc()
|
310 |
traceback.print_exc()
|
| 262 |
|
311 |
|
| 263 |
|
312 |
|
| 264 |
|
313 |
|
| 265 |
|
314 |
|
| - |
|
315 |
def getOriginalOrderId(self, orderId, ordersToClone, splitSubOrdersMap):
|
| - |
|
316 |
if splitSubOrdersMap.has_key(orderId):
|
| - |
|
317 |
return orderId
|
| - |
|
318 |
else:
|
| - |
|
319 |
originalOrderId = ordersToClone[orderId]['originalOrderId']
|
| - |
|
320 |
return self.getOriginalOrderId(originalOrderId, ordersToClone, splitSubOrdersMap)
|
| - |
|
321 |
|
| 266 |
def _saveToAffiliate(self, offers):
|
322 |
def _saveToAffiliate(self, offers):
|
| 267 |
if offers is None or len(offers)==0:
|
323 |
if offers is None or len(offers)==0:
|
| 268 |
print "no affiliate have been pushed"
|
324 |
print "no affiliate have been pushed"
|
| 269 |
return
|
325 |
return
|
| 270 |
collection = self.db.snapdealOrderAffiliateInfo
|
326 |
collection = self.db.snapdealOrderAffiliateInfo
|
| Line 310... |
Line 366... |
| 310 |
return urllib.urlencode(parameters)
|
366 |
return urllib.urlencode(parameters)
|
| 311 |
|
367 |
|
| 312 |
def main():
|
368 |
def main():
|
| 313 |
|
369 |
|
| 314 |
store = getStore(4)
|
370 |
store = getStore(4)
|
| 315 |
#store.scrapeStoreOrders()
|
371 |
store.scrapeStoreOrders()
|
| 316 |
#store._isSubOrderActive(8, "5970688907")
|
372 |
#store._isSubOrderActive(8, "5970688907")
|
| 317 |
#store.scrapeAffiliate()
|
373 |
#store.scrapeAffiliate()
|
| 318 |
store.parseOrderRawHtml(112345, "subtagId", 1122323, "html", 'http://www.saholic.com/pay-success?paymentId=1798123')
|
374 |
#store.parseOrderRawHtml(112345, "subtagId", 1122323, "html", 'http://www.saholic.com/pay-success?paymentId=1798123')
|
| 319 |
#print store.getCashbackAmount('1011378', 500)
|
375 |
#print store.getCashbackAmount('1011378', 500)
|
| 320 |
|
376 |
|
| 321 |
|
377 |
|
| 322 |
if __name__ == '__main__':
|
378 |
if __name__ == '__main__':
|
| 323 |
main()
|
379 |
main()
|