Subversion Repositories SmartDukaan

Rev

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

Rev 13924 Rev 13927
Line 1... Line -...
1
import pymongo
-
 
2
from datetime import datetime
1
from datetime import datetime
-
 
2
from dtr.main import Store
3
from dtr.utils.utils import to_java_date
3
from dtr.utils.utils import to_java_date
4
from operator import itemgetter 
4
from operator import itemgetter
-
 
5
import pymongo
5
 
6
 
6
con = None
7
con = None
7
cashBackMap = {}
8
cashBackMap = {}
8
itemCashBackMap = {}
9
itemCashBackMap = {}
9
 
10
 
Line 142... Line 143...
142
        result['currPage'] = page    
143
        result['currPage'] = page    
143
        return result
144
        return result
144
    else:
145
    else:
145
        return result
146
        return result
146
 
147
 
-
 
148
def getRefunds(userId, page=1, window=10):
-
 
149
    if page==None:
-
 
150
        page = 1
-
 
151
        
-
 
152
    if window==None:
-
 
153
        window = 50
-
 
154
    result = {}
-
 
155
    skip = (page-1)*window
-
 
156
    collection = get_mongo_connection().Dtr.refund
-
 
157
    cursor = collection.find({"userId":userId})
-
 
158
    total_count = cursor.count()
-
 
159
    pages = total_count/window + (0 if total_count%window==0 else 1)  
-
 
160
    print "total_count", total_count
-
 
161
    if total_count > skip:
-
 
162
        cursor = cursor.skip(skip).limit(window).sort({'batchId':-1})
-
 
163
        refunds = []
-
 
164
        for refund in cursor:
-
 
165
            del(refund["_id"])
-
 
166
            refunds.append(refund)
-
 
167
        result['data'] = refunds
-
 
168
        result['window'] = window
-
 
169
        result['totalCount'] = total_count 
-
 
170
        result['currCount'] = cursor.count()
-
 
171
        result['totalPages'] = pages
-
 
172
        result['currPage'] = page    
-
 
173
        return result
-
 
174
    else:
-
 
175
        return result
-
 
176
    
-
 
177
def getPendingRefunds(userId):
-
 
178
    result = get_mongo_connection().Dtr.merchantOrder\
-
 
179
        .aggregate([
-
 
180
                    {'$match':{'subOrders.cashBackStatus':Store.CB_APPROVED, 'userId':userId}},
-
 
181
                    {'$unwind':"$subOrders"},
-
 
182
                    { 
-
 
183
                     '$group':{
-
 
184
                               '_id':None,
-
 
185
                               'amount': { '$sum':'$subOrders.cashBackAmount'},
-
 
186
                               }
-
 
187
                     }
-
 
188
                ])['result'][0]
-
 
189
    del(result["_id"])
-
 
190
    return result
147
def getDeals(category_id, offset, limit, sort, direction):
191
def getDeals(category_id, offset, limit, sort, direction):
148
    if not bool(cashBackMap):
192
    if not bool(cashBackMap):
149
        populateCashBack()
193
        populateCashBack()
150
    rank = 1
194
    rank = 1
151
    deals = {}
195
    deals = {}