Subversion Repositories SmartDukaan

Rev

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

Rev 13850 Rev 13916
Line 48... Line 48...
48
def getItemsToUpdate():
48
def getItemsToUpdate():
49
    global dealsCatalogIds
49
    global dealsCatalogIds
50
    global itemCatalogMap
50
    global itemCatalogMap
51
    saholicCatalogIds = list(get_mongo_connection().Catalog.MasterData.find({'rank':{"$gt":0},'source_id':4}))
51
    saholicCatalogIds = list(get_mongo_connection().Catalog.MasterData.find({'rank':{"$gt":0},'source_id':4}))
52
    for d in saholicCatalogIds:
52
    for d in saholicCatalogIds:
53
        dealsCatalogIds.append(long(d['identifier']))
53
        dealsCatalogIds.append(long(d['identifier'].strip()))
54
    items = Item.query.filter(Item.catalog_item_id.in_(dealsCatalogIds)).all()
54
    items = Item.query.filter(Item.catalog_item_id.in_(dealsCatalogIds)).all()
55
    for item in items:
55
    for item in items:
56
        temp = []
56
        temp = []
57
        if not itemCatalogMap.has_key(item.catalog_item_id):
57
        if not itemCatalogMap.has_key(item.catalog_item_id):
58
            temp.append(item)
58
            temp.append(item)
Line 64... Line 64...
64
                temp.append(l)
64
                temp.append(l)
65
            temp.append(item)
65
            temp.append(item)
66
            itemCatalogMap[item.catalog_item_id] = temp
66
            itemCatalogMap[item.catalog_item_id] = temp
67
            
67
            
68
    for saholicCatalogId in saholicCatalogIds:
68
    for saholicCatalogId in saholicCatalogIds:
69
        d_items = itemCatalogMap.get(long(saholicCatalogId['identifier']))
69
        d_items = itemCatalogMap.get(long(saholicCatalogId['identifier'].strip()))
70
        available_price = None
70
        available_price = None
71
        for d_item in d_items: 
71
        for d_item in d_items: 
72
            if d_item.status == 3:
72
            if d_item.status == 3:
73
                in_stock =1
73
                in_stock =1
74
            else:
74
            else:
Line 89... Line 89...
89
        print in_stock
89
        print in_stock
90
        print available_price
90
        print available_price
91
        print dealsMap.get(d_item.id)
91
        print dealsMap.get(d_item.id)
92
        print "++++++++++++++++++++++++++"
92
        print "++++++++++++++++++++++++++"
93
        if available_price > 0 or available_price is not None:
93
        if available_price > 0 or available_price is not None:
94
            get_mongo_connection().Catalog.MasterData.update({'identifier':saholicCatalogId['identifier']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(timestamp),'in_stock':in_stock}}, multi=True)
94
            get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price,'updatedOn':to_java_date(timestamp),'in_stock':in_stock}}, multi=True)
-
 
95
            get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'available_price':available_price , 'in_stock':in_stock}}, multi=True)
95
        else:
96
        else:
96
            get_mongo_connection().Catalog.MasterData.update({'identifier':saholicCatalogId['identifier']}, {'$set' : {'updatedOn':to_java_date(timestamp),'in_stock':in_stock}}, multi=True)
97
            get_mongo_connection().Catalog.MasterData.update({'_id':saholicCatalogId['_id']}, {'$set' : {'updatedOn':to_java_date(timestamp),'in_stock':in_stock}}, multi=True)
-
 
98
            get_mongo_connection().Catalog.Deals.update({'_id':saholicCatalogId['_id']}, {'$set' : {'in_stock':in_stock}}, multi=True)
-
 
99
        
-
 
100
        try:
-
 
101
            recomputeDeal(saholicCatalogId['skuBundleId'])
-
 
102
        except:
-
 
103
            print "Unable to compute deal for ",saholicCatalogId['skuBundleId']
-
 
104
 
-
 
105
def recomputeDeal(skuBundleId):
-
 
106
    """Lets recompute deal for this bundle"""
-
 
107
    print "Recomputing for bundleId",skuBundleId
-
 
108
    
-
 
109
    similarItems = list(get_mongo_connection().Catalog.Deals.find({'skuBundleId':skuBundleId}).sort([('available_price',pymongo.ASCENDING)]))
-
 
110
    bestPrice = float("inf")
-
 
111
    bestOne = None
-
 
112
    bestSellerPoints = 0
-
 
113
    toUpdate = []
-
 
114
    for similarItem in similarItems:
-
 
115
        if similarItem['in_stock'] == 0:
-
 
116
            get_mongo_connection().Catalog.Deals.update({ '_id' : similarItem['_id'] }, {'$set':{'showDeal':0 }})
-
 
117
            continue
-
 
118
        if similarItem['available_price'] < bestPrice:
-
 
119
            bestOne = similarItem
-
 
120
            bestPrice = similarItem['available_price']
-
 
121
            bestSellerPoints = similarItem['bestSellerPoints']
-
 
122
        elif similarItem['available_price'] == bestPrice and bestSellerPoints < similarItem['bestSellerPoints']:
-
 
123
            bestOne = similarItem
-
 
124
            bestPrice = similarItem['available_price']
-
 
125
            bestSellerPoints = similarItem['bestSellerPoints']
-
 
126
        else:
-
 
127
            pass
-
 
128
    if bestOne is not None:
-
 
129
        for similarItem in similarItems:
-
 
130
            toUpdate.append(similarItem['_id'])
-
 
131
        toUpdate.remove(bestOne['_id'])
-
 
132
        get_mongo_connection().Catalog.Deals.update({ '_id' : bestOne['_id'] }, {'$set':{'showDeal':1 }})
-
 
133
    if len(toUpdate) > 0:
-
 
134
        get_mongo_connection().Catalog.Deals.update({ '_id' : { "$in": toUpdate } }, {'$set':{'showDeal':0 }},upsert=False, multi=True)
97
        
135
        
98
def main():
136
def main():
99
    getPrivateDeals()
137
    getPrivateDeals()
100
    getItemsToUpdate()
138
    getItemsToUpdate()
101
 
139