Subversion Repositories SmartDukaan

Rev

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

Rev 19135 Rev 19193
Line 346... Line 346...
346
        result['amount'] = 0.0
346
        result['amount'] = 0.0
347
    return result
347
    return result
348
 
348
 
349
def __constructDummyDealObject(skuBundleId):
349
def __constructDummyDealObject(skuBundleId):
350
    temp =[]
350
    temp =[]
351
    deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1,'subCategoryId':1})
351
    deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1,'subCategoryId':1,'netPriceAfterCashBack':1})
352
    for d in deals:
352
    for d in deals:
353
        d['persPoints'] = 0
353
        d['persPoints'] = 0
354
        temp.append(d)
354
        temp.append(d)
355
    return temp
355
    return temp
356
    
356
    
Line 397... Line 397...
397
            temp.append(temp_map)
397
            temp.append(temp_map)
398
            brandPrefMap[(x.brand).strip().upper()] = temp
398
            brandPrefMap[(x.brand).strip().upper()] = temp
399
        
399
        
400
    for x in session.query(user_actions).filter_by(user_id=userId).all():
400
    for x in session.query(user_actions).filter_by(user_id=userId).all():
401
        actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
401
        actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
402
    all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
402
    all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
403
    mobile_deals = []
403
    mobile_deals = []
404
    tablet_deals = []
404
    tablet_deals = []
405
    accessories_deals = []
405
    accessories_deals = []
406
    for deal in all_deals:
406
    for deal in all_deals:
407
 
407
 
Line 863... Line 863...
863
                        item[0]['availabilityInfo'] = [{}]
863
                        item[0]['availabilityInfo'] = [{}]
864
                    else:
864
                    else:
865
                        item[0]['availabilityInfo'] = item_availability_info
865
                        item[0]['availabilityInfo'] = item_availability_info
866
            except:
866
            except:
867
                item[0]['availabilityInfo'] = [{}]
867
                item[0]['availabilityInfo'] = [{}]
-
 
868
            
-
 
869
            if item[0]['source_id']==4:
-
 
870
                for av_info in item[0]['availabilityInfo']:
-
 
871
                    if not av_info:
-
 
872
                        continue
-
 
873
                    av_info['cash_back'] = item[0]['cash_back']
-
 
874
                    av_info['cash_back_type'] = item[0]['cash_back_type']
-
 
875
                    netPriceAfterCashBack = av_info['sellingPrice'] 
-
 
876
                    if av_info['cash_back'] ==1:
-
 
877
                        netPriceAfterCashBack = av_info['sellingPrice'] - float(av_info['sellingPrice'])*av_info['cash_back']/100
-
 
878
                    elif av_info['cash_back'] ==2:
-
 
879
                        netPriceAfterCashBack = av_info['sellingPrice'] - av_info['cash_back']
-
 
880
                    else:
-
 
881
                        pass
-
 
882
                    av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
-
 
883
                
-
 
884
            #item[0]['netPriceAfterCashBack'] = d['netPriceAfterCashBack']
-
 
885
            
-
 
886
            if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
-
 
887
                if item[0]['codAvailable'] ==1:
-
 
888
                    paytmPrice = item[0]['available_price']
-
 
889
                else:
-
 
890
                    paytmPrice = item[0]['gross_price']
-
 
891
                  
-
 
892
                if item[0]['cash_back_type'] ==1:
-
 
893
                    item[0]['netPriceAfterCashBack'] = paytmPrice -  float(paytmPrice)*item[0]['cash_back']/100
-
 
894
                elif item[0]['cash_back_type'] ==2:
-
 
895
                    item[0]['netPriceAfterCashBack'] = paytmPrice -  item[0]['cash_back']
-
 
896
                else:
-
 
897
                    item[0]['netPriceAfterCashBack'] = paytmPrice
-
 
898
                
-
 
899
            else:
-
 
900
                if item[0]['cash_back_type'] ==1:
-
 
901
                    item[0]['netPriceAfterCashBack'] = item[0]['available_price'] -  float(item[0]['available_price'])*item[0]['cash_back']/100
-
 
902
                elif item[0]['cash_back_type'] ==2:
-
 
903
                    item[0]['netPriceAfterCashBack'] = item[0]['available_price'] -  item[0]['cash_back']
-
 
904
                else:
-
 
905
                    item[0]['netPriceAfterCashBack'] = item[0]['available_price']
-
 
906
            
868
            temp.append(item[0])
907
            temp.append(item[0])
869
        if len(temp) > 1:
908
        if len(temp) > 1:
870
            temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
909
            temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
871
        dealsListMap.append(temp)
910
        dealsListMap.append(temp)
872
    return dealsListMap
911
    return dealsListMap
Line 1841... Line 1880...
1841
                    else:
1880
                    else:
1842
                        item[0]['availabilityInfo'] = item_availability_info
1881
                        item[0]['availabilityInfo'] = item_availability_info
1843
            except:
1882
            except:
1844
                item[0]['availabilityInfo'] = [{}]
1883
                item[0]['availabilityInfo'] = [{}]
1845
            
1884
            
-
 
1885
            if item[0]['source_id']==4:
-
 
1886
                for av_info in item[0]['availabilityInfo']:
-
 
1887
                    if not av_info:
-
 
1888
                        continue
-
 
1889
                    av_info['cash_back'] = item[0]['cash_back']
-
 
1890
                    av_info['cash_back_type'] = item[0]['cash_back_type']
-
 
1891
                    netPriceAfterCashBack = av_info['sellingPrice'] 
-
 
1892
                    if av_info['cash_back'] ==1:
-
 
1893
                        netPriceAfterCashBack = av_info['sellingPrice'] - float(av_info['sellingPrice'])*av_info['cash_back']/100
-
 
1894
                    elif av_info['cash_back'] ==2:
-
 
1895
                        netPriceAfterCashBack = av_info['sellingPrice'] - av_info['cash_back']
-
 
1896
                    else:
-
 
1897
                        pass
-
 
1898
                    av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
-
 
1899
            
-
 
1900
            if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
-
 
1901
                if item[0]['codAvailable'] ==1:
-
 
1902
                    paytmPrice = item[0]['available_price']
-
 
1903
                else:
-
 
1904
                    paytmPrice = item[0]['gross_price']
-
 
1905
                  
-
 
1906
                if item[0]['cash_back_type'] ==1:
-
 
1907
                    item[0]['netPriceAfterCashBack'] = paytmPrice -  float(paytmPrice)*item[0]['cash_back']/100
-
 
1908
                elif item[0]['cash_back_type'] ==2:
-
 
1909
                    item[0]['netPriceAfterCashBack'] = paytmPrice -  item[0]['cash_back']
-
 
1910
                else:
-
 
1911
                    item[0]['netPriceAfterCashBack'] = paytmPrice
-
 
1912
                
-
 
1913
            else:
-
 
1914
                if item[0]['cash_back_type'] ==1:
-
 
1915
                    item[0]['netPriceAfterCashBack'] = item[0]['available_price'] -  float(item[0]['available_price'])*item[0]['cash_back']/100
-
 
1916
                elif item[0]['cash_back_type'] ==2:
-
 
1917
                    item[0]['netPriceAfterCashBack'] = item[0]['available_price'] -  item[0]['cash_back']
-
 
1918
                else:
-
 
1919
                    item[0]['netPriceAfterCashBack'] = item[0]['available_price']
-
 
1920
            
-
 
1921
            
1846
            item[0]['totalPoints'] = d['totalPoints']
1922
            item[0]['totalPoints'] = d['totalPoints']
1847
        
1923
        
1848
            temp.append(item[0])
1924
            temp.append(item[0])
1849
        if len(temp) > 1:
1925
        if len(temp) > 1:
1850
            temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
1926
            temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
Line 2473... Line 2549...
2473
    return {'searchTerm':searchTerm,'count':totalCount}
2549
    return {'searchTerm':searchTerm,'count':totalCount}
2474
 
2550
 
2475
def getDealById(id):
2551
def getDealById(id):
2476
    item = list(get_mongo_connection().Catalog.MasterData.find({'_id':int(id)}))
2552
    item = list(get_mongo_connection().Catalog.MasterData.find({'_id':int(id)}))
2477
    d = get_mongo_connection().Catalog.Deals.find_one({'_id':int(id)})
2553
    d = get_mongo_connection().Catalog.Deals.find_one({'_id':int(id)})
2478
    if d is None:
-
 
2479
        d = {'showDp':0,'dp':0}
-
 
2480
    if len(item) ==0:
2554
    if len(item) ==0:
2481
        return {}
2555
        return {}
-
 
2556
    if d is None:
-
 
2557
        d = {'showDp':0,'dp':0}
2482
    try:
2558
    try:
2483
        cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
2559
        cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
2484
        if not cashBack or cashBack.get('cash_back_status')!=1:
2560
        if not cashBack or cashBack.get('cash_back_status')!=1:
2485
            item[0]['cash_back_type'] = 0
2561
            item[0]['cash_back_type'] = 0
2486
            item[0]['cash_back'] = 0
2562
            item[0]['cash_back'] = 0
Line 2550... Line 2626...
2550
                item[0]['availabilityInfo'] = [{}]
2626
                item[0]['availabilityInfo'] = [{}]
2551
            else:
2627
            else:
2552
                item[0]['availabilityInfo'] = item_availability_info
2628
                item[0]['availabilityInfo'] = item_availability_info
2553
    except:
2629
    except:
2554
        item[0]['availabilityInfo'] = [{}]
2630
        item[0]['availabilityInfo'] = [{}]
-
 
2631
    
-
 
2632
    if item[0]['source_id']==4:
-
 
2633
        for av_info in item[0]['availabilityInfo']:
-
 
2634
            if not av_info:
-
 
2635
                continue
-
 
2636
            av_info['cash_back'] = item[0]['cash_back']
-
 
2637
            av_info['cash_back_type'] = item[0]['cash_back_type']
-
 
2638
            netPriceAfterCashBack = av_info['sellingPrice'] 
-
 
2639
            if av_info['cash_back'] ==1:
-
 
2640
                netPriceAfterCashBack = av_info['sellingPrice'] - float(av_info['sellingPrice'])*av_info['cash_back']/100
-
 
2641
            elif av_info['cash_back'] ==2:
-
 
2642
                netPriceAfterCashBack = av_info['sellingPrice'] - av_info['cash_back']
-
 
2643
            else:
-
 
2644
                pass
-
 
2645
            av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
-
 
2646
    
-
 
2647
    if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
-
 
2648
        if item[0]['codAvailable'] ==1:
-
 
2649
            paytmPrice = item[0]['available_price']
-
 
2650
        else:
-
 
2651
            paytmPrice = item[0]['gross_price']
-
 
2652
          
-
 
2653
        if item[0]['cash_back_type'] ==1:
-
 
2654
            item[0]['netPriceAfterCashBack'] = paytmPrice -  float(paytmPrice)*item[0]['cash_back']/100
-
 
2655
        elif item[0]['cash_back_type'] ==2:
-
 
2656
            item[0]['netPriceAfterCashBack'] = paytmPrice -  item[0]['cash_back']
-
 
2657
        else:
-
 
2658
            item[0]['netPriceAfterCashBack'] = paytmPrice
-
 
2659
        
-
 
2660
    else:
-
 
2661
        if item[0]['cash_back_type'] ==1:
-
 
2662
            item[0]['netPriceAfterCashBack'] = item[0]['available_price'] -  float(item[0]['available_price'])*item[0]['cash_back']/100
-
 
2663
        elif item[0]['cash_back_type'] ==2:
-
 
2664
            item[0]['netPriceAfterCashBack'] = item[0]['available_price'] -  item[0]['cash_back']
-
 
2665
        else:
-
 
2666
            item[0]['netPriceAfterCashBack'] = item[0]['available_price']
-
 
2667
        
2555
    return item[0]
2668
    return item[0]
2556
 
2669
 
2557
            
2670
            
2558
def main():
2671
def main():
2559
    getDealsForSearchText("20", 'Samsung', 0, 10)
2672
    getDealsForSearchText("20", 'Samsung', 0, 10)