Subversion Repositories SmartDukaan

Rev

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

Rev 612 Rev 621
Line 11... Line 11...
11
from shop2020.thriftpy.model.v1.catalog.ttypes import \
11
from shop2020.thriftpy.model.v1.catalog.ttypes import \
12
    InventoryServiceException, status
12
    InventoryServiceException, status
13
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
13
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
14
import datetime
14
import datetime
15
from shop2020.utils.Utils import log_entry, to_py_date
15
from shop2020.utils.Utils import log_entry, to_py_date
16
from sqlalchemy import desc
16
from sqlalchemy import desc, asc
17
 
17
 
18
 
18
 
19
def initialize():
19
def initialize():
20
    DataService.initialize()
20
    DataService.initialize()
21
    
21
    
Line 379... Line 379...
379
        raise InventoryServiceException(101, "bad item")
379
        raise InventoryServiceException(101, "bad item")
380
    
380
    
381
    warehouses = item.currentInventory.warehouse
381
    warehouses = item.currentInventory.warehouse
382
    return warehouses
382
    return warehouses
383
 
383
 
-
 
384
def get_best_sellers(start_index, stop_index, category=None):
-
 
385
    query = get_best_sellers_query(category)
-
 
386
    best_sellers = query.order_by(asc(Item.bestSellingRank)).all()[start_index:stop_index]
-
 
387
    return get_thrift_item_list(best_sellers)
-
 
388
 
384
def get_best_sellers():
389
def get_best_sellers_count(category):
-
 
390
    query = get_best_sellers_query(category)
-
 
391
    return query.count()
-
 
392
 
-
 
393
def get_best_sellers_catalog_ids(start_index, stop_index, category):
385
    sellers = BestSellers.query.all()
394
    query = get_best_sellers_query(category)
-
 
395
    best_sellers = query.order_by(asc(Item.bestSellingRank)).all()[start_index:stop_index]
-
 
396
    return [item.catalog_item_id for item in best_sellers]
386
    
397
    
387
    t_sellers = []
398
def get_best_sellers_query(category):
-
 
399
    query = Item.query.filter(Item.bestSellingRank != None)
388
    for seller in sellers:
400
    if category != None:
389
        t_sellers.append(seller.item_id)
401
        query = query.filter_by(category=category)
390
    return t_sellers   
402
    return query
391
 
403
 
392
def get_best_deals():
404
def get_best_deals():
393
    items = Item.query.filter(Item.bestDealValue != None).all()
405
    items = Item.query.filter(Item.bestDealValue != None).order_by(desc(Item.bestDealValue)).all()
394
    return get_thrift_item_list(items)
406
    return get_thrift_item_list(items)
395
 
407
 
396
def get_best_deals_count():
408
def get_best_deals_count():
397
    return Item.query.filter(Item.bestDealValue != None).count()
409
    return Item.query.filter(Item.bestDealValue != None).count()
398
    
410
    
399
def get_best_deals_catalog_ids(start_index, total_items):
411
def get_best_deals_catalog_ids(start_index, stop_index, category=None):
400
    stop_index = start_index + total_items
-
 
401
    best_deal_items = Item.query.filter(Item.bestDealValue != None).order_by(desc(Item.bestDealValue)).all()[start_index:stop_index]
412
    query = Item.query.filter(Item.bestDealValue != None)
402
    t_deals = []
413
    if category != None:
403
    for deal in best_deal_items:
414
        query = query.filter_by(category=category)
404
        t_deals.append(deal.catalog_item_id)
415
    best_deal_items = query.order_by(desc(Item.bestDealValue)).all()[start_index:stop_index]
405
    return t_deals
416
    return [item.catalog_item_id for item in best_deal_items]
406
 
417
 
407
def get_latest_arrivals(limit):
418
def get_latest_arrivals(limit):
408
    items = Item.query.order_by(desc(Item.startDate)).all()[0:limit]
419
    items = Item.query.order_by(desc(Item.startDate)).all()[0:limit]
409
    return get_thrift_item_list(items)
420
    return get_thrift_item_list(items)
410
    
421
    
411
def get_latest_arrivals_count(limit):
422
def get_latest_arrivals_count(limit):
412
    #FIXME: This method has not been functionally tested. Have to talk to Rajveer to check where is it used.
423
    #FIXME: This method has not been functionally tested. Have to talk to Rajveer to check where is it used.
413
    return min(Item.query.count(), limit)
424
    return min(Item.query.count(), limit)
414
    
425
    
415
def get_latest_arrivals_catalog_ids(start_index, total_items):
426
def get_latest_arrivals_catalog_ids(start_index, stop_index, category=None):
416
    stop_index = start_index + total_items
427
    query = Item.query
417
    arrivals = Item.query.order_by(desc(Item.startDate)).all()[start_index:stop_index]
-
 
418
    
-
 
419
    t_arrivals = []
428
    if category != None:
420
    for arrival in arrivals:
429
        query = query.filter_by(category=category)
421
        t_arrivals.append(arrival.catalog_item_id)
430
    latest_arrivals = query.order_by(desc(Item.startDate)).all()[start_index:stop_index]
422
    return t_arrivals    
431
    return [item.catalog_item_id for item in latest_arrivals] 
423
 
432
 
424
def get_thrift_item_list(items):
433
def get_thrift_item_list(items):
425
    ret_items = []
434
    ret_items = []
426
    for item in items:
435
    for item in items:
427
        if item:
436
        if item: