| Line 8... |
Line 8... |
| 8 |
from shop2020.clients.HelperClient import HelperClient
|
8 |
from shop2020.clients.HelperClient import HelperClient
|
| 9 |
from shop2020.clients.TransactionClient import TransactionClient
|
9 |
from shop2020.clients.TransactionClient import TransactionClient
|
| 10 |
from shop2020.config.client.ConfigClient import ConfigClient
|
10 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| 11 |
from shop2020.model.v1.catalog.impl import DataService
|
11 |
from shop2020.model.v1.catalog.impl import DataService
|
| 12 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
12 |
from shop2020.model.v1.catalog.impl.CategoryManager import CategoryManager
|
| 13 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, \
|
13 |
from shop2020.model.v1.catalog.impl.Convertors import to_t_item, to_t_source
|
| 14 |
to_t_vendor_item_pricing, to_t_source
|
- |
|
| 15 |
from shop2020.model.v1.catalog.impl.DataService import Item, Warehouse, \
|
14 |
from shop2020.model.v1.catalog.impl.DataService import Item, Warehouse, \
|
| 16 |
ItemInventoryHistory, CurrentInventorySnapshot, ItemChangeLog, \
|
15 |
ItemInventoryHistory, CurrentInventorySnapshot, ItemChangeLog, \
|
| 17 |
Category, EntityIDGenerator, VendorItemPricing, VendorItemMapping, Vendor, \
|
16 |
Category, EntityIDGenerator, VendorItemPricing, VendorItemMapping, Vendor, \
|
| 18 |
SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog, \
|
17 |
SimilarItems, ProductNotification, Source, SourceItemPricing, AuthorizationLog, \
|
| 19 |
MissedInventoryUpdate, BadInventorySnapshot, VendorItemProcurementDelay, \
|
18 |
MissedInventoryUpdate, BadInventorySnapshot, VendorItemProcurementDelay, \
|
| 20 |
VendorHolidays
|
19 |
VendorHolidays, ItemAvailabilityCache
|
| 21 |
from shop2020.thriftpy.model.v1.catalog.ttypes import InventoryServiceException, \
|
20 |
from shop2020.thriftpy.model.v1.catalog.ttypes import InventoryServiceException, \
|
| 22 |
status, ItemShippingInfo, HolidayType, InventoryType, WarehouseType
|
21 |
status, ItemShippingInfo, HolidayType, InventoryType
|
| 23 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
22 |
from shop2020.thriftpy.model.v1.order.ttypes import AlertType
|
| 24 |
from shop2020.utils import EmailAttachmentSender
|
23 |
from shop2020.utils import EmailAttachmentSender
|
| 25 |
from shop2020.utils.EmailAttachmentSender import mail
|
24 |
from shop2020.utils.EmailAttachmentSender import mail
|
| 26 |
from shop2020.utils.Utils import log_entry, to_py_date, log_risky_flag
|
25 |
from shop2020.utils.Utils import to_py_date, log_risky_flag
|
| 27 |
from sqlalchemy import desc, asc
|
26 |
from sqlalchemy import desc, asc
|
| 28 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
27 |
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
|
| 29 |
from sqlalchemy.sql.expression import and_, or_, distinct, func
|
28 |
from sqlalchemy.sql.expression import and_, or_, distinct, func
|
| 30 |
from string import Template
|
29 |
from string import Template
|
| 31 |
from urllib2 import HTTPBasicAuthHandler
|
30 |
from urllib2 import HTTPBasicAuthHandler
|
| Line 39... |
Line 38... |
| 39 |
|
38 |
|
| 40 |
to_addresses = ["cnc.center@shop2020.in", "ashutosh.saxena@shop2020.in"]
|
39 |
to_addresses = ["cnc.center@shop2020.in", "ashutosh.saxena@shop2020.in"]
|
| 41 |
from_user = "cnc.center@shop2020.in"
|
40 |
from_user = "cnc.center@shop2020.in"
|
| 42 |
from_pwd = "5h0p2o2o"
|
41 |
from_pwd = "5h0p2o2o"
|
| 43 |
|
42 |
|
| 44 |
item_availability_cache = {}
|
- |
|
| 45 |
|
- |
|
| 46 |
def initialize(dbname='catalog', db_hostname="localhost"):
|
43 |
def initialize(dbname='catalog', db_hostname="localhost"):
|
| 47 |
DataService.initialize(dbname, db_hostname)
|
44 |
DataService.initialize(dbname, db_hostname)
|
| - |
|
45 |
__clear_item_availability_cache()
|
| 48 |
|
46 |
|
| 49 |
def get_all_items_by_status(status, offset=0, limit=None):
|
47 |
def get_all_items_by_status(status, offset=0, limit=None):
|
| 50 |
query = Item.query
|
48 |
query = Item.query
|
| 51 |
if status is not None:
|
49 |
if status is not None:
|
| 52 |
query = query.filter_by(status=status)
|
50 |
query = query.filter_by(status=status)
|
| Line 728... |
Line 726... |
| 728 |
item.updatedOn = current_timestamp
|
726 |
item.updatedOn = current_timestamp
|
| 729 |
session.commit()
|
727 |
session.commit()
|
| 730 |
return True
|
728 |
return True
|
| 731 |
|
729 |
|
| 732 |
def get_item_availability_for_location(item_id):
|
730 |
def get_item_availability_for_location(item_id):
|
| 733 |
if item_availability_cache.has_key(item_id):
|
731 |
item_availability = ItemAvailabilityCache.get_by(itemId=item_id)
|
| 734 |
return item_availability_cache[item_id]
|
732 |
if item_availability:
|
| - |
|
733 |
return [item_availability.warehouseId, item_availability.expectedDelay, item_availability.billingWarehouseId, item_availability.sellingPrice]
|
| - |
|
734 |
else:
|
| 735 |
__update_item_availability_cache(item_id)
|
735 |
__update_item_availability_cache(item_id)
|
| 736 |
return item_availability_cache[item_id]
|
736 |
return get_item_availability_for_location(item_id)
|
| 737 |
|
737 |
|
| 738 |
def __cache_item_availability():
|
738 |
def __clear_item_availability_cache():
|
| 739 |
items = Item.query.filter(Item.status.in_((status.ACTIVE, status.COMING_SOON, status.PAUSED, status.PAUSED_BY_RISK))).all()
|
739 |
ItemAvailabilityCache.query.delete()
|
| 740 |
for item in items:
|
740 |
session.commit()
|
| 741 |
__update_item_availability_cache(item.id)
|
- |
|
| 742 |
|
741 |
|
| 743 |
def __update_item_availability_cache(item_id):
|
742 |
def __update_item_availability_cache(item_id):
|
| 744 |
"""
|
743 |
"""
|
| 745 |
Determines the warehouse that should be used to fulfil an order for the given item.
|
744 |
Determines the warehouse that should be used to fulfil an order for the given item.
|
| 746 |
Algorithm explained at https://sites.google.com/a/shop2020.in/virtual-w-h-and-inventory/technical-details
|
745 |
Algorithm explained at https://sites.google.com/a/shop2020.in/virtual-w-h-and-inventory/technical-details
|
| Line 853... |
Line 852... |
| 853 |
expectedDelay = int(item.expectedDelay)
|
852 |
expectedDelay = int(item.expectedDelay)
|
| 854 |
|
853 |
|
| 855 |
if total_availability <= 0:
|
854 |
if total_availability <= 0:
|
| 856 |
expectedDelay = expectedDelay + __get_expected_procurement_delay(item)
|
855 |
expectedDelay = expectedDelay + __get_expected_procurement_delay(item)
|
| 857 |
expectedDelay = expectedDelay + __get_vendor_holiday_delay(item, expectedDelay)
|
856 |
expectedDelay = expectedDelay + __get_vendor_holiday_delay(item, expectedDelay)
|
| 858 |
|
857 |
|
| - |
|
858 |
item_availability_cache = ItemAvailabilityCache.get_by(itemId=item_id)
|
| - |
|
859 |
if item_availability_cache is None:
|
| - |
|
860 |
item_availability_cache = ItemAvailabilityCache()
|
| - |
|
861 |
item_availability_cache.itemId = item_id
|
| - |
|
862 |
item_availability_cache.warehouseId = int(warehouse_retid)
|
| - |
|
863 |
item_availability_cache.expectedDelay = expectedDelay
|
| 859 |
item_availability_cache[item_id] = [int(warehouse_retid), expectedDelay, billingWarehouseId, item.sellingPrice]
|
864 |
item_availability_cache.billingWarehouseId = billingWarehouseId
|
| - |
|
865 |
item_availability_cache.sellingPrice = item.sellingPrice
|
| - |
|
866 |
session.commit()
|
| 860 |
|
867 |
|
| 861 |
def __get_warehouse_with_max_availability(warehouse_ids, item):
|
868 |
def __get_warehouse_with_max_availability(warehouse_ids, item):
|
| 862 |
warehouse_retid = -1
|
869 |
warehouse_retid = -1
|
| 863 |
max_availability = 0
|
870 |
max_availability = 0
|
| 864 |
total_availability = 0
|
871 |
total_availability = 0
|