Skip to main content

Using Parts in Work Orders under LIFO/FIFO

In order to use parts in a Work Order, you must pass these two parameters in addition to those listed in the Work Order Line Item Reference:

  • part_location_detail_id
  • inventory_set_id
Example

Let's say you purchased 5 tires, with a unit cost of $100 each in February for the Boston location and added to it to Fleetio. Then you purchased addition 2 tires for $115 each in March for the Boston location and added it to Fleetio. You now have 2 Inventory Sets in Fleetio at Boston and a total quantity of 7

Step 1 • List Inventory Sets

Make a GET request to the /part_location_details/:id/inventory_sets endpoint.

Let's say you want to use 4 tires on a Work Order. The response will contain information about the next available Inventory Set based on LIFO/FIFO:

[
{
"id": 41,
"added_at": "2022-02-17T13:06:55.095-05:00",
"available_quantity": 4.0,
"part_location_detail_id": 18234358,
"leftover_quantity": 1.0,
"part_id": 1790561,
"unit_cost_cents": 10000.0
}
]

If we make a request for 7 instead, the returned response will have two elements since the first Inventory Set only has 5 quantity available. In order to fulfill the requested amount, second Inventory Set which was purchased at $115 will also be returned.

[
{
"id": 41,
"added_at": "2022-02-17T13:06:55.095-05:00",
"available_quantity": 5.0,
"part_location_detail_id": 18234358,
"leftover_quantity": -2.0,
"part_id": 1790561,
"unit_cost_cents": 10000.0
},
{
"id": 42,
"added_at": "2022-03-17T13:06:55.095-05:00",
"available_quantity": 2.0,
"part_location_detail_id": 18234358,
"leftover_quantity": 0.0,
"part_id": 1790561,
"unit_cost_cents": 11500.0
}
]

Step 2 • Create a Work Order Line Item

Make a request to create Work Order Line Item using the information provided above.

You can use the id provided in the above step as the inventory_set_id to the work_order_sub_line_item element in the payload. For example:

curl https://secure.fleetio.com/api/v2/work_orders/123/work_order_line_items \
-H 'Authorization: Token token="API_KEY"' \
-H "Account-Token: ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-X POST -d '{
"type": "WorkOrderServiceTaskLineItem",
"item_type": "ServiceTask",
"item_id": 12345,
"description": "Replacing brake pads",
"work_order_sub_line_items_attributes":[
{
"item_type": "Part",
"item_id": 101,
"unit_cost": 10000,
"inventory_set_id": 41,
"part_location_detail_id": 18234358,
"quantity": 5
},
{
"item_type": "Part",
"item_id": 101,
"unit_cost": 11500,
"inventory_set_id": 42,
"part_location_detail_id": 18234358,
"quantity": 2
}
]
}'