Subversion Repositories SmartDukaan

Rev

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

Rev 17054 Rev 17098
Line 201... Line 201...
201
        #collectionMap = {'palcedOn':1}
201
        #collectionMap = {'palcedOn':1}
202
        searchMap = {}
202
        searchMap = {}
203
        collectionMap = {"orderTrackingUrl":1,"merchantOrderId":1}
203
        collectionMap = {"orderTrackingUrl":1,"merchantOrderId":1}
204
        orders = self._getActiveOrders(searchMap,collectionMap)
204
        orders = self._getActiveOrders(searchMap,collectionMap)
205
        for order in orders:
205
        for order in orders:
-
 
206
            try:
206
            print "Order", self.store_name, order['orderId'], order['orderTrackingUrl'], order['merchantOrderId']
207
                print "Order", self.store_name, order['orderId'], order['orderTrackingUrl'], order['merchantOrderId']
207
            br1 = track(HS_ORDER_TRACK_URL, order['merchantOrderId'])
208
                br1 = track(HS_ORDER_TRACK_URL, order['merchantOrderId'])
208
            ungzipResponseBr(br1.response(), br1)
209
                ungzipResponseBr(br1.response(), br1)
209
            trackPageSoup = BeautifulSoup(br1.response().read())
210
                trackPageSoup = BeautifulSoup(br1.response().read())
210
            subOrderTable = trackPageSoup.body.find("table", {'class':'lower-table'})
211
                subOrderTable = trackPageSoup.body.find("table", {'class':'lower-table'})
211
            subOrders = subOrderTable.findAll('tr', recursive=False)
212
                subOrders = subOrderTable.findAll('tr', recursive=False)
212
            firstRow = subOrders.pop(0)
213
                firstRow = subOrders.pop(0)
213
            
-
 
214
            closed = True
214
                closed = True
215
            for row in subOrders:
215
                for row in subOrders:
216
                cols = row.find_all('td')
216
                    cols = row.find_all('td')
217
                subOrderId = cols[0].text.strip()
217
                    subOrderId = cols[0].text.strip()
218
                subOrderStatus = cols[1].text.strip()
218
                    subOrderStatus = cols[1].text.strip()
219
                subbulk = self.db.merchantOrder.initialize_ordered_bulk_op()
219
                    subbulk = self.db.merchantOrder.initialize_ordered_bulk_op()
220
                print 'Sub Order Id', str(subOrderId)
220
                    print 'Sub Order Id', str(subOrderId)
221
                subOrder =  self._isSubOrderActive(order, str(subOrderId))
221
                    subOrder =  self._isSubOrderActive(order, str(subOrderId))
222
                if subOrder is None:
222
                    if subOrder is None:
223
                    print 'No HS Sub Order Found for SubOrder Id:- '+ str(subOrderId)
223
                        print 'No HS Sub Order Found for SubOrder Id:- '+ str(subOrderId)
224
                elif subOrder['closed']:
224
                    elif subOrder['closed']:
225
                    continue
225
                        continue
226
                else:
-
 
227
                    findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": str(subOrderId)}
-
 
228
                    updateMap = {}
-
 
229
                    updateMap["subOrders.$.detailedStatus"] = subOrderStatus
-
 
230
                    status = self._getStatusFromDetailedStatus(subOrderStatus) 
-
 
231
                    closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
-
 
232
                    if status is not None:
-
 
233
                        updateMap["subOrders.$.status"] = status
-
 
234
                    if closedStatus:
-
 
235
                        #if status is closed then change the paybackStatus accordingly
-
 
236
                        print 'Order Closed'
-
 
237
                        updateMap["subOrders.$.closed"] = True
-
 
238
                        if status == Store.ORDER_DELIVERED:
-
 
239
                            if subOrder.get("cashBackStatus") == Store.CB_PENDING:
-
 
240
                                updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
-
 
241
                        elif status == Store.ORDER_CANCELLED:
-
 
242
                            if subOrder.get("cashBackStatus") == Store.CB_PENDING:
-
 
243
                                updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
-
 
244
                    else:
226
                    else:
-
 
227
                        findMap = {"orderId": order['orderId'], "subOrders.merchantSubOrderId": str(subOrderId)}
-
 
228
                        updateMap = {}
-
 
229
                        updateMap["subOrders.$.detailedStatus"] = subOrderStatus
-
 
230
                        status = self._getStatusFromDetailedStatus(subOrderStatus) 
-
 
231
                        closedStatus = status in [Store.ORDER_DELIVERED, Store.ORDER_CANCELLED]
-
 
232
                        if status is not None:
-
 
233
                            updateMap["subOrders.$.status"] = status
-
 
234
                        if closedStatus:
-
 
235
                            #if status is closed then change the paybackStatus accordingly
-
 
236
                            print 'Order Closed'
-
 
237
                            updateMap["subOrders.$.closed"] = True
-
 
238
                            if status == Store.ORDER_DELIVERED:
-
 
239
                                if subOrder.get("cashBackStatus") == Store.CB_PENDING:
-
 
240
                                    updateMap["subOrders.$.cashBackStatus"] = Store.CB_APPROVED
-
 
241
                            elif status == Store.ORDER_CANCELLED:
-
 
242
                                if subOrder.get("cashBackStatus") == Store.CB_PENDING:
-
 
243
                                    updateMap["subOrders.$.cashBackStatus"] = Store.CB_CANCELLED
-
 
244
                        else:
245
                        closed = False
245
                            closed = False
246
                        print 'Order not Closed'
246
                            print 'Order not Closed'
247
                        
247
                            
248
                    subbulk.find(findMap).update({'$set' : updateMap})
248
                        subbulk.find(findMap).update({'$set' : updateMap})
249
                    subresult = subbulk.execute()
249
                        subresult = subbulk.execute()
250
                    tprint(subresult)
250
                        tprint(subresult)
-
 
251
            except:
-
 
252
                print "Error occurred for tracking order... "+str(order['merchantOrderId'])
-
 
253
                traceback.print_exc()
-
 
254
                continue
251
                
255
                
252
            
256
            
253
            
257
            
254
def track(url, orderId):
258
def track(url, orderId):
255
    br = getBrowserObject()
259
    br = getBrowserObject()
Line 262... Line 266...
262
    print csrf
266
    print csrf
263
    #html = response.read()
267
    #html = response.read()
264
    #print html
268
    #print html
265
    br.select_form(name='trackForm')
269
    br.select_form(name='trackForm')
266
    br.form['orderId'] = str(orderId)
270
    br.form['orderId'] = str(orderId)
-
 
271
    br.form['_csrf'] = str(csrf)
267
    response = br.submit()
272
    response = br.submit()
268
    print "********************"
273
    print "********************"
269
    print "Attempting to Login"
274
    print "Attempting to Login"
270
    print "********************"
275
    print "********************"
271
    #ungzipResponse(response, br)
276
    #ungzipResponse(response, br)