Rev 5313 | Rev 5437 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 27-Apr-2010@author: ashish'''from shop2020.clients.CatalogClient import CatalogClientfrom shop2020.clients.PurchaseClient import PurchaseClientfrom shop2020.config.client.ConfigClient import ConfigClientfrom shop2020.model.v1.catalog.impl import DataServicefrom shop2020.model.v1.catalog.impl.Convertors import to_t_item, \to_t_item_inventory, to_t_warehouse, to_t_vendor_item_pricing, to_t_category, \to_t_vendor, to_t_vendor_item_mapping, to_t_source_item_pricing, \to_t_product_notification_request, to_t_product_notification_request_countfrom shop2020.model.v1.catalog.impl.DataAcessors import add_item, add_warehouse, \update_inventory, retire_warehouse, retire_item, change_item_status, get_item, \get_all_items, get_all_items_by_status, get_item_availability_for_warehouse, \get_item_availability_for_location, get_all_warehouses_by_status, get_Warehouse, \get_all_warehouses_for_item, get_all_items_for_warehouse, update_item, \start_item_on, close_session, add_vendor, retire_item_on, get_item_inventory_by_item_id, \get_items_by_catalog_id, get_best_deals, get_best_deals_catalog_ids, \get_best_deals_count, get_best_sellers, get_latest_arrivals, \get_latest_arrivals_catalog_ids, get_latest_arrivals_count, is_active, \get_best_sellers_catalog_ids, get_best_sellers_count, put_category_object, \get_category_object, mark_item_as_content_complete, reserve_item_in_warehouse, \reduce_reservation_count, generate_new_entity_id, get_all_item_pricing, \add_vendor_pricing, get_item_pricing, get_category, get_all_categories, \add_category, get_item_status_description, get_all_vendors, get_item_mappings, \add_vendor_item_mapping, check_similar_item, change_risky_flag, \get_items_for_mastersheet, get_risky_items, get_similar_items_catalog_ids, \add_product_notification, send_product_notifications, update_inventory_history, \get_all_brands_by_category, is_alive, get_item_pricing_by_source, \add_source_item_pricing, get_all_sources, get_item_for_source, \get_all_source_pricing, get_item_count_by_status, search_items, \get_search_result_count, get_pending_orders_inventory, get_product_notifications, \get_product_notification_request_count, add_inventory, \get_all_similar_items_catalog_ids, add_similar_item_catalog_id, \delete_similar_item_catalog_id, add_authorization_log_for_item, \get_thrift_item_list, get_all_brands, add_bad_inventory, \mark_missed_inventory_updates_as_processed, \get_item_keys_to_be_processed, reset_availability, get_shipping_locations,\get_coming_soon, get_coming_soon_catalog_ids, get_coming_soon_count,\initialize, get_inventory_snapshot, clear_item_availability_cachefrom shop2020.model.v1.catalog.impl.DataService import Warehouse, \MissedInventoryUpdate, VendorItemMappingfrom shop2020.thriftpy.model.v1.catalog.ttypes import status, \InventoryServiceException, AvailableAndReservedStock, WarehouseType, InventoryTypefrom shop2020.thriftpy.purchase.ttypes import PurchaseOrder, LineItemfrom shop2020.utils.Utils import log_entry, to_py_date, to_java_dateimport datetimeimport xlrdclass InventoryServiceHandler:'''classdocs'''def __init__(self, dbname='catalog', db_hostname='localhost'):'''Constructor'''initialize(dbname, db_hostname)try:config_client = ConfigClient()self.latest_arrivals_limit = int(config_client.get_property("LATEST_ARRIVALS_LIMIT"));self.best_sellers_limit = int(config_client.get_property("BEST_SELLERS_LIMIT"))except:self.latest_arrivals_limit = 50self.best_sellers_limit = 50#DONEdef addItem(self, item):"""Availability and inventory attributesParameters:- item"""log_entry(self, "addItem called")try:return add_item(item)finally:close_session()def addWarehouse(self, warehouse):"""Parameters:- warehouse"""log_entry(self, "addWarehouse called")try:return add_warehouse(warehouse)finally:close_session()def updateInventoryHistory(self, warehouse_id, timestamp, availability):"""Stores the incremental warehouse updates of items.Parameters:- warehouse_id- timestamp- availability"""try:return update_inventory_history(warehouse_id, timestamp, availability)finally:close_session()def updateInventory(self, warehouse_id, timestamp, availability):"""Parameters:- warehouse_id- timestamp- availability"""log_entry(self, "update Inventory called")try:return update_inventory(warehouse_id, timestamp, availability)finally:close_session()def addInventory(self, itemId, warehouseId, quantity):"""Add the inventory to existing stock.Parameters:- itemId- warehouseId- quantity"""log_entry(self, "add Inventory called")try:return add_inventory(itemId, warehouseId, quantity)finally:close_session()def isActive(self, item_id):"""Parameters:- item_id"""try:return is_active(item_id)finally:close_session()def getItemStatusDescription(self, itemId):"""Parameters:- itemId"""try:return get_item_status_description(itemId)finally:close_session()def retireWarehouse(self, warehouse_id):"""Parameters:- warehouse_id"""log_entry(self, "retire warehouse called")try:return retire_warehouse(warehouse_id)finally:close_session()def retireItem(self, item_id):"""Parameters:- item_id"""log_entry(self, "retire item called")try:return retire_item(item_id)finally:close_session()def startItemOn(self, item_id, timestamp):"""Parameters:- item_id- timestamp"""try:start_item_on(item_id, timestamp)finally:close_session()def retireItemOn(self, item_id, timestamp):"""Parameters:- item_id- timestamp"""try:retire_item_on(item_id, timestamp)finally:close_session()def changeItemStatus(self, item_id, timestamp, newstatus):"""Parameters:- item_id- timestamp- newstatus"""log_entry(self, "change item status called")try:return change_item_status(item_id, newstatus)finally:close_session()def getItem(self, item_id):"""Parameters:- item_id"""log_entry(self, "item requested")try:item = to_t_item( get_item(item_id))return itemfinally:close_session()def getItemsByCatalogId(self, catalog_item_id):"""Parameters:- catalog_item_id"""log_entry(self, "item requested")try:return get_thrift_item_list(get_items_by_catalog_id(catalog_item_id))finally:close_session()def getValidItemsByCatalogId(self, catalog_item_id):"""Parameters:- catalog_item_id"""log_entry(self, "items requested for CatalogItem")try:return get_thrift_item_list(filter(is_valid, get_items_by_catalog_id(catalog_item_id)))finally:close_session()def getAllItems(self, isActive):"""Parameters:- isActive"""log_entry(self, "all items requested")try:items = get_all_items(isActive)ret_items = []for item in items:if item:ret_items.append(to_t_item(item))return ret_itemsfinally:close_session()def getAllItemsByStatus(self, itemStatus):"""Parameters:- itemStatus"""log_entry(self, "all items requested")try:items = get_all_items_by_status(itemStatus)ret_items = []for item in items:if item:ret_items.append(to_t_item(item))return ret_itemsfinally:close_session()'''def getItemInventory(self, item_id):"""Parameters:- item_id"""log_entry(self, "item inventory requested")try:inventory = get_item_inventoy(item_id)return to_t_item_inventory(inventory, item_id)finally:close_session()'''def getItemInventoryByItemId(self, item_id):"""Parameters:- item_id"""log_entry(self, "item inventory requested")try:inventory = get_item_inventory_by_item_id(item_id)return to_t_item_inventory(inventory, item_id)finally:close_session()def getAllBrandsByCategory(self, categoryId):"""Parameters:- categoryId"""try:return get_all_brands_by_category(categoryId)finally:close_session()def getAllBrands(self):try:return get_all_brands()finally:close_session()'''def getItemInventoryByCatalogId(self, item_id):"""Parameters:- item_id"""log_entry(self, "item inventory requested")inventory = get_item_inventory_by_catalog_id(item_id)return to_t_item_inventory(inventory, item_id)'''def getAllItemsInRange(self, offset, limit):"""Gets at most 'limit' items starting at the given offset. Returns an empty list if there are no more items at the given offset.Parameters:- offset- limit"""try:items = get_all_items(False, offset, limit)return [to_t_item(item) for item in items]finally:close_session()def getAllItemsByStatusInRange(self, itemStatus, offset, limit):"""Gets at most 'limit' items starting at the given offset in the given status. Returns an empty list if there are no more items at the given offset.Parameters:- itemStatus- offset- limit"""log_entry(self, "all items requested")try:items = get_all_items_by_status(itemStatus, offset, limit)return [to_t_item(item) for item in items]finally:close_session()def getItemCountByStatus(self, useStatus, itemStatus):"""Gets a count of all items by statusParameters:- useStatus- itemStatus"""try:return get_item_count_by_status(useStatus, itemStatus)finally:close_session()def getItemAvailabilityAtLocation(self, itemId):"""Determines the warehouse that should be used to fulfil an order for the given item.It first checks all the warehouses which are in the logistics location given by thewarehouse_loc parameter. If none of the warehouses there have any inventory, then thepreferred warehouse for the item is used.Returns an ordered list of size 4 with following elements in the given order:1. Logistics location of the warehouse which was finally picked up to ship the order.2. Id of the warehouse which was finally picked up.3. Inventory size in the selected warehouse.4. Expected delay added by the category manager.Parameters:- itemId"""try:return get_item_availability_for_location(itemId)finally:close_session()def getItemAvailibilityAtWarehouse(self, warehouse_id, item_id):"""Parameters:- warehouse_id- item_id"""log_entry(self, "item availability at warehouse requested")try:return get_item_availability_for_warehouse(warehouse_id, item_id)finally:close_session()def markItemAsContentComplete(self, entityId, category, brand, modelName, modelNumber):"""Parameters:- entityId- category- brand- modelName- modelNumber"""try:return mark_item_as_content_complete(entityId, category, brand, modelName, modelNumber)finally:close_session()def getItemInventoryHistory(self, id, item_id, warehouse_id, from_date, to_date):"""Parameters:- id- item_id- warehouse_id- from_date- to_date"""passdef getAllWarehouses(self, isActive):"""Parameters:- isActive"""try:if isActive:warehouses = get_all_warehouses_by_status(status.ACTIVE)else:warehouses = get_all_warehouses_by_status(None)ret_warehouses = []for warehouse in warehouses:ret_warehouses.append(to_t_warehouse(warehouse))return ret_warehousesfinally:close_session()def getWarehouse(self, warehouse_id):"""Parameters:- warehouse_id"""log_entry(self, "get warehouse call")try:warehouse = get_Warehouse(warehouse_id)if warehouse:return to_t_warehouse(warehouse)else:raise InventoryServiceException(101, "no such warehouse: " + str(warehouse_id))finally:close_session()def getAllWarehousesForItem(self, item_id):"""Parameters:- item_id"""log_entry(self, "getting all warehouses for item")try:all_warehouses = get_all_warehouses_for_item(item_id)t_warehouses = []for warehouse in all_warehouses:t_warehouses.append(to_t_warehouse(warehouse))return t_warehousesfinally:close_session()def getAllItemsForWarehouse(self, warehouse_id):"""Parameters:- warehouse_id"""log_entry(self, "getting all items for warehouse")try:all_items = get_all_items_for_warehouse(warehouse_id)t_items = []for item in all_items:t_items.append(to_t_item(item))return t_itemsfinally:close_session()def reserveItemInWarehouse(self, itemId, warehouseId, quantity):"""Increases the reservation count for an item in a warehouse. Should always succeed normally.Parameters:- itemId- warehouseId"""log_entry(self, "reserveItemInWarehouse called")try:return reserve_item_in_warehouse(itemId, warehouseId, quantity)finally:close_session()def reduceReservationCount(self, itemId, warehouseId, quantity):"""Decreases the reservation count for an item in a warehouse. Should always succeed normally.Parameters:- itemId- warehouseId"""log_entry(self, "reduceReservationCount called")try:return reduce_reservation_count(itemId, warehouseId, quantity)finally:close_session()def updateItem(self, item):"""Parameters:- item"""log_entry(self, "addItem called")try:return update_item(item)finally:close_session()def getBestSellers(self, start_index=0, total_items=None, category=-1):try:if total_items is None:total_items = self.best_sellers_limitstop_index = start_index + total_itemsreturn get_best_sellers(start_index, stop_index, category)finally:close_session()def getBestSellersCatalogIds(self, start_index, total_items, brand, category=-1):"""Parameters:- beginIndex- totalItems"""try:if total_items is None:total_items = self.best_sellers_limitstop_index = start_index + total_itemsreturn get_best_sellers_catalog_ids(start_index, stop_index, brand, category)finally:close_session()def getBestSellersCount(self, ):try:return get_best_sellers_count()finally:close_session()def getBestDeals(self,):try:return get_best_deals()finally:close_session()def getBestDealsCatalogIds(self, start_index, total_items, brand,category=-1):"""Parameters:- beginIndex- totalItems"""try:stop_index = start_index + total_itemsreturn get_best_deals_catalog_ids(start_index, stop_index, brand, category)finally:close_session()def getBestDealsCount(self, ):try:return get_best_deals_count()finally:close_session()def getComingSoon(self,):try:return get_coming_soon()finally:close_session()def getComingSoonCatalogIds(self, start_index, total_items, brand,category=-1):"""Parameters:- beginIndex- totalItems"""try:stop_index = start_index + total_itemsreturn get_coming_soon_catalog_ids(start_index, stop_index, brand, category)finally:close_session()def getComingSoonCount(self, ):try:return get_coming_soon_count()finally:close_session()def getLatestArrivals(self,):try:return get_latest_arrivals(self.latest_arrivals_limit)finally:close_session()def getLatestArrivalsCatalogIds(self, beginIndex, totalItems, brand, categories):"""Returns the list of catalog ids of latest arrivals in the given categories of the given brand.To ignore the categories, pass the list as empty. To ignore brand, pass it as null.Parameters:- beginIndex- totalItems- brand- categories"""try:if beginIndex > self.latest_arrivals_limit:return []stopIndex = beginIndex + totalItemsif stopIndex > self.latest_arrivals_limit:stopIndex = self.latest_arrivals_limitreturn get_latest_arrivals_catalog_ids(beginIndex, stopIndex, brand, categories)finally:close_session()def getLatestArrivalsCount(self, ):try:return get_latest_arrivals_count(self.latest_arrivals_limit)finally:close_session()def getItemPricing(self, itemId, vendorId):"""Returns the pricing information of an item associated with the vendor of the given warehouse.Raises an exception if either the item, vendor or the associated pricing information can't be found.Parameters:- itemId- warehouseId"""try:return to_t_vendor_item_pricing(get_item_pricing(itemId, vendorId))finally:close_session()def getAllItemPricing(self, itemId):"""Returns list of the pricing information of an item associated an item.Raises an exception if the item can't be found.Parameters:- itemId"""try:return [to_t_vendor_item_pricing(vid) for vid in get_all_item_pricing(itemId)]finally:close_session()def generateNewEntityID(self, ):try:return generate_new_entity_id()finally:close_session()def putCategoryObject(self, object):"""Parameters:- object"""try:return put_category_object(object)finally:close_session()def getCategoryObject(self, ):try:return get_category_object()finally:close_session()def addCategory(self, category):"""Parameters:- category"""try:return add_category(category)finally:close_session()def getCategory(self, id):"""Parameters:- id"""try:return to_t_category(get_category(id))finally:close_session()def getAllCategories(self, ):try:categories = get_all_categories()return [to_t_category(category) for category in categories]finally:close_session()def addVendorItemPricing(self, vendorItemPricing):"""Adds vendor prices corresponding to the item. If pricing already exists then updates the prices.Raises an exception if either the item or vendor can't be found corresponding to their ids.Parameters:- vendorItemPricing"""log_entry(self, "updateVendorItemPricing called")try:return add_vendor_pricing(vendorItemPricing)finally:close_session()def getAllVendors(self, ):"""Return list of all vendors"""try:return [to_t_vendor(v) for v in get_all_vendors()]finally:close_session()def getAllSimilarItems(self, itemId):"""Returns list of similar items.Parameters:- itemId"""try:return get_all_similar_items_catalog_ids(itemId)finally:close_session()def addSimilarItem(self, itemId, catalogItemId):"""add similar item.Parameters:- itemId, catalogItemId"""try:return add_similar_item_catalog_id(itemId, catalogItemId)finally:close_session()def deleteSimilarItem(self, itemId, catalogItemId):"""delete similar items.Parameters:- itemId, catalogItemIds"""try:return delete_similar_item_catalog_id(itemId, catalogItemId)finally:close_session()def addVendorItemMapping(self, key, vendorItemMapping):"""Adds VendorItemMapping. Updates VendorItemMapping if exists corresponding to the item key.Parameters:- key- vendorItemMapping"""log_entry(self, "addVendorItemMapping called")try:return add_vendor_item_mapping(key, vendorItemMapping)finally:close_session()def getVendorItemMappings(self, itemId):"""Returns the list of vendor item mapping corresponding to itemId passed as parameter.Raises an exception if item not found corresponding to itemIdParameters:- itemId"""try:item_mappings = get_item_mappings(itemId)return [to_t_vendor_item_mapping(vim) for vim in item_mappings]finally:close_session()def checkSimilarItem(self, brand, modelNumber, modelName, color):"""Checks if similar item exists (with same Brand, ModelNumber, ModelName, Color)If yes, returns the itemId else returns 0Parameters:- brand- modelNumber- modelName- color"""try:return check_similar_item(brand, modelNumber, modelName, color)finally:close_session()def changeItemRiskyFlag(self, itemId, risky):"""Marks/Unmarks an item as risky. This flag is used for automatic marking of an item as INACTIVE in case of zero inventory.Parameters:- itemId- risky"""try:change_risky_flag(itemId, risky)finally:close_session()def getItemsForMasterSheet(self, category, brand):"""Returns list of items with any status except PHASED_OUT and filtered by category, brand.Parameters:- category- vendor- brand"""try:return [to_t_item(item) for item in get_items_for_mastersheet(category, brand)]finally:close_session()def getItemsByRiskyFlag(self, ):"""Returns list of items marked as risky."""try:return [to_t_item(item) for item in get_risky_items()]finally:close_session()def getSimilarItemsCatalogIds(self, beginIndex, totalItems, itemId):"""Returns list of catalog ids of items with same similarity index as of the given itemIdParameters:- beginIndex- totalItems- itemId"""try:return get_similar_items_catalog_ids(beginIndex, beginIndex+totalItems, itemId)finally:close_session()def addProductNotification(self, itemId, email):"""Add user requests for out of stock items. Once user will ask for notify me an entry willParameters:- itemId"""try:return add_product_notification(itemId, email)finally:close_session()def sendProductNotifications(self, ):"""Send the product notifications to the users for items which has stock."""try:return send_product_notifications()finally:close_session()def getAllSources(self, ):"""Return list of all sources"""try:return get_all_sources()finally:close_session()def getItemPricingBySource(self, itemId, sourceId):"""Returns the pricing information of an item. If no information is found, exception will be thrown.Parameters:- itemId- sourceId"""try:return to_t_source_item_pricing(get_item_pricing_by_source(itemId, sourceId))finally:close_session()def addSourceItemPricing(self, sourceItemPricing):"""Adds prices to be displayed corresponding to the item if user comes from a source.Parameters:- sourceItemPricing"""try:add_source_item_pricing(sourceItemPricing)finally:close_session()def getAllSourcePricing(self, itemId):"""Returns the list of source pricing information of an item.Raises an exception if item not found corresponding to itemIdParameters:- itemId"""try:return [to_t_source_item_pricing(source_item_pricing) for source_item_pricing in get_all_source_pricing(itemId)]# return [to_t_item(item) for item in get_risky_items()]finally:close_session()def getItemForSource(self, item_id, sourceId):"""Parameters:- item_id- sourceId"""try:return to_t_item(get_item_for_source(item_id, sourceId))finally:close_session()def searchItemsInRange(self, searchTerms, offset, limit):"""Searches items matching the the given terms in the catalogParameters:- searchTerms"""try:return [to_t_item(item) for item in search_items(searchTerms, offset, limit)]finally:close_session()def getSearchResultCount(self, searchTerms):"""Gets the count of search results for the given search terms so that the user can go through all the pages.Parameters:- searchTerms"""try:return get_search_result_count(searchTerms)finally:close_session()def getPendingOrdersInventory(self, vendorId):"""Returns a list of inventory stock for items for which there are pending orders for the given vendor."""try:pending_items_inventory = get_pending_orders_inventory(vendorId)return [AvailableAndReservedStock(itemId = i[0], available=i[1], reserved=i[2], minimumStock=0) for i in pending_items_inventory]finally:close_session()def getProductNotifications(self, startDateTime):'''Returns a list of Product Notification objects each representing user requests for notification'''try:return [to_t_product_notification_request(notification) for notification in get_product_notifications(to_py_date(startDateTime))]finally:close_session()def getProductNotificationRequestCount(self, startDateTime):'''Returns list of items and the counts of product notification requests'''try:notification_request_counts = [(notification.item, count) for notification, count in get_product_notification_request_count(to_py_date(startDateTime))]return [to_t_product_notification_request_count(count) for count in notification_request_counts]finally:close_session()def isAlive(self, ):"""For checking weather service is active alive or not. It also checks connectivity with database"""try:return is_alive()finally:close_session()def closeSession(self, ):"""For closing the open session in sqlalchemy"""close_session()def addVendor(self, vendor):"""add a new vendor"""try:return add_vendor(vendor)finally:close_session()def addAuthorizationLog(self, itemId, username, reason):"""add a log to authorize table.Parameters:- itemId, username, reason"""try:return add_authorization_log_for_item(itemId, username, reason)finally:close_session()def getWarehouses(self, warehouseType, inventoryType, vendorId, billingWarehouseId, shippingWarehouseId):"""This method returns all warehouses for a given warehosueType, inventoryType, vendor, billingWarehouse and shippingWarehouse.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 3, 7, 7) would return ours warehouse with GOOD type inventory for vendor 1 for billing warehouse 7 and shipping warehouse 7getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 3, 7, 7) would return ours warehouse with GOOD type inventory for vendor 3 for billing warehouse 7 and shipping warehouse 7getWarehouses(null, null, 3, 7, 7) would return all type warehouses with all type inventory for vendor 3 for billing warehouse 7 and shipping warehouse 7getWarehouses(null, null, 0, 0, 7) would return all type warehouses with all type inventory for all vendors for all billing warehouses at shipping warehouse 7Parameters:- warehouseType- inventoryType- vendorId- billingWarehouseId- shippingWarehouseId"""try:query = Warehouse.queryif warehouseType is not None:query = query.filter_by(warehouseType = WarehouseType._VALUES_TO_NAMES[warehouseType])if inventoryType is not None:query = query.filter_by(inventoryType = InventoryType._VALUES_TO_NAMES[inventoryType])if vendorId:query = query.filter_by(vendor_id = vendorId)if billingWarehouseId:query = query.filter_by(billingWarehouseId = billingWarehouseId)if shippingWarehouseId:query = query.filter_by(shippingWarehouseId = shippingWarehouseId)return [to_t_warehouse(w) for w in query.all()]finally:close_session()def getItemKeysToBeProcessed(self, warehouseId):"""Returns the list of item keys which need to be processed for a given warehouse.This is currently used by Support application to send item keys whose inventory needsto be updated from PLBParameters:- warehouseId"""try:return get_item_keys_to_be_processed(warehouseId)finally:close_session()def markMissedInventoryUpdatesAsProcessed(self, itemKey, warehouseId):"""Marks/Deletes missed inventory updates for a given key and warehouse.This generally happens when updates from PLB are applied on the currentinventorysnapshot for an itemParameters:- itemKey- warehouseId"""try:mark_missed_inventory_updates_as_processed(itemKey, warehouseId)finally:close_session()def resetAvailability(self, itemKey, vendorId, quantity, warehouseId):"""Resets availability of an item to the quantity mentioned in a warehouse.Parameters:- itemKey- vendorId- quantity- warehouseId"""try:reset_availability(itemKey, vendorId, quantity, warehouseId)finally:close_session()def getIgnoredItemKeys(self, ):"""Returns all the item key mappings that have been ignored until date. Value of map has the warehouse idand the timestamp from where alert was raised."""try:itemKeysMap = {}for key in MissedInventoryUpdate.query.filter_by(isIgnored = 1).all():itemKeysMap[key.itemKey] = { key.warehouseId : to_java_date(key.timestamp) }return itemKeysMapfinally:close_session()def addBadInventory(self, itemId, warehouseId, quantity):"""Add the BAD type inventory to existing stock.Parameters:- itemId- warehouseId- quantity"""try:add_bad_inventory(itemId, warehouseId, quantity)finally:close_session()def getShippingLocations(self, ):"""Returns all shipping locations"""try:return [to_t_warehouse(w) for w in get_shipping_locations()]finally:close_session()def getAllVendorItemMappings(self, ):"""Fetches all the vendor item mappings present."""try:return [to_t_vendor_item_mapping(m) for m in VendorItemMapping.query.all()]finally:close_session()def getInventorySnapshot(self, warehouseId):"""Gets items' inventory for a warehouseIf warehouse is passed as zero, items' inventory across all warehouses is sentParameters:- warehouseId"""try:resultMap = {}itemInventoryMap = get_inventory_snapshot(warehouseId)for key, value in itemInventoryMap.items():resultMap[key] = to_t_item_inventory(value, key)return resultMapfinally:close_session()def clearItemAvailabilityCache(self, ):"""Clear item availability cache."""try:clear_item_availability_cache()finally:close_session()def is_valid(item):if item.status in [status.ACTIVE, status.PAUSED, status.PAUSED_BY_RISK]:if item.startDate:return not(datetime.datetime.now() < item.startDate or item.sellingPrice == 0)else:return True