Stock Transfer Part 1

12 December 2019 - 150 views
Developing inventory management tools requires a good understanding of SAP Business One API's. Many API's in the Service Layer documentation lack payload samples leaving developers to do their own research. This article aims to help developers understand the payload data that is required to create a stock transfer.

Warehouse To Warehouse


The simplest type of stock transfer is warehouse to warehouse that are not bin enabled as the payload data is easier to construct. The data must contain one or more stock transfer lines At the very minimum each line must contain an ItemCode, the Quantity to transfer and the WarehouseCode the item is being transferred to. Listing 1 below shows a sample JSON payload that also includes the FromWarehouse, which as you would expect defines the warehouse the stock is transferring from.

Listing 1

POST https://localhost:50000/b1s/v1/StockTransfers

{
    FromWarehouse: "From Warehouse code",
    StockTransferLines: [ 
        {
            ItemCode: "v100001",
            Quantity: 100,
            WarehouseCode : "Target Warehouse Code",
        }
    ]
}

Warehouse To Bin Enabled Warehouse


Stock can be transferred to a bin enabled warehouse by specifying the bin location using the StockTransferLinesBinAllocations property for each item. This property contains an array of one or more bins that the item should be transferred to. The bin object must contain the bin abs entry, the quantity to move and an enum action type. The action type indicates the to/from warehouse movement. The sample code below will help make this a little clearer.

Listing 2

{
    FromWarehouse: "From Warehouse code",
    StockTransferLines: [ 
        {
            ItemCode: "v100001",
            Quantity: 100,
            StockTransferLinesBinAllocations : [
                {
                    BinAbsEntry : 35369,
                    Quantity : 100,
                    BinActionType : 1
                }
            ]
        }
    ]
}

The sample payload data above specifies that 100 units of item v100000 should be transferred to bin location 35369 using action type 1, which means the item is moving to the target warehouse. In the previous code sample in listing 1, the target warehouse is explicitly set using the property WarehouseCode. In this example however the target warehouse is determined by the bin location abs entry.

Lets take a look at another example. The following payload data in listing 3 below shows how to transfer stock for one item to multiple bins. Notice that the total quantity 200 is split between the two bins. When specifying multiple bins, the total quantity for all bins must add up to the total quantity at the item level. Omitting the item level Quantity property will result in an error.

Listing 3

{
    FromWarehouse: "From Warehouse code",
    StockTransferLines: [ 
        {
            ItemCode: "v100001",
            Quantity: 200,
            StockTransferLinesBinAllocations : [
                {
                    BinAbsEntry : 35369,
                    Quantity : 100,
                    BinActionType : 1,
                },
                {
                    BinAbsEntry : 35370,
                    Quantity : 100,
                    BinActionType : 1,
                }
            ]
        }
    ]
}

The last example below shows a payload that contains multiple items with one ore more bins.

Listing 4

{
    FromWarehouse: "From Warehouse code",
    StockTransferLines: [ 
        {
            ItemCode: "v100001",
            Quantity: 200,
            StockTransferLinesBinAllocations : [
                {
                    BinAbsEntry : 35369,
                    Quantity : 100,
                    BinActionType : 1,
                },
                {
                    BinAbsEntry : 35370,
                    Quantity : 100,
                    BinActionType : 1,

                }
            ]
        },
        {
            ItemCode: "v100002",
            Quantity: 10,
            StockTransferLinesBinAllocations : [
                {
                    BinAbsEntry : 35369,
                    Quantity : 10,
                    BinActionType : 1,
                }
            ]
        }
    ]
}

Summary


In this article I explained how to do simple stock transfers from warehouse to warehouse and warehouse to bin enabled warehouses. In Part 2, I'll explain how to construct the payload data for batch managed items.