Subversion Repositories SmartDukaan

Rev

Rev 22719 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

namespace java in.shop2020.model.v1.inventory
namespace py shop2020.thriftpy.model.v1.inventory

include "GenericService.thrift"

enum AmazonFCWarehouseLocation {
        Mumbai = 0,
        Bangalore = 1,
        Gurgaon = 2,
        Delhi = 3
}

enum WarehouseLocation {
        Delhi = 0,
        Mumbai = 1,
        Karnataka = 2,
        Haryana = 3,
        Rajasthan = 4,
        Telangana = 5,
        Gujrat = 6
}

struct Vendor {
        1:i64 id,
        2:string name
}

enum VatType {
        SP = 0,
        MRP = 1
}

enum BillingType {
        OURS = 0,
        EXTERNAL = 1,
        OURS_EXTERNAL = 2
}

enum WarehouseType {
    OURS = 0,
    THIRD_PARTY = 1,
    OURS_THIRDPARTY = 2
}

enum InventoryType {
    GOOD = 0,
    BAD = 1,
    VIRTUAL = 2
}

enum HolidayType {
        WEEKLY = 0,
        MONTHLY = 1,
        SPECIFIC = 2
}

/* 
Warehouse fields details
location: it is full address
vendorString: some key for the warehouse
*/
struct Warehouse {
        1:i64 id,
        2:string displayName,
        3:string location,
        5:i64 addedOn,
        6:i64 lastCheckedOn,
        7:string tinNumber,
        8:string pincode,
        9:string vendorString,
        10:WarehouseLocation logisticsLocation,
        12:BillingType billingType,
        13:WarehouseType warehouseType,
        14:InventoryType inventoryType,
        15:Vendor vendor,
        16:i64 shippingWarehouseId,
        17:i64 billingWarehouseId,
        18:bool isAvailabilityMonitored,
        19:i64 transferDelayInHours,
        20:i64 stateId,
        21:i64 source,
        22:string gstin
}

struct StateInfo{
        1:i64 id,
        2:string stateName,
        3:VatType vatType,
        4:string stateCode,
        5:string shortName
}


/* */
struct ItemInventory{
        1:i64 id,
        2:map<i64,i64> availability,
        3:map<i64,i64> reserved,
        4:map<i64,i64> held
}

struct ItemInventoryHistory{
        1:i64 item_id,
        2:i64 warehouse_id,
        3:i64 timestamp,
        4:i64 availability
}

struct VendorItemPricing{
        1:i64 vendorId,
        2:i64 itemId,
        3:double transferPrice,
        4:double mop,
        5:double dealerPrice,
        6:double nlc
}

struct VendorItemMapping{
        1:i64 vendorId,
        2:string itemKey,
        3:i64 itemId
}

struct AvailableAndReservedStock {
        1:i64 itemId,
        2:i64 available,
        3:i64 reserved,
        4:i64 minimumStock
}

struct IgnoredInventoryUpdateItems {
        1:i64 itemId,
        2:i64 warehouseId
}

struct ItemStockPurchaseParams{
        1:i64 item_id,
        2:i32 numOfDaysStock,
        3:i64 minStockLevel
}
 
exception InventoryServiceException{
        1:i64 id,
        2:string message
}

struct OOSStatus {
        1:i64 item_id
        2:i64 date
        3:bool is_oos
        4:i64 num_orders
        5:i64 rto_orders
        6:i32 sourceId
}

struct AmazonInventorySnapshot {
    1:i64 item_id
    2:i64 availability
    3:i64 reserved
    4:bool is_oos
} 

struct AmazonFbaInventorySnapshot {
    1:i64 item_id
    2:i64 availability
    3:AmazonFCWarehouseLocation location
    4:i64 unfulfillable
    5:i64 reserved
    6:i64 inbound
}

struct HoldInventoryDetail {
        1:i64 item_id
        2:i64 warehouse_id
        3:i64 held
        4:i64 source
}

struct SnapdealInventoryItem{
        1:i64 item_id
        2:i64 availability
        3:i64 lastUpdatedOnSnapdeal
        4:i64 pendingOrders
        5:bool is_oos
}

struct FlipkartInventorySnapshot{
        1:i64 item_id
        2:i64 availability
        3:i64 createdOrders
        4:i64 heldOrders
        5:bool is_oos
}

struct SnapdealStockAtEOD{
        1:i64 item_id
        2:i64 availability
        3:i64 date
}

struct FlipkartStockAtEOD{
        1:i64 item_id
        2:i64 availability
        3:i64 date
}

struct StockWeightedNlcInfo{
        1:i64 itemId,
        2:i64 source,
        3:i64 updatedTimestamp,
        4:i64 stockQuantity,
        5:string grnDetail,
        6:double avgWeightedNlc
}

struct BulkAddInventory{
        1:i64 item_id,
        2:i64 warehouse_id,
        3:i64 inventory
}
struct ItemLocationAvailability{
        1:i64 itemId,
        2:i64 locationId,
        3:i64 physicalQty,
        4:i64 virtualQty,
        5:i64 minTransferDelay,
        6:i64 maxTransferDelay
}

struct ItemPincodeAvailability{
        1:i64 itemId,
        2:string pinCode,
        3:i64 vatQty,
        4:i64 totalQty,
        5:i64 minDeliveryDate,
        6:i64 maxDeliveryDate
}

service InventoryService extends GenericService.GenericService{

        i64 addWarehouse(1:Warehouse warehouse) throws (1:InventoryServiceException cex),
        
        /**
        add a new vendor
        */
        i64 addVendor(1:Vendor vendor) throws (1:InventoryServiceException cex),
                
        /**
        Stores the incremental warehouse updates of items.
        */
        void updateInventoryHistory(1:i64 warehouse_id, 2:string timestamp, 3:map<string, i64> availability) throws (1:InventoryServiceException cex),
        
        /**
        Stores the final inventory stocks of items.
        */
        void updateInventory(1:i64 warehouse_id, 2:string timestamp, 3:map<string, i64> availability) throws (1:InventoryServiceException cex),

        /**
        Add the inventory to existing stock.
        */
        void addInventory(1:i64 itemId, 2:i64 warehouseId, 3:i64 quantity) throws (1:InventoryServiceException cex),

        //all delete methods
        void retireWarehouse(1:i64 warehouse_id) throws (1:InventoryServiceException cex),
        
        ItemInventory getItemInventoryByItemId(1:i64 item_id) throws (1:InventoryServiceException cex),
        i64 getItemAvailibilityAtWarehouse(1:i64 warehouse_id, 2:i64 item_id) throws (1:InventoryServiceException cex),
        
        /**
        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 the
        warehouse_loc parameter. If none of the warehouses there have any inventory, then the
        preferred warehouse for the item is used. 
        
        Returns an ordered list of size 4 with following elements in the given order:
        1. Id of the fulfillment warehouse which was finally picked up.
        2. Expected delay added by the category manager.
        3. Id of the billing warehouse which was finally picked up.
         */
        list<i64> getItemAvailabilityAtLocation(1:i64 itemId, 2:i64 sourceId) throws (1:InventoryServiceException isex),
        
        list<Warehouse> getAllWarehouses(1:bool isActive) throws (1:InventoryServiceException cex),
        
        /**
         Returns the warehouse with the given id.
        */
        Warehouse getWarehouse(1:i64 warehouse_id) throws (1:InventoryServiceException cex),
        list<i64> getAllItemsForWarehouse(1:i64 warehouse_id) throws (1:InventoryServiceException cex),
        
        /**
        Depending on reservation in the table, verify if we can bill this order or not.
        */
        bool isOrderBillable(1:i64 itemId, 2:i64 warehouseId, 3:i64 sourceId, 4:i64 orderId),
        
        /**
         Increases the reservation count for an item in a warehouse. Should always succeed normally.
        */
        bool reserveItemInWarehouse(1:i64 itemId, 2:i64 warehouseId, 3:i64 sourceId, 4:i64 orderId, 5:i64 createdTimestamp, 6:i64 promisedShippingTimestamp, 7:double quantity) throws (1:InventoryServiceException cex),
        
        /**
         Updates the reservation for Order
        */
        bool updateReservationForOrder(1:i64 itemId, 2:i64 warehouseId, 3:i64 sourceId, 4:i64 orderId, 5:i64 createdTimestamp, 6:i64 promisedShippingTimestamp, 7:double quantity) throws (1:InventoryServiceException cex),
        
        /**
         Decreases the reservation count for an item in a warehouse. Should always succeed normally.
        */
        bool reduceReservationCount(1:i64 itemId, 2:i64 warehouseId, 3:i64 sourceId, 4:i64 orderId, 5:double quantity) throws (1:InventoryServiceException cex),

        /**
        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.
        */
        VendorItemPricing getItemPricing(1:i64 itemId, 2:i64 vendorId) throws (1:InventoryServiceException cex),
        
        /**
        Returns the list of vendor pricing information of an item.
        Raises an exception if item not found corresponding to itemId
        */
        list<VendorItemPricing> getAllItemPricing(1:i64 itemId) throws (1:InventoryServiceException cex),
        
        
        /**
        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.
        */
        void addVendorItemPricing(1:VendorItemPricing vendorItemPricing) throws (1:InventoryServiceException cex),
        
        /**
        Returns a vendor given its id
        */
        Vendor getVendor(1:i64 vendorId), 
        
    /**
    Return list of all vendors
    */
    list<Vendor> getAllVendors(), 

        /**
        Adds VendorItemMapping. Updates VendorItemMapping if exists corresponding to the item key.  
        */
        void addVendorItemMapping(1:string key, 2:VendorItemMapping vendorItemMapping) throws (1:InventoryServiceException cex),
        
        /**
        Returns the list of vendor item mapping corresponding to itemId passed as parameter.
        Raises an exception if item not found corresponding to itemId
        */
        list<VendorItemMapping> getVendorItemMappings(1:i64 itemId) throws (1:InventoryServiceException cex),
        
        /**
        Returns a list of inventory stock for items for which there are pending orders for the given vendor.
        */
        list<AvailableAndReservedStock> getPendingOrdersInventory(1:i64 vendorid),
        
        /**
         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 7
         getWarehouses(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 7
     getWarehouses(null, null, 3, 7, 7) would return all type warehouses with all type inventory for vendor 3 for billing warehouse 7 and shipping warehouse 7
     getWarehouses(null, null, 0, 0, 7) would return all type warehouses with all type inventory for all vendors for all billing warehouses at shipping warehouse 7
         */
        list<Warehouse> getWarehouses(1:WarehouseType warehouseType, 2:InventoryType inventoryType, 3:i64 vendorId, 4:i64 billingWarehouseId, 5:i64 shippingWarehouseId);

    /**
     * Resets availability of an item to the quantity mentioned in a warehouse.
     */
    void resetAvailability(1:string itemKey, 2:i64 vendorId, 3:i64 quantity, 4:i64 warehouseId) throws (1:InventoryServiceException cex);

    /**
     * Resets availability of a warehouse to zero.
     */
    void resetAvailabilityForWarehouse(1:i64 warehouseId) throws (1:InventoryServiceException cex);

    /**
     * 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 needs 
     * to be updated from PLB
     */
    list<string> getItemKeysToBeProcessed(1:i64 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 item
     */
    void markMissedInventoryUpdatesAsProcessed(1:string itemKey, 2:i64 warehouseId);

    /**
     * Returns all the item key mappings that have been ignored until date. Value of map has the warehouse id
     * and the timestamp from where alert was raised.
     */
    map<string, map<i64, i64>> getIgnoredItemKeys();

    /**
    Add the BAD type inventory to existing stock.
    */
    void addBadInventory(1:i64 itemId, 2:i64 warehouseId, 3:i64 quantity) throws (1:InventoryServiceException cex);

    /**
    Returns all shipping locations
    */    
    list<Warehouse> getShippingLocations();

    /**
     * Fetches all the vendor item mappings present.
     */    
    list<VendorItemMapping> getAllVendorItemMappings();

    /**
     * Gets items' inventory for a warehouse
     * If warehouse is passed as zero, items' inventory across all warehouses is sent
     */
    map<i64, ItemInventory> getInventorySnapshot(1:i64 warehouseId);
    
    /**
    * Clear item availability cache.
    */
    void clearItemAvailabilityCache();
    
    void updateVendorString(1:i64 warehouseId, 2:string vendorString);
    
    void clearItemAvailabilityCacheForItem(1:i64 item_id);
    
    i64 getOurWarehouseIdForVendor(1:i64 vendorId, 2:i64 billingWarehouseId);
    
    map<i64, i64> getItemAvailabilitiesAtOurWarehouses(1:list<i64> item_ids);
    
    list<i64> getMonitoredWarehouseForVendors(1:list<i64> vendorIds);
    
    list<IgnoredInventoryUpdateItems> getIgnoredWarehouseidsAndItemids();
            
    bool insertItemtoIgnoreInventoryUpdatelist(1:i64 item_id,2:i64 warehouse_id);
             
    bool deleteItemFromIgnoredInventoryUpdateList(1:i64 item_id,2:i64 warehouse_id);
    
    i32 getAllIgnoredInventoryupdateItemsCount();
    
    list<i64> getIgnoredInventoryUpdateItemids(1:i32 offset,2:i32 limit);
    
    void updateItemStockPurchaseParams(1:i64 item_id, 2:i32 numOfDaysStock, 3:i64 minStockLevel);
    
    ItemStockPurchaseParams getItemStockPurchaseParams(1:i64 itemId);
    
    void addOosStatusForItem(1:map<i64, bool> oosStatusMap, 2: i64 date);
    
    list<OOSStatus> getOosStatusesForXDaysForItem(1:i64 itemId, 2:i32 sourceId, 3:i32 days);
    
    list<OOSStatus> getOosStatusesForXDays(1:i32 sourceId, 2:i32 days);
    
    list<VendorItemPricing> getAllVendorItemPricing(1:i64 itemId, 2:i64 vendorId);
    
    list<ItemStockPurchaseParams> getNonZeroItemStockPurchaseParams();
    
    /**
        Returns a list of inventory stock for items for which there are pending orders or have billable inventory.
        */
        list<AvailableAndReservedStock> getBillableInventoryAndPendingOrders();
        
        string getWarehouseName(1:i64 warehouse_id);
        
        AmazonInventorySnapshot getAmazonInventoryForItem(1:i64 item_id);
        
        list<AmazonInventorySnapshot> getAllAmazonInventory();
        
        void addOrUpdateAmazonInventoryForItem(1:AmazonInventorySnapshot amazonInventorySnapshot,2:i64 time);
        
        string getLastNdaySaleForItem(1:i64 itemId, 2:i64 numberOfDays);
        
        void addOrUpdateAmazonFbaInventory(1:AmazonFbaInventorySnapshot amazonfbainventorysnapshot);
        
        void addUpdateHoldInventory(1:i64 itemId, 2:i64 warehouseId, 3:i64 holdQuantity, 4:i64 source)  throws (1:InventoryServiceException cex);
        
        list<AmazonFbaInventorySnapshot> getAmazonFbaItemInventory(1:i64 itemId);
        
        list<AmazonFbaInventorySnapshot> getAllAmazonFbaItemInventory();
        
        list<i64> getOursGoodWarehouseIdsForLocation(1:i64 state_id);
        
        i64 getHoldInventoryDetailForItemForWarehouseIdExceptSource(1:i64 id,2:i64 warehouse_id,3:i64 source);
        
        SnapdealInventoryItem getSnapdealInventoryForItem(1:i64 item_id);
        
        void addOrUpdateSnapdealInventoryForItem(1:SnapdealInventoryItem snapdealinventoryitem)
        
        double getNlcForWarehouse(1:i64 warehouse_id,2:i64 item_id)
        
        map<i32, i64> getHeldInventoryMapForItem(1:i64 item_id, 2:i64 warehouse_id)
        
        void addOrUpdateAllAmazonFbaInventory(list<AmazonFbaInventorySnapshot> allamazonfbainventorysnapshot)
        
        void addOrUpdateAllSnapdealInventory(list<SnapdealInventoryItem> allsnapdealinventorysnapshot)
        
        list<SnapdealInventoryItem> getSnapdealInventorySnapshot()
        
        list<HoldInventoryDetail> getHoldInventoryDetails(1:i64 itemId, 2:i64 warehouseId, 3:i64 source)
        
        void addOrUpdateFlipkartInventorySnapshot(1:list<FlipkartInventorySnapshot> flipkartInventorySnapshot,2:i64 time)
        
        list<FlipkartInventorySnapshot> getFlipkartInventorySnapshot()
        
        FlipkartInventorySnapshot getFlipkartlInventoryForItem(1:i64 item_id)
        
        map<i64,StateInfo> getStateMaster()
        
        void updateSnapdealStockAtEOD(list<SnapdealStockAtEOD> allsnapdealstock)
        
        void updateFlipkartStockAtEOD(list<FlipkartStockAtEOD> allflipkartstock)
        
        double getWanNlcForSource(1:i64 item_id,2:i64 source)
        
        list<AmazonFbaInventorySnapshot> getAllAvailableAmazonFbaItemInventory();
        
        bool updateItemAvailabilityForItemIds(1:list<i64> itemIds)
        
        list<i64> addVendorItemPricingInBulk(1:list<VendorItemPricing> vendorItemPricingList)
        
        void addInventoryInBulk (1:list<BulkAddInventory> bulkInventoryList) throws (1:InventoryServiceException cex);
        
        map<i64, i64> getFofoAvailability(1:list<i64> itemIds)
        
        map<i64, Warehouse> getFofoFulFillmentWarehouseMap(1:list<i64> itemIds)
        
        list<ItemLocationAvailability> getItemLocationAvailabilityCache(1:list<ItemLocationAvailability> itemLocations)
        list<ItemLocationAvailability> getItemLocationAvailabilityCacheByItemId(1:list<i64> itemIds)
        string getItemPincodeAvailability(1:map<i64, i64> itempricing, 2:string pincode)
        
}