| Line 27... |
Line 27... |
| 27 |
|
27 |
|
| 28 |
con = None
|
28 |
con = None
|
| 29 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5}
|
29 |
SOURCE_MAP = {'AMAZON':1,'FLIPKART':2,'SNAPDEAL':3,'SAHOLIC':4, 'SHOPCLUES.COM':5}
|
| 30 |
DISCOUNT_TYPE = {'MRP':1,'DP':2}
|
30 |
DISCOUNT_TYPE = {'MRP':1,'DP':2}
|
| 31 |
LATEST_UPDATED_ITEMS = []
|
31 |
LATEST_UPDATED_ITEMS = []
|
| - |
|
32 |
STATUS_WEIGHTAGE = {1 : 1.0, 2 : 2.0, 3 : 1.0, 4 : 0.5}
|
| 32 |
|
33 |
|
| 33 |
now = datetime.now()
|
34 |
now = datetime.now()
|
| 34 |
|
35 |
|
| 35 |
class __SkuInfo:
|
36 |
class __SkuInfo:
|
| 36 |
|
37 |
|
| 37 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
38 |
def __init__(self, _id, skuBundleId, category_id, mrp, available_price, source_id, rank, maxNlc, minNlc, schemeAmount, minDiscount, \
|
| 38 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, dealPoints, brand_id, manualDealThresholdPrice,\
|
39 |
maxDiscount, discountType, dp, nlcPoints, status, in_stock, maxprice, brand, dealType, dealPoints, brand_id, manualDealThresholdPrice,\
|
| 39 |
codAvailable):
|
40 |
codAvailable,showDp):
|
| 40 |
self._id = _id
|
41 |
self._id = _id
|
| 41 |
self.skuBundleId = skuBundleId
|
42 |
self.skuBundleId = skuBundleId
|
| 42 |
self.category_id = category_id
|
43 |
self.category_id = category_id
|
| 43 |
self.mrp = mrp
|
44 |
self.mrp = mrp
|
| 44 |
self.available_price = available_price
|
45 |
self.available_price = available_price
|
| Line 59... |
Line 60... |
| 59 |
self.dealType = dealType
|
60 |
self.dealType = dealType
|
| 60 |
self.dealPoints = dealPoints
|
61 |
self.dealPoints = dealPoints
|
| 61 |
self.brand_id = brand_id
|
62 |
self.brand_id = brand_id
|
| 62 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
63 |
self.manualDealThresholdPrice = manualDealThresholdPrice
|
| 63 |
self.codAvailable = codAvailable
|
64 |
self.codAvailable = codAvailable
|
| - |
|
65 |
self.showDp = showDp
|
| 64 |
|
66 |
|
| 65 |
|
67 |
|
| 66 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
68 |
def get_mongo_connection(host=options.mongoHost, port=27017):
|
| 67 |
global con
|
69 |
global con
|
| 68 |
if con is None:
|
70 |
if con is None:
|
| Line 88... |
Line 90... |
| 88 |
#topSkus = collection.find( {'_id':664})
|
90 |
#topSkus = collection.find( {'_id':664})
|
| 89 |
for sku in topSkus:
|
91 |
for sku in topSkus:
|
| 90 |
"""Fix this """
|
92 |
"""Fix this """
|
| 91 |
#TODO Compute deal flags else where.
|
93 |
#TODO Compute deal flags else where.
|
| 92 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
94 |
info = __SkuInfo(sku['_id'], sku['skuBundleId'], sku['category_id'], sku['mrp'], sku['available_price'], sku['source_id'], sku['rank'], None, None, 0.0, None, \
|
| 93 |
None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, 0, sku['brand_id'], None, sku['codAvailable'])
|
95 |
None, None, None, None, sku['status'], sku['in_stock'],sku['maxPrice'],sku['brand'].strip().upper(), 0, 0, sku['brand_id'], None, sku['codAvailable'], 0)
|
| 94 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
|
96 |
exceptionalNlc = list(get_mongo_connection().Catalog.ExceptionalNlc.find( {"$and" : [ {'skuBundleId':info.skuBundleId}, {'overrideNlc':1} ]} ))
|
| 95 |
if len(exceptionalNlc) > 0:
|
97 |
if len(exceptionalNlc) > 0:
|
| 96 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
98 |
"""Exceptional nlc found, no need to calculate max and min R-nlc"""
|
| 97 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
99 |
info.maxNlc = exceptionalNlc[0]['maxNlc']
|
| 98 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
100 |
info.minNlc = exceptionalNlc[0]['minNlc']
|
| Line 110... |
Line 112... |
| 110 |
info.schemeAmount = float(skuSchemeDetails[0]['schemeAmount'])
|
112 |
info.schemeAmount = float(skuSchemeDetails[0]['schemeAmount'])
|
| 111 |
|
113 |
|
| 112 |
skuDealerPrices = list(get_mongo_connection().Catalog.SkuDealerPrices.find( {'skuBundleId':info.skuBundleId} ) )
|
114 |
skuDealerPrices = list(get_mongo_connection().Catalog.SkuDealerPrices.find( {'skuBundleId':info.skuBundleId} ) )
|
| 113 |
if len(skuDealerPrices) > 0:
|
115 |
if len(skuDealerPrices) > 0:
|
| 114 |
info.dp = skuDealerPrices[0]['dp']
|
116 |
info.dp = skuDealerPrices[0]['dp']
|
| - |
|
117 |
info.showDp = skuDealerPrices[0]['showDp']
|
| 115 |
skuDiscount = list(get_mongo_connection().Catalog.SkuDiscountInfo.find( {'skuBundleId':info.skuBundleId} ) )
|
118 |
skuDiscount = list(get_mongo_connection().Catalog.SkuDiscountInfo.find( {'skuBundleId':info.skuBundleId} ) )
|
| 116 |
if len(skuDiscount) > 0:
|
119 |
if len(skuDiscount) > 0:
|
| 117 |
"""Sku rule found, populate max , min Discount and discount type"""
|
120 |
"""Sku rule found, populate max , min Discount and discount type"""
|
| 118 |
info.maxDiscount = skuDiscount[0]['max_discount']
|
121 |
info.maxDiscount = skuDiscount[0]['max_discount']
|
| 119 |
info.minDiscount = skuDiscount[0]['min_discount']
|
122 |
info.minDiscount = skuDiscount[0]['min_discount']
|
| Line 164... |
Line 167... |
| 164 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
167 |
it = Item.query.filter_by(catalog_item_id=identifier).first()
|
| 165 |
try:
|
168 |
try:
|
| 166 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
169 |
vendorPricing = inventory_client.getAllItemPricing(it.id)
|
| 167 |
min_dp = min(pricing.dealerPrice for pricing in vendorPricing)
|
170 |
min_dp = min(pricing.dealerPrice for pricing in vendorPricing)
|
| 168 |
obj.dp = min_dp
|
171 |
obj.dp = min_dp
|
| - |
|
172 |
obj.showDp = 1
|
| 169 |
except:
|
173 |
except:
|
| 170 |
pass
|
174 |
pass
|
| 171 |
if obj.dp > 0:
|
175 |
if obj.dp > 0:
|
| 172 |
obj.minNlc = obj.dp - (obj.dp * obj.maxDiscount/100) - obj.schemeAmount
|
176 |
obj.minNlc = obj.dp - (obj.dp * obj.maxDiscount/100) - obj.schemeAmount
|
| 173 |
obj.maxNlc = obj.dp - (obj.dp * obj.minDiscount/100) - obj.schemeAmount
|
177 |
obj.maxNlc = obj.dp - (obj.dp * obj.minDiscount/100) - obj.schemeAmount
|
| Line 261... |
Line 265... |
| 261 |
for sku in allItems:
|
265 |
for sku in allItems:
|
| 262 |
bestSellerPoints = list(get_mongo_connection().Catalog.BestSellerPoints.find( {"$and":[{'min_rank': { "$lte": sku['rank'] } }, {'max_rank': { "$gte": sku['rank'] } } , { 'category_id' : sku['category_id'] }, { 'source_id' : sku['source_id'] }] } ))
|
266 |
bestSellerPoints = list(get_mongo_connection().Catalog.BestSellerPoints.find( {"$and":[{'min_rank': { "$lte": sku['rank'] } }, {'max_rank': { "$gte": sku['rank'] } } , { 'category_id' : sku['category_id'] }, { 'source_id' : sku['source_id'] }] } ))
|
| 263 |
if len(bestSellerPoints) > 0:
|
267 |
if len(bestSellerPoints) > 0:
|
| 264 |
print bestSellerPoints[0]['points']
|
268 |
print bestSellerPoints[0]['points']
|
| 265 |
if (bestSellerPoints[0]['points']) > 0:
|
269 |
if (bestSellerPoints[0]['points']) > 0:
|
| 266 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points']) * bestSellerPoints[0]['weightage']
|
270 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points']) * bestSellerPoints[0]['weightage'] * STATUS_WEIGHTAGE.get(sku['status'])
|
| 267 |
else:
|
271 |
else:
|
| 268 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points'])
|
272 |
sku['bestSellerPoints'] = (bestSellerPoints[0]['points'])
|
| 269 |
else:
|
273 |
else:
|
| 270 |
sku['bestSellerPoints'] = -100
|
274 |
sku['bestSellerPoints'] = -120
|
| 271 |
#sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
|
275 |
#sku['totalPoints'] = sku['bestSellerPoints'] + sku['nlcPoints']
|
| 272 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints']}},multi=False)
|
276 |
get_mongo_connection().Catalog.Deals.update({'_id':sku['_id']},{'$set':{'bestSellerPoints':sku['bestSellerPoints']}},multi=False)
|
| 273 |
|
277 |
|
| 274 |
shortageSkus = get_mongo_connection().Catalog.MasterData.find({"$and":[{'is_shortage': 1 }, { 'source_id' : { "$in": SOURCE_MAP.values() } }] }).distinct('_id')
|
278 |
shortageSkus = get_mongo_connection().Catalog.MasterData.find({"$and":[{'is_shortage': 1 }, { 'source_id' : { "$in": SOURCE_MAP.values() } }] }).distinct('_id')
|
| 275 |
print "Shortage skus"
|
279 |
print "Shortage skus"
|