| 94 |
ashish |
1 |
'''
|
|
|
2 |
Created on 23-Mar-2010
|
|
|
3 |
|
|
|
4 |
@author: ashish
|
|
|
5 |
'''
|
|
|
6 |
from elixir import *
|
|
|
7 |
from shop2020.model.v1.catalog.impl import DataService
|
| 122 |
ashish |
8 |
from shop2020.model.v1.catalog.impl.DataService import Item, \
|
| 103 |
ashish |
9 |
Warehouse, ItemInventoryHistory, CurrentInventorySnapshot, ItemInfo,\
|
| 602 |
chandransh |
10 |
ItemChangeLog, Price, BestDeals, BestSellers
|
| 122 |
ashish |
11 |
from shop2020.thriftpy.model.v1.catalog.ttypes import \
|
|
|
12 |
InventoryServiceException, status
|
| 602 |
chandransh |
13 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
|
| 94 |
ashish |
14 |
import datetime
|
| 602 |
chandransh |
15 |
from shop2020.utils.Utils import log_entry, to_py_date
|
|
|
16 |
from sqlalchemy import desc
|
| 94 |
ashish |
17 |
|
|
|
18 |
|
|
|
19 |
def initialize():
|
|
|
20 |
DataService.initialize()
|
|
|
21 |
|
|
|
22 |
|
| 103 |
ashish |
23 |
def get_all_items(is_active):
|
|
|
24 |
if is_active:
|
| 122 |
ashish |
25 |
return Item.query.filter_by(status= status.ACTIVE).all()
|
| 103 |
ashish |
26 |
else:
|
|
|
27 |
return Item.query.all()
|
|
|
28 |
|
|
|
29 |
def get_all_items_by_status(status):
|
|
|
30 |
if not status:
|
|
|
31 |
#return all items
|
|
|
32 |
return get_all_items(False)
|
|
|
33 |
else:
|
| 122 |
ashish |
34 |
return Item.query.filter_by(status=status).all()
|
| 103 |
ashish |
35 |
|
| 94 |
ashish |
36 |
def get_Item(item_id):
|
|
|
37 |
return Item.get_by(id=item_id)
|
|
|
38 |
|
| 379 |
ashish |
39 |
def get_item_by_catalog_id(catalog_id):
|
| 447 |
rajveer |
40 |
query = Item.query.filter_by(catalog_item_id=catalog_id)
|
| 437 |
rajveer |
41 |
try:
|
|
|
42 |
return query.one()
|
|
|
43 |
except:
|
|
|
44 |
raise InventoryServiceException(109, "Item not found")
|
|
|
45 |
|
| 483 |
rajveer |
46 |
def get_item_by_vendor_id(vendor_id):
|
|
|
47 |
query = Item.query.filter_by(vendor_item_id=vendor_id)
|
| 494 |
rajveer |
48 |
#query = Item.query.filter_by(vendor_item_id='6417182037054')
|
| 483 |
rajveer |
49 |
try:
|
|
|
50 |
return query.one()
|
|
|
51 |
except:
|
|
|
52 |
raise InventoryServiceException(109, "Item not found")
|
|
|
53 |
|
| 576 |
chandransh |
54 |
def is_active(item_id):
|
|
|
55 |
try:
|
|
|
56 |
item = get_item_by_catalog_id(item_id)
|
|
|
57 |
return item.status == status.ACTIVE
|
|
|
58 |
except InventoryServiceException:
|
|
|
59 |
return False
|
| 563 |
chandransh |
60 |
|
| 94 |
ashish |
61 |
def get_Warehouse(warehouse_id):
|
|
|
62 |
return Warehouse.get_by(id=warehouse_id)
|
|
|
63 |
|
| 122 |
ashish |
64 |
def get_all_warehouses_by_status(status):
|
|
|
65 |
if not status:
|
|
|
66 |
return Warehouse.query.all()
|
|
|
67 |
else:
|
|
|
68 |
return Warehouse.query.filter_by(status=status)
|
|
|
69 |
|
| 94 |
ashish |
70 |
def get_all_warehouses_for_item(item_id):
|
|
|
71 |
item = get_Item(item_id)
|
|
|
72 |
if not item:
|
| 122 |
ashish |
73 |
raise InventoryServiceException(108, "Some unforeseen error while obtaining item")
|
|
|
74 |
return item.get_all_warehouses
|
| 94 |
ashish |
75 |
|
| 122 |
ashish |
76 |
def get_all_items_for_warehouse(warehouse_id):
|
|
|
77 |
warehouse = get_Warehouse(warehouse_id)
|
|
|
78 |
if not warehouse:
|
|
|
79 |
raise InventoryServiceException(108, "bad warehouse")
|
|
|
80 |
return warehouse.all_items
|
|
|
81 |
|
| 94 |
ashish |
82 |
def add_warehouse(warehouse):
|
| 103 |
ashish |
83 |
if not warehouse:
|
| 122 |
ashish |
84 |
raise InventoryServiceException(108, "Bad warehouse")
|
| 103 |
ashish |
85 |
if get_Warehouse(warehouse.id):
|
|
|
86 |
#warehouse is already present.
|
| 122 |
ashish |
87 |
raise InventoryServiceException(101, "Warehouse already present")
|
| 103 |
ashish |
88 |
|
| 94 |
ashish |
89 |
ds_warehouse = Warehouse()
|
|
|
90 |
ds_warehouse.id = warehouse.id
|
|
|
91 |
ds_warehouse.location = warehouse.location
|
| 122 |
ashish |
92 |
ds_warehouse.status = status.ACTIVE
|
| 103 |
ashish |
93 |
ds_warehouse.addedOn = datetime.datetime.now()
|
| 483 |
rajveer |
94 |
ds_warehouse.lastCheckedOn = datetime.datetime.now()
|
|
|
95 |
ds_warehouse.tinNumber = warehouse.tinNumber
|
|
|
96 |
ds_warehouse.pincode = warehouse.pincode
|
|
|
97 |
if warehouse.vendorString:
|
|
|
98 |
ds_warehouse.vendorString = warehouse.vendorString
|
| 94 |
ashish |
99 |
session.commit()
|
| 103 |
ashish |
100 |
return ds_warehouse.id
|
| 94 |
ashish |
101 |
|
| 122 |
ashish |
102 |
def update_item(item):
|
|
|
103 |
if not item:
|
|
|
104 |
raise InventoryServiceException(108, "Bad item in request")
|
|
|
105 |
|
|
|
106 |
if not item.id:
|
|
|
107 |
raise InventoryServiceException(101, "non existent item")
|
|
|
108 |
|
|
|
109 |
ds_item = get_Item(item.id)
|
|
|
110 |
|
|
|
111 |
if not ds_item:
|
|
|
112 |
raise InventoryServiceException(101, "Item already exists")
|
|
|
113 |
|
| 511 |
rajveer |
114 |
if item.manufacturerName:
|
|
|
115 |
ds_item.manufacturer_name = item.manufacturerName
|
|
|
116 |
if item.modelName:
|
|
|
117 |
ds_item.model_name = item.modelName
|
|
|
118 |
if item.modelNumber:
|
|
|
119 |
ds_item.model_number = item.modelNumber
|
| 483 |
rajveer |
120 |
if item.category:
|
|
|
121 |
ds_item.category = item.category
|
|
|
122 |
if item.comments:
|
|
|
123 |
ds_item.comments = item.comments
|
| 511 |
rajveer |
124 |
|
| 122 |
ashish |
125 |
if item.catalogItemId:
|
|
|
126 |
ds_item.catalog_item_id = item.catalogItemId
|
|
|
127 |
if item.vendorItemId:
|
|
|
128 |
ds_item.vendor_item_id = item.vendorItemId
|
|
|
129 |
else:
|
|
|
130 |
raise InventoryServiceException(101, "vendor item id cannot be missing")
|
| 483 |
rajveer |
131 |
|
|
|
132 |
if item.mrp:
|
|
|
133 |
ds_item.mrp = item.mrp
|
|
|
134 |
if item.mop:
|
|
|
135 |
ds_item.mop = item.mop
|
|
|
136 |
if item.sellingPrice:
|
|
|
137 |
ds_item.sellingPrice = item.sellingPrice
|
| 122 |
ashish |
138 |
if item.weight:
|
|
|
139 |
ds_item.weight = item.weight
|
| 511 |
rajveer |
140 |
if item.itemStatus:
|
|
|
141 |
ds_item.status = item.itemStatus
|
| 122 |
ashish |
142 |
|
| 511 |
rajveer |
143 |
if item.startDate:
|
|
|
144 |
ds_item.startDate = item.startDate
|
|
|
145 |
if item.retireDate:
|
|
|
146 |
ds_item.retireDate = item.retireDate
|
|
|
147 |
|
| 122 |
ashish |
148 |
if item.featureId:
|
|
|
149 |
ds_item.feature_id = item.featureId
|
|
|
150 |
if item.featureDescription:
|
|
|
151 |
ds_item.feature_description = item.featureDescription
|
|
|
152 |
|
|
|
153 |
session.commit();
|
|
|
154 |
return ds_item.id
|
| 94 |
ashish |
155 |
|
| 103 |
ashish |
156 |
def add_item(item):
|
|
|
157 |
if not item:
|
| 122 |
ashish |
158 |
raise InventoryServiceException(108, "Bad item in request")
|
| 103 |
ashish |
159 |
if get_Item(item.id):
|
| 122 |
ashish |
160 |
raise InventoryServiceException(101, "Item already exists")
|
| 483 |
rajveer |
161 |
|
| 103 |
ashish |
162 |
ds_item = Item()
|
| 122 |
ashish |
163 |
if item.id:
|
|
|
164 |
ds_item.id = item.id
|
| 515 |
rajveer |
165 |
if item.manufacturerName:
|
|
|
166 |
ds_item.manufacturer_name = item.manufacturerName
|
|
|
167 |
if item.modelName:
|
|
|
168 |
ds_item.model_name = item.modelName
|
|
|
169 |
if item.modelNumber:
|
|
|
170 |
ds_item.model_number = item.modelNumber
|
| 483 |
rajveer |
171 |
if item.category:
|
|
|
172 |
ds_item.category = item.category
|
|
|
173 |
if item.comments:
|
|
|
174 |
ds_item.comments = item.comments
|
|
|
175 |
|
| 122 |
ashish |
176 |
if item.catalogItemId:
|
|
|
177 |
ds_item.catalog_item_id = item.catalogItemId
|
|
|
178 |
if item.vendorItemId:
|
|
|
179 |
ds_item.vendor_item_id = item.vendorItemId
|
|
|
180 |
else:
|
|
|
181 |
raise InventoryServiceException(101, "vendor item id cannot be missing")
|
|
|
182 |
if item.itemStatus:
|
|
|
183 |
ds_item.status = item.itemStatus
|
|
|
184 |
else: #this is for update calls
|
|
|
185 |
ds_item.status = status.IN_PROCESS
|
| 103 |
ashish |
186 |
ds_item.addedOn = datetime.datetime.now()
|
| 483 |
rajveer |
187 |
if item.mrp:
|
|
|
188 |
ds_item.mrp = item.mrp
|
|
|
189 |
if item.mop:
|
|
|
190 |
ds_item.mop = item.mop
|
|
|
191 |
if item.sellingPrice:
|
|
|
192 |
ds_item.sellingPrice = item.sellingPrice
|
| 122 |
ashish |
193 |
if item.weight:
|
|
|
194 |
ds_item.weight = item.weight
|
|
|
195 |
|
|
|
196 |
if item.featureId:
|
|
|
197 |
ds_item.feature_id = item.featureId
|
|
|
198 |
if item.featureDescription:
|
|
|
199 |
ds_item.feature_description = item.featureDescription
|
|
|
200 |
|
| 103 |
ashish |
201 |
if item.otherInfo:
|
|
|
202 |
for k,v in item.otherInfo.iteritems():
|
|
|
203 |
info = ItemInfo()
|
|
|
204 |
info.key = k
|
|
|
205 |
info.value = v
|
|
|
206 |
ds_item.iteminfo.append(info)
|
|
|
207 |
#check if categories present. If yes, add them to system
|
| 122 |
ashish |
208 |
|
| 103 |
ashish |
209 |
session.commit();
|
|
|
210 |
return ds_item.id
|
|
|
211 |
|
| 483 |
rajveer |
212 |
#this is no more used
|
| 122 |
ashish |
213 |
def update_price(item, ds_item):
|
|
|
214 |
log_entry("update_price", "updating price for item")
|
|
|
215 |
for k,v in item.price.iteritems():
|
|
|
216 |
price = Price()
|
|
|
217 |
price.warehouse_id = k
|
|
|
218 |
price.price = v
|
| 386 |
ashish |
219 |
price.item = ds_item
|
|
|
220 |
session.commit()
|
| 122 |
ashish |
221 |
|
| 483 |
rajveer |
222 |
#this is no more used
|
| 122 |
ashish |
223 |
def update_price_for_warehouse(item_id, warehouse_id, price):
|
|
|
224 |
log_entry("update_price", "updating price for item and warehouse")
|
|
|
225 |
price = Price.query.filter_by(warehouse_id=warehouse_id, item_id=item_id).one()
|
|
|
226 |
if not price:
|
|
|
227 |
price = Price()
|
|
|
228 |
item = get_Item(item_id)
|
|
|
229 |
price.warehouse_id = warehouse_id
|
|
|
230 |
price.item = item
|
|
|
231 |
price.price = price
|
|
|
232 |
session.commit()
|
| 94 |
ashish |
233 |
|
|
|
234 |
|
| 483 |
rajveer |
235 |
def update_inventory(warehouse_id, timestamp, availability):
|
|
|
236 |
warehouse = get_Warehouse(warehouse_id)
|
|
|
237 |
if not warehouse:
|
|
|
238 |
raise InventoryServiceException(107, "Warehouse? Where?")
|
|
|
239 |
|
|
|
240 |
time = datetime.datetime.now()
|
|
|
241 |
warehouse.lastCheckedOn = time
|
|
|
242 |
warehouse.vendorString = timestamp
|
|
|
243 |
|
|
|
244 |
for k,v in availability.iteritems():
|
|
|
245 |
vendor_id = k
|
|
|
246 |
quantity = v
|
|
|
247 |
try:
|
| 494 |
rajveer |
248 |
item = Item.query.filter_by(vendor_item_id=vendor_id).one()
|
|
|
249 |
except:
|
|
|
250 |
continue
|
|
|
251 |
try:
|
| 483 |
rajveer |
252 |
item_inventory_history = ItemInventoryHistory()
|
|
|
253 |
item_inventory_history.warehouse = warehouse
|
|
|
254 |
item_inventory_history.item = item
|
|
|
255 |
item_inventory_history.timestamp = time
|
|
|
256 |
item_inventory_history.availibility = quantity
|
|
|
257 |
|
|
|
258 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item=item, warehouse=warehouse)
|
|
|
259 |
if not current_inventory_snapshot:
|
|
|
260 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
|
|
261 |
current_inventory_snapshot.item = item
|
|
|
262 |
current_inventory_snapshot.warehouse = warehouse
|
|
|
263 |
current_inventory_snapshot.availibility = 0
|
|
|
264 |
# added the difference in the current inventory
|
|
|
265 |
current_inventory_snapshot.availibility = current_inventory_snapshot.availibility + quantity
|
|
|
266 |
except:
|
|
|
267 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
|
|
268 |
session.commit()
|
|
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
#this is no more used
|
|
|
273 |
def update_inventory_old(item_id, warehouse_id, quantity, timestamp):
|
| 94 |
ashish |
274 |
item = get_Item(item_id)
|
|
|
275 |
warehouse = get_Warehouse(warehouse_id)
|
| 122 |
ashish |
276 |
time = to_py_date(timestamp)
|
| 94 |
ashish |
277 |
|
|
|
278 |
if not item:
|
| 122 |
ashish |
279 |
raise InventoryServiceException(106, "Item not found, how did you get this?")
|
| 94 |
ashish |
280 |
if not warehouse:
|
| 122 |
ashish |
281 |
raise InventoryServiceException(107, "Warehouse? Where?")
|
| 94 |
ashish |
282 |
try:
|
|
|
283 |
item_inventory_history = ItemInventoryHistory()
|
|
|
284 |
item_inventory_history.warehouse = warehouse
|
|
|
285 |
item_inventory_history.item = item
|
|
|
286 |
item_inventory_history.timestamp = time
|
| 122 |
ashish |
287 |
item_inventory_history.availibility = quantity
|
| 94 |
ashish |
288 |
|
|
|
289 |
current_inventory_snapshot = CurrentInventorySnapshot.get_by(item=item, warehouse=warehouse)
|
| 122 |
ashish |
290 |
if not current_inventory_snapshot:
|
|
|
291 |
current_inventory_snapshot = CurrentInventorySnapshot()
|
|
|
292 |
current_inventory_snapshot.item = item
|
|
|
293 |
current_inventory_snapshot.warehouse = warehouse
|
|
|
294 |
|
| 94 |
ashish |
295 |
current_inventory_snapshot.availibility = quantity
|
|
|
296 |
current_inventory_snapshot.checkedOn = time
|
|
|
297 |
session.commit()
|
|
|
298 |
except:
|
| 122 |
ashish |
299 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 94 |
ashish |
300 |
|
|
|
301 |
def get_item_inventoy(item_id):
|
|
|
302 |
|
|
|
303 |
inventory = Item.get_by(id=item_id).currentInventory
|
|
|
304 |
if not inventory:
|
| 122 |
ashish |
305 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
| 94 |
ashish |
306 |
return inventory
|
|
|
307 |
|
| 383 |
ashish |
308 |
def get_item_inventory_by_catalog_id(item_id):
|
| 379 |
ashish |
309 |
inventory = Item.get_by(catalog_item_id=item_id).currentInventory
|
|
|
310 |
if not inventory:
|
|
|
311 |
raise InventoryServiceException(108, "Some unforeseen error while updating inventory")
|
|
|
312 |
return inventory
|
|
|
313 |
|
| 103 |
ashish |
314 |
|
|
|
315 |
def retire_warehouse(warehouse_id):
|
|
|
316 |
if not warehouse_id:
|
| 122 |
ashish |
317 |
raise InventoryServiceException(101, "Bad warehouse id")
|
| 103 |
ashish |
318 |
warehouse = get_Warehouse(warehouse_id)
|
|
|
319 |
if not warehouse:
|
| 122 |
ashish |
320 |
raise InventoryServiceException(108, "warehouse id not present")
|
|
|
321 |
warehouse.status = status.DELETED;
|
| 103 |
ashish |
322 |
session.commit()
|
|
|
323 |
|
|
|
324 |
def retire_item(item_id):
|
|
|
325 |
if not item_id:
|
| 122 |
ashish |
326 |
raise InventoryServiceException(101, "bad item id")
|
| 103 |
ashish |
327 |
item = get_Item(item_id)
|
|
|
328 |
if not item:
|
| 122 |
ashish |
329 |
raise InventoryServiceException(108, "item id not present")
|
|
|
330 |
item.status = status.PHASED_OUT
|
|
|
331 |
item.retireDate = datetime.datetime.now()
|
| 103 |
ashish |
332 |
session.commit()
|
| 122 |
ashish |
333 |
|
|
|
334 |
#need to implement threads based solution here
|
| 103 |
ashish |
335 |
def start_item_on(item_id, timestamp):
|
|
|
336 |
if not item_id:
|
| 122 |
ashish |
337 |
raise InventoryServiceException(101, "bad item id")
|
| 103 |
ashish |
338 |
item = get_Item(item_id)
|
|
|
339 |
if not item:
|
| 122 |
ashish |
340 |
raise InventoryServiceException(108, "item id not present")
|
| 103 |
ashish |
341 |
|
| 122 |
ashish |
342 |
item.status = status.ACTIVE
|
|
|
343 |
item.startDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
|
|
344 |
add_status_change_log(item, status.ACTIVE)
|
| 103 |
ashish |
345 |
session.commit()
|
|
|
346 |
|
| 122 |
ashish |
347 |
#need to implement threads here
|
| 103 |
ashish |
348 |
def retire_item_on(item_id, timestamp):
|
|
|
349 |
if not item_id:
|
| 122 |
ashish |
350 |
raise InventoryServiceException(101, "bad item id")
|
| 103 |
ashish |
351 |
item = get_Item(item_id)
|
|
|
352 |
if not item:
|
| 122 |
ashish |
353 |
raise InventoryServiceException(108, "item id not present")
|
| 103 |
ashish |
354 |
|
| 122 |
ashish |
355 |
item.status = status.PHASED_OUT
|
|
|
356 |
item.retireDate = datetime.datetime.fromtimestamp(to_py_date(timestamp))
|
|
|
357 |
add_status_change_log(item, status.PHASED_OUT)
|
| 103 |
ashish |
358 |
session.commit()
|
|
|
359 |
|
|
|
360 |
def add_status_change_log(item, new_status):
|
|
|
361 |
item_change_log = ItemChangeLog()
|
|
|
362 |
item_change_log.new_status = new_status
|
|
|
363 |
item_change_log.old_status = item.status
|
|
|
364 |
item_change_log.timestamp = datetime.datetime.now()
|
|
|
365 |
item_change_log.item = item
|
|
|
366 |
session.commit()
|
|
|
367 |
|
|
|
368 |
def change_item_status(item_id, new_status):
|
|
|
369 |
if not item_id:
|
| 122 |
ashish |
370 |
raise InventoryServiceException(101, "bad item id")
|
| 103 |
ashish |
371 |
item = get_Item(item_id)
|
|
|
372 |
if not item:
|
| 122 |
ashish |
373 |
raise InventoryServiceException(108, "item id not present")
|
| 103 |
ashish |
374 |
|
| 122 |
ashish |
375 |
item.status = new_status
|
|
|
376 |
add_status_change_log(item, new_status)
|
| 103 |
ashish |
377 |
session.commit()
|
|
|
378 |
|
|
|
379 |
def get_item_availability_for_warehouse(warehouse_id, item_id):
|
|
|
380 |
if not warehouse_id:
|
| 122 |
ashish |
381 |
raise InventoryServiceException(101, "bad warehouse_id")
|
| 103 |
ashish |
382 |
if not item_id:
|
| 122 |
ashish |
383 |
raise InventoryServiceException(101, "bad item_id")
|
| 103 |
ashish |
384 |
|
|
|
385 |
warehouse = get_Warehouse(warehouse_id)
|
|
|
386 |
if not warehouse:
|
| 122 |
ashish |
387 |
raise InventoryServiceException(108, "warehouse does not exist")
|
| 504 |
rajveer |
388 |
item = get_item_by_catalog_id(item_id)
|
|
|
389 |
|
| 103 |
ashish |
390 |
if not item:
|
| 122 |
ashish |
391 |
raise InventoryServiceException(108, "item does not exist")
|
|
|
392 |
|
| 494 |
rajveer |
393 |
query = CurrentInventorySnapshot.query.filter_by(warehouse_id = warehouse_id)
|
| 504 |
rajveer |
394 |
query = query.filter_by(item_id = item.id)
|
| 494 |
rajveer |
395 |
try:
|
|
|
396 |
current_inventory_snapshot = query.one()
|
|
|
397 |
return current_inventory_snapshot.availibility
|
|
|
398 |
except:
|
|
|
399 |
return 0
|
|
|
400 |
"""
|
|
|
401 |
current_inventory_snapshot = CurrentInventorySnapshot.query.filter(CurrentInventorySnapshot.warehouse_id == warehouse_id, CurrentInventorySnapshot.item_id == item_id).one()
|
| 103 |
ashish |
402 |
if not current_inventory_snapshot:
|
|
|
403 |
return 0
|
|
|
404 |
else:
|
|
|
405 |
return current_inventory_snapshot.availibility
|
| 494 |
rajveer |
406 |
"""
|
| 122 |
ashish |
407 |
def get_warehouses_for_item(item_id):
|
|
|
408 |
if not item_id:
|
|
|
409 |
raise InventoryServiceException(101, "bad item_id")
|
|
|
410 |
item = get_Item(item_id)
|
|
|
411 |
|
|
|
412 |
if not item:
|
|
|
413 |
raise InventoryServiceException(101, "bad item")
|
|
|
414 |
|
| 483 |
rajveer |
415 |
warehouses = item.currentInventory.warehouse
|
| 501 |
rajveer |
416 |
return warehouses
|
|
|
417 |
|
|
|
418 |
def get_best_sellers():
|
|
|
419 |
sellers = BestSellers.query.all()
|
|
|
420 |
|
|
|
421 |
t_sellers = []
|
|
|
422 |
for seller in sellers:
|
|
|
423 |
t_sellers.append(seller.item_id)
|
|
|
424 |
return t_sellers
|
|
|
425 |
|
|
|
426 |
def get_best_deals():
|
|
|
427 |
deals = BestDeals.query.all()
|
|
|
428 |
|
|
|
429 |
#query = BestDeals.query.all()
|
|
|
430 |
#deals = query.order_by(asc(BestDeals.priority)).all()
|
|
|
431 |
|
|
|
432 |
|
|
|
433 |
t_deals = []
|
|
|
434 |
for deal in deals:
|
|
|
435 |
t_deals.append(deal.item_id)
|
|
|
436 |
return t_deals
|
|
|
437 |
|
| 599 |
chandransh |
438 |
def get_latest_arrivals(limit):
|
|
|
439 |
items = Item.query.order_by(desc(Item.startDate)).all()[0:limit]
|
| 602 |
chandransh |
440 |
ret_items = []
|
|
|
441 |
for item in items:
|
|
|
442 |
if item:
|
|
|
443 |
ret_items.append(to_t_item(item))
|
|
|
444 |
return ret_items
|
| 598 |
chandransh |
445 |
|
| 602 |
chandransh |
446 |
def get_latest_arrivals_count(limit):
|
|
|
447 |
#FIXME: This method has not been tested. Have to talk to Rajveer to check where is it used.
|
|
|
448 |
return min(Item.query.count(), limit)
|
|
|
449 |
|
| 599 |
chandransh |
450 |
def get_latest_arrivals_catalog_ids(limit):
|
|
|
451 |
arrivals = Item.query.order_by(desc(Item.startDate)).all()[0:limit]
|
| 501 |
rajveer |
452 |
|
|
|
453 |
t_arrivals = []
|
|
|
454 |
for arrival in arrivals:
|
| 599 |
chandransh |
455 |
t_arrivals.append(arrival.catalog_item_id)
|
| 501 |
rajveer |
456 |
return t_arrivals
|