Skip to main content

Work Order Line Items Reference

Work Order Line Items specify each unit of work that the work order targets. Line items must reference a Service Task, and support fields such as description, labor_cost, parts_cost, and subtotal. For more information about Work Orders and line items in general, please reference our help center docs.

Type

You must set the line item type to WorkOrderServiceTaskLineItem

Item

As mentioned above, each line item must reference a Service Task. This association is called item in Fleetio and it is polymorphic. In a standard belongs-to association, a child belongs-to a parent and that parent is always the same class. Such as a Fuel Entry always belonging to a vehicle. A polymorphic association is a belongs-to association where the parent object can be one of a number of classes, such as a Meter Entry belonging to either a Fuel Entry, Service Entry, Work Order, etc.

A polymorphic association is typically defined by two fields: the standard foreign key field and a type field which serves as the placeholder for the parent's class name. For work order line items (and several other resources in Fleetio), the foreign key is called item_id and the type field is called item_type. In order to create a line item that is associated with a Service Task with an id of 12345, you would set item_type to "ServiceTask" and item_id to 12345. Both fields are required.

Linking Issues

You can link Issues to a Work Order Line Item by passing an array of issue_ids to a line item.

Including Parts and Labor Costs

Line items allow for the specification of cost for both parts and labor. There are two ways to denote these costs for each line item, either by specifying the cost directly, or by adding parts and labor sub line items to the line item in question.

To add costs directly to a line item, pass a value to the parts_cost, labor_cost and/or subtotal fields. To set subtotal directly on a line item, you must not set parts_cost and labor_cost. If you do, subtotal will be calculated as parts + labor.

Adding a Line Item with Part and Labor Sub Line Items

Adding sub line items is a bit trickier, but not terribly complicated in the long run. Each line item can have many sub line items (or none at all), which specify any parts used or any labor performed. Sub line items support 3 properties: item, unit_cost, and quantity. unit_cost and quantity should be self explanatory. The total cost for the sub line item is simply calculated as unit_cost * quantity. The item property for sub line items works exactly the same way as it does for line items. There is an item_type field and an item_id field. Supported values for item_type are "Part" (denotes a part line item), and "Contact" (denotes a labor line item).

Below is an example of adding a line item with a part and a labor sub line item:

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",
"issue_ids[]": 1,
"issue_ids[]": 2,
"work_order_sub_line_items_attributes":[
{
"item_type": "Part",
"item_id": 101,
"unit_cost": 9.95,
"quantity": 2
},
{
"item_type": "Contact",
"item_id": 4455,
"unit_cost": 24,
"quantity": 0.5
}]
}'

The above example will create a line item for Work Order #123. The line item will be associated with the Service Task #12345 and will have 1 part line item and 1 labor line item. The part line item will be associated to Part #101 and have a total cost of $19.90, while the labor line item will reference contact #4455 and will have a total cost of $12.00. The line item will then be created with a part_cost of 19.90 and a labor_cost of 12.00, causing the work order's total_amount to be recalculated to a value of 31.90. The line item will also be linked to two issues - IDs of 1 and 2.

Work order line item fields

FieldTypeDescription
typestring (required, string)Used to denote what type of line item this is. Currently, the only valid value is WorkOrderServiceTaskLineItem.
item_typestring (required, editable)Used in conjunction with item_id denotes the class name for the item association. Valid values are "ServiceTask".
item_idinteger (required, editable)Used in conjunction with item_id, denotes the foreign key for the item association. This is typically the ServiceTask id.
descriptiontext (optional, editable)Free text field for item description.
issue_ids[]integer (optional, editable)An array of issue IDs that you want the line item to be linked to. This field can be passed several times to the server if you wish to link more than one issue (see cURL example) .
labor_costdouble (optional, editable)Total labor cost for this line item. If there are labor line items present, the labor cost will be calculated from the sum of their totals and this value will be overwritten.
parts_costdouble (optional, editable)Total parts cost for this line item. If there are part line items present, the labor cost will be calculated from the sum of their totals and this value will be overwritten.
subtotaldouble (optional, editable)Subtotal for this line item. If parts or labor are present and non zero, this value is ignored.

Work order sub line item fields

| Field Description | --- | --- | | item_type | string (required, editable) | Used in conjunction with item_id denotes the class name for the item association. Valid values are "Part" and "Contact" for part line items and labor line items respectively. | | item_id | integer (required, editable) | Used in conjunction with item_id, denotes the foreign key for the item association. | | unit_cost | double (optional, editable) | Cost per unit for part or labor. If labor, this represents the contact's hourly labor rate. | | quantity | double (optional, editable) | Number of units for this line item. If labor, this represents the number of hours the contact worked. |

📘 Advanced Inventory Valuation Method (LIFO/FIFO)

If your account has been setup to use LIFO/FIFO, in addition to the fields listed above you must also provide inventory_set_id and part_location_detail_id for any part line items. Additional information available here.