Subversion Repositories SmartDukaan

Rev

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

Rev 17755 Rev 19188
Line 43... Line 43...
43
        except Exception, e:
43
        except Exception, e:
44
            print e
44
            print e
45
            return None
45
            return None
46
    return con
46
    return con
47
 
47
 
-
 
48
def getNetPriceForItem(itemId, source_id, category_id ,price):
-
 
49
    cash_back_type = 0
-
 
50
    cash_back = 0
-
 
51
    try:
-
 
52
        cashBack = getCashBack(itemId, source_id, category_id, mc, options.mongoHost)
-
 
53
        if not cashBack or cashBack.get('cash_back_status')!=1:
-
 
54
            cash_back_type = 0
-
 
55
            cash_back = 0 
-
 
56
            
-
 
57
        else:
-
 
58
            if cashBack['cash_back_type'] in (1,2):
-
 
59
                
-
 
60
                if cashBack.get('maxCashBack') is not None:
-
 
61
                    
-
 
62
                    if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*price)/100 > cashBack.get('maxCashBack'):
-
 
63
                        cashBack['cash_back_type'] = 2
-
 
64
                        cashBack['cash_back'] = cashBack['maxCashBack']
-
 
65
                    elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
-
 
66
                        cashBack['cash_back'] = cashBack['maxCashBack']
-
 
67
                    else:
-
 
68
                        pass
-
 
69
                
-
 
70
                
-
 
71
                
-
 
72
                cash_back_type = cashBack['cash_back_type']
-
 
73
                cash_back = float(cashBack['cash_back'])
-
 
74
    except Exception as cashBackEx:
-
 
75
        pass
-
 
76
    
-
 
77
    if cash_back_type ==1:
-
 
78
        return (price - float(cash_back)*price/100)
-
 
79
    elif cash_back_type ==2:
-
 
80
        return (price - cash_back)
-
 
81
    else:
-
 
82
        return price
-
 
83
 
-
 
84
 
48
def getPrivateDeals():
85
def getPrivateDeals():
49
    try:
86
    try:
50
        global dealsMap
87
        global dealsMap
51
        dealsMap = dict()
88
        dealsMap = dict()
52
        all_active_items_query =  session.query(PrivateDeals).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate))
89
        all_active_items_query =  session.query(PrivateDeals).filter(PrivateDeals.isActive==True).filter(now().between(PrivateDeals.startDate, PrivateDeals.endDate))
Line 141... Line 178...
141
        print in_stock
178
        print in_stock
142
        print available_price
179
        print available_price
143
        print dealsMap.get(d_item.id)
180
        print dealsMap.get(d_item.id)
144
        print "++++++++++++++++++++++++++"
181
        print "++++++++++++++++++++++++++"
145
        if available_price > 0 or available_price is not None:
182
        if available_price > 0 or available_price is not None:
-
 
183
            netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('SAHOLIC'), data['category_id'], available_price)
146
            get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':in_stock}}, multi=True)
184
            get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(datetime.now()),'priceUpdatedOn':to_java_date(datetime.now()),'in_stock':in_stock}}, multi=True)
147
            get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price , 'in_stock':in_stock}}, multi=True)
185
            get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price , 'in_stock':in_stock,'netPriceAfterCashBack':netPriceAfterCashBack}}, multi=True)
148
        else:
186
        else:
-
 
187
            netPriceAfterCashBack = getNetPriceForItem(data['_id'], SOURCE_MAP.get('SAHOLIC'), data['category_id'], saholicCatalogId['available_price'])
149
            get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':in_stock,'priceUpdatedOn':to_java_date(datetime.now())}}, multi=True)
188
            get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'updatedOn':to_java_date(datetime.now()),'in_stock':in_stock,'priceUpdatedOn':to_java_date(datetime.now())}}, multi=True)
150
            get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'in_stock':in_stock}}, multi=True)
189
            get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'in_stock':in_stock,'netPriceAfterCashBack':netPriceAfterCashBack}}, multi=True)
151
        
190
        
152
        try:
191
        try:
153
            recomputeDeal(saholicCatalogId)
192
            recomputeDeal(saholicCatalogId)
154
        except:
193
        except:
155
            print "Unable to compute deal for ",saholicCatalogId['skuBundleId']
194
            print "Unable to compute deal for ",saholicCatalogId['skuBundleId']
Line 181... Line 220...
181
def recomputeDeal(item):
220
def recomputeDeal(item):
182
    """Lets recompute deal for this bundle"""
221
    """Lets recompute deal for this bundle"""
183
    print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
222
    print "Recomputing for bundleId %d" %(item.get('skuBundleId'))
184
    skuBundleId = item['skuBundleId']
223
    skuBundleId = item['skuBundleId']
185
    
224
    
186
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
225
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('netPriceAfterCashBack',pymongo.ASCENDING)]))
187
    bestPrice = float("inf")
226
    bestPrice = float("inf")
188
    bestOne = None
227
    bestOne = None
189
    bestSellerPoints = 0
228
    bestSellerPoints = 0
190
    toUpdate = []
229
    toUpdate = []
191
    prepaidBestPrice = float("inf")
230
    prepaidBestPrice = float("inf")
Line 199... Line 238...
199
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
238
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
200
                continue
239
                continue
201
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
240
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
202
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
241
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
203
                continue
242
                continue
204
            if similarItem['available_price'] < bestPrice:
243
            if similarItem.get('netPriceAfterCashBack') < bestPrice:
205
                bestOne = similarItem
244
                bestOne = similarItem
206
                bestPrice = similarItem['available_price']
245
                bestPrice = similarItem.get('netPriceAfterCashBack')
207
                bestSellerPoints = similarItem['bestSellerPoints']
246
                bestSellerPoints = similarItem['bestSellerPoints']
208
            elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
247
            elif similarItem.get('netPriceAfterCashBack') == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
209
                bestOne = similarItem
248
                bestOne = similarItem
210
                bestPrice = similarItem['available_price']
249
                bestPrice = similarItem.get('netPriceAfterCashBack')
211
                bestSellerPoints = similarItem['bestSellerPoints']
250
                bestSellerPoints = similarItem['bestSellerPoints']
212
            else:
251
            else:
213
                pass
252
                pass
214
        else:
253
        else:
215
            if mc.get("negative_deals") is None:
254
            if mc.get("negative_deals") is None:
216
                populateNegativeDeals()
255
                populateNegativeDeals()
217
            if similarItem['in_stock'] == 0  or similarItem['_id'] in mc.get("negative_deals"):
256
            if similarItem['in_stock'] == 0  or similarItem['_id'] in mc.get("negative_deals"):
218
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
257
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0, 'prepaidDeal':0 }})
219
                continue
258
                continue
220
            if similarItem['source_id'] == SOURCE_MAP.get('PAYTM.COM'):
-
 
221
                similarItem['available_price'] = similarItem['gross_price']
-
 
222
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
259
            if similarItem['source_id'] == SOURCE_MAP.get('SHOPCLUES.COM') and similarItem['rank']==0:
223
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
260
                get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':0 }})
224
                continue
261
                continue
225
            if similarItem['available_price'] < prepaidBestPrice:
262
            if similarItem.get('netPriceAfterCashBack') < prepaidBestPrice:
226
                prepaidBestOne = similarItem
263
                prepaidBestOne = similarItem
227
                prepaidBestPrice = similarItem['available_price']
264
                prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
228
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
265
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
229
            elif similarItem['available_price'] == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
266
            elif similarItem.get('netPriceAfterCashBack') == prepaidBestPrice and prepaidBestSellerPoints < similarItem['bestSellerPoints']:
230
                prepaidBestOne = similarItem
267
                prepaidBestOne = similarItem
231
                prepaidBestPrice = similarItem['available_price']
268
                prepaidBestPrice = similarItem.get('netPriceAfterCashBack')
232
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
269
                prepaidBestSellerPoints = similarItem['bestSellerPoints']
233
            else:
270
            else:
234
                pass
271
                pass
235
    if bestOne is not None or prepaidBestOne is not None:
272
    if bestOne is not None or prepaidBestOne is not None:
236
        for similarItem in similarItems:
273
        for similarItem in similarItems:
Line 238... Line 275...
238
        if bestOne is not None:
275
        if bestOne is not None:
239
            toUpdate.remove(bestOne['_id'])
276
            toUpdate.remove(bestOne['_id'])
240
            get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
277
            get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1,'prepaidDeal':0 }})
241
        if prepaidBestOne is not None:
278
        if prepaidBestOne is not None:
242
            if bestOne is not None:
279
            if bestOne is not None:
243
                if prepaidBestOne['available_price'] < bestOne['available_price']: 
280
                if prepaidBestOne.get('netPriceAfterCashBack') < bestOne.get('netPriceAfterCashBack'): 
244
                    toUpdate.remove(prepaidBestOne['_id'])
281
                    toUpdate.remove(prepaidBestOne['_id'])
245
                    get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
282
                    get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
246
            else:
283
            else:
247
                toUpdate.remove(prepaidBestOne['_id'])
284
                toUpdate.remove(prepaidBestOne['_id'])
248
                get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
285
                get_mongo_connection().Catalog.Deals.update({ '_id' : prepaidBestOne['_id'] }, {'$set':{'showDeal':0,'prepaidDeal':1 }})
249
    if len(toUpdate) > 0:
286
    if len(toUpdate) > 0:
250
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
287
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0,'prepaidDeal':0 }},upsert=False, multi=True)
251
  
-
 
252
 
288
 
253
        
289
        
254
def main():
290
def main():
255
    getPrivateDeals()
291
    getPrivateDeals()
256
    try:
292
    try: