| Line 23... |
Line 23... |
| 23 |
(options, args) = parser.parse_args()
|
23 |
(options, args) = parser.parse_args()
|
| 24 |
|
24 |
|
| 25 |
bundleMap = {}
|
25 |
bundleMap = {}
|
| 26 |
inventoryMap = {}
|
26 |
inventoryMap = {}
|
| 27 |
memCon = None
|
27 |
memCon = None
|
| 28 |
maxQuantity = 20
|
28 |
maxQuantity = 100
|
| 29 |
flaggedItems = []
|
29 |
flaggedItems = []
|
| 30 |
itemPricingMap = {}
|
30 |
itemPricingMap = {}
|
| - |
|
31 |
bulkItemsMap = {}
|
| 31 |
|
32 |
|
| 32 |
def get_inventory_client():
|
33 |
def get_inventory_client():
|
| 33 |
ic = InventoryClient("inventory_service_server_host2","inventory_service_server_port2").get_client()
|
34 |
ic = InventoryClient("inventory_service_server_host2","inventory_service_server_port2").get_client()
|
| 34 |
return ic
|
35 |
return ic
|
| 35 |
|
36 |
|
| Line 112... |
Line 113... |
| 112 |
item['maxQuantity'] = temp_maxQuantity
|
113 |
item['maxQuantity'] = temp_maxQuantity
|
| 113 |
else:
|
114 |
else:
|
| 114 |
item['maxQuantity'] = min(availability,item.get('maxQuantity'))
|
115 |
item['maxQuantity'] = min(availability,item.get('maxQuantity'))
|
| 115 |
if item['minBuyQuantity'] > availability:
|
116 |
if item['minBuyQuantity'] > availability:
|
| 116 |
item['minBuyQuantity'] = availability
|
117 |
item['minBuyQuantity'] = availability
|
| 117 |
toremove = []
|
- |
|
| 118 |
for bulkPricing in item['bulkPricing']:
|
- |
|
| 119 |
if bulkPricing['quantity'] < item['minBuyQuantity'] or bulkPricing['quantity'] > item['maxQuantity']:
|
- |
|
| 120 |
toremove.append(bulkPricing)
|
- |
|
| 121 |
for removePricing in toremove:
|
118 |
checkBulkPrices(item)
|
| 122 |
item['bulkPricing'].remove(removePricing)
|
- |
|
| 123 |
item['bulkPricing'] = sorted(item['bulkPricing'], key=lambda k: k['quantity'],reverse=False)
|
119 |
item['bulkPricing'] = sorted(item['bulkPricing'], key=lambda k: k['quantity'],reverse=False)
|
| - |
|
120 |
|
| 124 |
temp = sorted(v, key = lambda x: (x['availability']),reverse=True)
|
121 |
temp = sorted(v, key = lambda x: (x['availability']),reverse=True)
|
| 125 |
mc = get_memcache_connection(host=options.mongoHost)
|
122 |
mc = get_memcache_connection(host=options.mongoHost)
|
| 126 |
mc.set(str("item_availability_"+str(k)), temp, 60*60)
|
123 |
mc.set(str("item_availability_"+str(k)), temp, 60*60)
|
| 127 |
|
124 |
|
| - |
|
125 |
def checkBulkPrices(item):
|
| - |
|
126 |
adjusted = False
|
| - |
|
127 |
"""Lets check minBuyQty exist in bulkPricing"""
|
| - |
|
128 |
minBuyQty = item['minBuyQuantity']
|
| - |
|
129 |
for bulkPricingDict in item['bulkPricing']:
|
| - |
|
130 |
if bulkPricingDict.get('quantity') == minBuyQty:
|
| - |
|
131 |
adjusted = True
|
| - |
|
132 |
if minBuyQty > 1 and not adjusted:
|
| - |
|
133 |
allBulkPricing = bulkItemsMap.get(item.get('item_id'))
|
| - |
|
134 |
if len(allBulkPricing) == 0:
|
| - |
|
135 |
item['bulkPricing'] = [{'quantity':minBuyQty,'price':item.get('sellingPrice')}]
|
| - |
|
136 |
else:
|
| - |
|
137 |
allBulkPricing = sorted(allBulkPricing, key=lambda k: k['quantity'],reverse=False)
|
| - |
|
138 |
effectiveBulkPrice = None
|
| - |
|
139 |
for bulkPricing in allBulkPricing:
|
| - |
|
140 |
if bulkPricing.get('quantity') < minBuyQty:
|
| - |
|
141 |
effectiveBulkPrice = bulkPricing
|
| - |
|
142 |
if effectiveBulkPrice is None:
|
| - |
|
143 |
item['bulkPricing'].append({'quantity':minBuyQty,'price':item.get('sellingPrice')})
|
| - |
|
144 |
else:
|
| - |
|
145 |
item['bulkPricing'].append({'quantity':minBuyQty,'price':effectiveBulkPrice['price']})
|
| - |
|
146 |
toremove = []
|
| - |
|
147 |
for bulkPricing in item['bulkPricing']:
|
| - |
|
148 |
if bulkPricing['quantity'] < item['minBuyQuantity'] or bulkPricing['quantity'] > item['maxQuantity']:
|
| - |
|
149 |
toremove.append(bulkPricing)
|
| - |
|
150 |
for removePricing in toremove:
|
| - |
|
151 |
item['bulkPricing'].remove(removePricing)
|
| - |
|
152 |
|
| - |
|
153 |
|
| 128 |
def flagNoAvailableItems():
|
154 |
def flagNoAvailableItems():
|
| 129 |
global flaggedItems
|
155 |
global flaggedItems
|
| 130 |
for k, v in bundleMap.iteritems():
|
156 |
for k, v in bundleMap.iteritems():
|
| 131 |
for item in v:
|
157 |
for item in v:
|
| 132 |
availability = inventoryMap.get(item.get('item_id'))
|
158 |
availability = inventoryMap.get(item.get('item_id'))
|
| 133 |
if availability is None:
|
159 |
if availability is None:
|
| 134 |
flaggedItems.append(item.get('item_id'))
|
160 |
flaggedItems.append(item.get('item_id'))
|
| 135 |
|
161 |
|
| 136 |
def addBulkPricingInfo():
|
162 |
def addBulkPricingInfo():
|
| 137 |
bulkItemsMap = {}
|
163 |
global bulkItemsMap
|
| 138 |
bulkItems = session.query(BulkItemPricing).all()
|
164 |
bulkItems = session.query(BulkItemPricing).all()
|
| 139 |
for item in bulkItems:
|
165 |
for item in bulkItems:
|
| 140 |
if bulkItemsMap.has_key(item.item_id):
|
166 |
if bulkItemsMap.has_key(item.item_id):
|
| 141 |
temp_list = bulkItemsMap.get(item.item_id)
|
167 |
temp_list = bulkItemsMap.get(item.item_id)
|
| 142 |
temp_list.append({'quantity':item.quantity,'price':item.price})
|
168 |
temp_list.append({'quantity':item.quantity,'price':item.price})
|
| Line 152... |
Line 178... |
| 152 |
for temp in bulkPricing:
|
178 |
for temp in bulkPricing:
|
| 153 |
if temp.get('quantity') ==1:
|
179 |
if temp.get('quantity') ==1:
|
| 154 |
singleUnitPricing = True
|
180 |
singleUnitPricing = True
|
| 155 |
if not singleUnitPricing:
|
181 |
if not singleUnitPricing:
|
| 156 |
bulkPricing.append({'quantity':1,'price':itemPricingMap.get(item.get('item_id'))})
|
182 |
bulkPricing.append({'quantity':1,'price':itemPricingMap.get(item.get('item_id'))})
|
| 157 |
item['bulkPricing'] = bulkPricing
|
183 |
item['bulkPricing'] = bulkPricing
|
| 158 |
|
184 |
|
| 159 |
|
185 |
|
| 160 |
def fetchItemAvailablity():
|
186 |
def fetchItemAvailablity():
|
| 161 |
global inventoryMap
|
187 |
global inventoryMap
|
| 162 |
try:
|
188 |
try:
|
| Line 177... |
Line 203... |
| 177 |
print "Flagged items ",flaggedItems
|
203 |
print "Flagged items ",flaggedItems
|
| 178 |
get_inventory_client().updateItemAvailabilityForItemIds(flaggedItems)
|
204 |
get_inventory_client().updateItemAvailabilityForItemIds(flaggedItems)
|
| 179 |
fetchItemAvailablity()
|
205 |
fetchItemAvailablity()
|
| 180 |
addInfoToMemCache()
|
206 |
addInfoToMemCache()
|
| 181 |
mc = get_memcache_connection(host=options.mongoHost)
|
207 |
mc = get_memcache_connection(host=options.mongoHost)
|
| 182 |
print mc.get("item_availability_1007389")
|
208 |
print mc.get("item_availability_1016554")
|