| Line 14... |
Line 14... |
| 14 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
|
14 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item
|
| 15 |
import datetime
|
15 |
import datetime
|
| 16 |
import sys
|
16 |
import sys
|
| 17 |
from shop2020.utils.Utils import log_entry, to_py_date
|
17 |
from shop2020.utils.Utils import log_entry, to_py_date
|
| 18 |
from sqlalchemy import desc, asc
|
18 |
from sqlalchemy import desc, asc
|
| - |
|
19 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
| 19 |
|
20 |
|
| 20 |
|
21 |
|
| 21 |
def initialize():
|
22 |
def initialize():
|
| 22 |
DataService.initialize()
|
23 |
DataService.initialize()
|
| 23 |
|
24 |
|
| Line 470... |
Line 471... |
| 470 |
def get_best_sellers_catalog_ids(start_index, stop_index, brand, category=-1):
|
471 |
def get_best_sellers_catalog_ids(start_index, stop_index, brand, category=-1):
|
| 471 |
query = get_best_sellers_query(category, brand)
|
472 |
query = get_best_sellers_query(category, brand)
|
| 472 |
best_sellers = query.all()[start_index:stop_index]
|
473 |
best_sellers = query.all()[start_index:stop_index]
|
| 473 |
return [item.catalog_item_id for item in best_sellers]
|
474 |
return [item.catalog_item_id for item in best_sellers]
|
| 474 |
|
475 |
|
| - |
|
476 |
def get_child_categories(category):
|
| - |
|
477 |
cm = CategoryManager()
|
| - |
|
478 |
return cm.getCategory(category).children_category_ids
|
| - |
|
479 |
|
| 475 |
def get_best_sellers_query(category, brand):
|
480 |
def get_best_sellers_query(category, brand):
|
| 476 |
query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
|
481 |
query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestSellingRank != None)
|
| 477 |
if category != -1:
|
482 |
if category != -1:
|
| - |
|
483 |
all_categories = [category]
|
| - |
|
484 |
child_categories = get_child_categories(category)
|
| - |
|
485 |
if child_categories is not None:
|
| - |
|
486 |
all_categories = all_categories + child_categories
|
| 478 |
query = query.filter_by(category=category)
|
487 |
query = query.filter(Item.category.in_(all_categories))
|
| 479 |
if brand is not None:
|
488 |
if brand is not None:
|
| 480 |
query = query.filter_by(brand=brand)
|
489 |
query = query.filter_by(brand=brand)
|
| 481 |
query = query.order_by(asc(Item.bestSellingRank))
|
490 |
query = query.order_by(asc(Item.bestSellingRank))
|
| 482 |
return query
|
491 |
return query
|
| 483 |
|
492 |
|
| Line 498... |
Line 507... |
| 498 |
return [item.catalog_item_id for item in best_deal_items]
|
507 |
return [item.catalog_item_id for item in best_deal_items]
|
| 499 |
|
508 |
|
| 500 |
def get_best_deals_query(category, brand):
|
509 |
def get_best_deals_query(category, brand):
|
| 501 |
query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
|
510 |
query = Item.query.filter_by(status=status.ACTIVE).filter(Item.bestDealValue != None)
|
| 502 |
if category != -1:
|
511 |
if category != -1:
|
| - |
|
512 |
all_categories = [category]
|
| - |
|
513 |
child_categories = get_child_categories(category)
|
| - |
|
514 |
if child_categories is not None:
|
| - |
|
515 |
all_categories = all_categories + child_categories
|
| 503 |
query = query.filter_by(category=category)
|
516 |
query = query.filter(Item.category.in_(all_categories))
|
| 504 |
if brand is not None:
|
517 |
if brand is not None:
|
| 505 |
query = query.filter_by(brand=brand)
|
518 |
query = query.filter_by(brand=brand)
|
| 506 |
query = query.group_by(Item.catalog_item_id).order_by(desc(Item.bestDealValue))
|
519 |
query = query.group_by(Item.catalog_item_id).order_by(desc(Item.bestDealValue))
|
| 507 |
return query
|
520 |
return query
|
| 508 |
|
521 |
|
| Line 524... |
Line 537... |
| 524 |
return [item.catalog_item_id for item in latest_arrivals]
|
537 |
return [item.catalog_item_id for item in latest_arrivals]
|
| 525 |
|
538 |
|
| 526 |
def get_latest_arrivals_query(category, brand):
|
539 |
def get_latest_arrivals_query(category, brand):
|
| 527 |
query = Item.query.filter_by(status=status.ACTIVE)
|
540 |
query = Item.query.filter_by(status=status.ACTIVE)
|
| 528 |
if category != -1:
|
541 |
if category != -1:
|
| - |
|
542 |
all_categories = [category]
|
| - |
|
543 |
child_categories = get_child_categories(category)
|
| - |
|
544 |
if child_categories is not None:
|
| - |
|
545 |
all_categories = all_categories + child_categories
|
| 529 |
query = query.filter_by(category=category)
|
546 |
query = query.filter(Item.category.in_(all_categories))
|
| 530 |
if brand is not None:
|
547 |
if brand is not None:
|
| 531 |
query = query.filter_by(brand=brand)
|
548 |
query = query.filter_by(brand=brand)
|
| 532 |
query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate))
|
549 |
query = query.group_by(Item.catalog_item_id).order_by(desc(Item.startDate))
|
| 533 |
return query
|
550 |
return query
|
| 534 |
|
551 |
|
| Line 570... |
Line 587... |
| 570 |
except sqlalchemy.orm.exc.MultipleResultsFound:
|
587 |
except sqlalchemy.orm.exc.MultipleResultsFound:
|
| 571 |
raise InventoryServiceException(110, "Multiple pricing information present for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
588 |
raise InventoryServiceException(110, "Multiple pricing information present for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
| 572 |
except sqlalchemy.orm.exc.NoResultFound:
|
589 |
except sqlalchemy.orm.exc.NoResultFound:
|
| 573 |
raise InventoryServiceException(111, "Missing pricing information for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
590 |
raise InventoryServiceException(111, "Missing pricing information for Vendor: " + vendor.name + " and Item: " + str(item_id))
|
| 574 |
|
591 |
|
| - |
|
592 |
def add_category(t_category):
|
| - |
|
593 |
category = Category.get_by(id=t_category.id)
|
| - |
|
594 |
if category is None:
|
| - |
|
595 |
category = Category()
|
| - |
|
596 |
category.id = t_category.id
|
| - |
|
597 |
category.label = t_category.label
|
| - |
|
598 |
category.description = t_category.description
|
| - |
|
599 |
category.parent_category_id = t_category.parent_category_id
|
| - |
|
600 |
session.commit()
|
| - |
|
601 |
return True
|
| - |
|
602 |
|
| - |
|
603 |
def get_category(id):
|
| - |
|
604 |
return Category.query.filter_by(id=id).first()
|
| - |
|
605 |
|
| - |
|
606 |
def get_all_categories():
|
| - |
|
607 |
return Category.query.all()
|
| - |
|
608 |
|
| 575 |
def close_session():
|
609 |
def close_session():
|
| 576 |
if session.is_active:
|
610 |
if session.is_active:
|
| 577 |
print "session is active. closing it."
|
611 |
print "session is active. closing it."
|
| 578 |
session.close()
|
612 |
session.close()
|