Lots and FIFO Valuation

Fenicia calculates your inventory's cost using cost layers (lots). Costing is FIFO (first in, first out) for every tenant: the NONE and AVERAGE methods no longer exist. A lot is born when merchandise is released to sellable stock: when a purchase order receipt is released (see Receipts and receiving tray) or when a transfer is received. When stock is consumed (for example, an order's sale), Fenicia depletes the oldest lots first. If the variant has inventoryTracking.trackExpiration, the sale uses FEFO (first expired, first out).

There is no public endpoint to create a lot

Lots are generated internally when merchandise is released from a receipt or when a transfer is received — not from this API. Queries require the inventory:read permission. The only write on this page is a lot's cost correction, which requires inventory:manage.

Before you start: pagination differs from the rest of /inventory/*

Pagination trap

Most /inventory/* listings (stock, transfers, adjustments, counts) paginate 1-indexed (page=1 by default). GET /inventory/lots is the exception within the inventory domain itself: it paginates 0-indexed (page=0 by default), just like /locations/*. Its response shape is also flat — { data, total, page, limit, totalPages, hasMore } — different from the { items, pagination: {...} } used by stock, transfers, adjustments, and counts. If you share a pagination helper across inventory resources, this silently breaks the page count.

List lots

Lists FIFO cost layers with filters. Requires inventory:read.

pagenumber

Page, 0-based. Default: 0.

limitnumber

Results per page. Default: 50.

skustring

Filter by exact SKU.

locationIdstring

Filter by location.

statusstring

active, depleted, expired, or cancelled.

sourceTypestring

purchase_order or transfer. The adjustment and initial values are historical: no new lots are created with that source.

batchNumberstring

Filter by manufacturer batch.

supplierIdstring

Filter by supplier.

startDatestring

ISO 8601 start date, filters by receivedAt.

endDatestring

ISO 8601 end date.

200
{
  "data": [
    {
      "id": "lot_01HZK...",
      "tenantId": "69db07c8bce4d49b18c42a49",
      "sku": "CAM-ROJO-M",
      "locationId": "loc_cedis_cdmx",
      "sourceType": "purchase_order",
      "sourceId": "po_4471",
      "supplierId": "sup_221",
      "purchaseOrderNumber": "PO-2026-0441",
      "receiptId": "rcp_01J9A",
      "unitCost": 210.50,
      "currency": "MXN",
      "initialQuantity": 200,
      "currentQuantity": 137,
      "receivedAt": "2026-06-02T09:00:00.000Z",
      "batchNumber": "L-2291",
      "expirationDate": "2027-03-31T00:00:00.000Z",
      "status": "active"
    }
  ],
  "total": 34,
  "page": 0,
  "limit": 50,
  "totalPages": 1,
  "hasMore": false
}

Aggregated valuation by location

Valuation of a location in three lines: lots at their cost, stock without a lot at unitCost (estimated), and in-process merchandise at its cost. Requires inventory:read.

locationIdstring

Restricts the aggregation to one location.

200
{
  "valuation": [
    {
      "locationId": "loc_cedis_cdmx",
      "lots": { "quantity": 4820, "value": 1014610.00, "lotCount": 63 },
      "withoutLot": { "quantity": 35, "value": 7350.00, "estimated": true, "costMissingSkus": 2 },
      "inProcess": { "quantity": 47, "value": 37600.00 },
      "totalValue": 1059560.00
    }
  ]
}

Tip

Lots are valued at their cost and only lots with status: 'active' count. Stock without a lot is valued at the product's unitCost and flagged estimated: true, because it has no real cost layer. costMissingSkus counts the SKUs with no lot and no unitCost: they are worth 0 and the valuation is partial. In-process merchandise (positions of a receiving flow) is valued at its position's cost.

Query a lot

Gets a lot by its ID. Requires inventory:read.

idstringrequired

Lot ID.

200
{
  "id": "lot_01HZK...",
  "sku": "CAM-ROJO-M",
  "locationId": "loc_cedis_cdmx",
  "unitCost": 210.50,
  "currentQuantity": 137,
  "status": "active",
  "receivedAt": "2026-06-02T09:00:00.000Z"
}
404
{ "code": "not-found", "message": "Lot not found" }

Lot movements

Lists the historical consumption/reversal movements of a lot. Requires inventory:read.

idstringrequired

Lot ID.

200
{
  "movements": [
    {
      "id": "mov_01HZ...",
      "lotId": "lot_01HZK...",
      "sku": "CAM-ROJO-M",
      "locationId": "loc_cedis_cdmx",
      "type": "sale",
      "quantity": 2,
      "unitCost": 210.50,
      "referenceType": "order",
      "referenceId": "ord_9931",
      "createdAt": "2026-07-10T18:22:00.000Z"
    }
  ]
}

Weighted average cost by SKU

Weighted average cost across a SKU's active lots. Requires inventory:read.

skustringrequired

SKU to query (path).

locationIdstring

Restricts the calculation to one location.

200
{ "averageCost": 208.14, "totalQuantity": 512, "totalValue": 106567.68, "currency": "MXN" }

Información

If the SKU has no active lots, the response is 200 with zeroed values, not a 404.

Detailed valuation by SKU and location

Lot-by-lot valuation breakdown for a SKU at a specific location. Requires inventory:read.

skustringrequired

SKU to query (path).

locationIdstringrequired

Location to query. Required — the request fails with 400 if omitted.

200
{
  "sku": "CAM-ROJO-M",
  "locationId": "loc_cedis_cdmx",
  "totalQuantity": 137,
  "totalValue": 28838.50,
  "weightedAverageCost": 210.50,
  "lots": [
    {
      "lotId": "lot_01HZK...",
      "unitCost": 210.50,
      "currentQuantity": 137,
      "value": 28838.50,
      "receivedAt": "2026-06-02T09:00:00.000Z",
      "sourceType": "purchase_order",
      "sourceId": "po_4471"
    }
  ]
}

Lots by source

Lists the lots generated by a specific source (a purchase order, an adjustment, etc.). Requires inventory:read.

typestringrequired

sourceType: purchase_order, transfer, adjustment, or initial (the last two are historical).

idstringrequired

Source ID (sourceId).

200
{ "lots": [ { "id": "lot_01HZK...", "sku": "CAM-ROJO-M", "sourceType": "purchase_order", "sourceId": "po_4471" } ] }

COGS of an order

Cost of goods sold (COGS) for an order, derived from sale-type lot movements. Requires inventory:read.

orderIdstringrequired

Order ID.

200
{
  "totalCOGS": 421.00,
  "items": [
    { "sku": "CAM-ROJO-M", "quantity": 2, "unitCost": 210.50, "totalCost": 421.00 }
  ]
}

Información

This COGS is calculated from the InventoryLotMovement records with referenceType: 'order' and type: 'sale' associated with the order — not from a separate summary table.

Correct a lot's cost

Corrects a lot's unit cost and recalculates the order lines that consumed it. Requires inventory:manage.

{ "unitCost": 215.00, "reason": "Factura del proveedor con flete incluido" }
200Cost corrected. Fenicia recalculates the affected order lines asynchronously.
{
  "id": "lot_01HZK...",
  "previousUnitCost": 210.50,
  "unitCost": 215.00,
  "currency": "MXN",
  "status": "active"
}
404No lot exists with that ID in your tenant.
{ "code": "not-found", "message": "Lot not found" }

Returns the lot with its previous and new cost. Inventory publishes the io.fenicia.inventory.lot-cost-corrected event and the orders service recalculates every line that consumed that lot, including its reversals. The line's original cogs is never touched: each correction is appended to cogsAdjustments[]. Replaying the same event does not duplicate corrections.

Required permission: inventory:manage

Parameters

idstringrequired

Lot ID.

unitCostnumberrequired

Correct unit cost, in the tenant's currency. Greater than or equal to 0.

reasonstringrequired

Reason for the correction. Free text; it is kept in the history.

Expiring and expired lots

Lists active lots whose expiration falls within the next days. Requires inventory:read.

200Lots that expire within the requested window.
{
  "data": [
    { "id": "lot_01HZK...", "sku": "CAM-ROJO-M", "locationId": "loc_cedis_cdmx", "currentQuantity": 137, "batchNumber": "L-2291", "expirationDate": "2026-11-15T00:00:00.000Z", "status": "active" }
  ]
}

Returns the expiring lots in data. It is an alert: it does not move inventory.

Required permission: inventory:read

Parameters

daysnumber

Window in days from today. Default: 30.

locationIdstring

Restricts the query to one location.

Lists expired lots that still have pieces. Requires inventory:read.

200Expired lots with stock.
{
  "data": [
    { "id": "lot_01HZ0...", "sku": "CAM-AZUL-M", "locationId": "loc_cedis_cdmx", "currentQuantity": 12, "expirationDate": "2026-09-30T00:00:00.000Z", "status": "expired" }
  ]
}

Returns the expired lots in data. An expired lot is not sold. To write it off, create an adjustment with the lot's lotId and the expired reason: it is recorded as scrap.

Required permission: inventory:read

Mismatch between lots and stock

Lists the SKUs and locations where the sum of lots is greater than stock. Requires inventory:read.

200Differences found.
{
  "data": [
    { "sku": "CAM-ROJO-M", "locationId": "loc_cedis_cdmx", "stock": 130, "lotQuantity": 137, "difference": 7, "marketplaceWarehouse": false }
  ]
}

Returns the differences in data. The rule is that the sum of the lots' currentQuantity never exceeds Inventory.stock. This query is read-only: it warns, it does not fix. In a marketplace warehouse the difference has a tolerance, because the marketplace writes its own stock there.

Required permission: inventory:read

Data model

InventoryLot

tenantId, sku, productSku?, locationId, sourceType (purchase_order|transfer|adjustment|initial),
sourceId, receiptId?, originLotId?, supplierId?, supplierName?, purchaseOrderNumber?,
unitCost (≥0, tenant currency), currency, initialQuantity (≥0), currentQuantity (≥0), receivedAt,
batchNumber?, expirationDate?, notes?, status (active|depleted|expired|cancelled, default active)

InventoryLotMovement

tenantId, lotId, sku, locationId,
type (sale|supply_consumption|transfer_out|transfer_in|adjustment|return|fulfillment_send|
       receipt|stage_move|release|scrap|supplier_return),
quantity (≥0), unitCost (≥0),
referenceType (order|transfer|adjustment|fulfillment|purchase_order), referenceId,
receiptId?, positionId?, fromStageId?, toStageId?, transitionLabel?, performedBy,
destinationType? (fba|mercado_full|warehouse|store|other), destinationId?, destinationName?, createdAt

FIFO and FEFO consumption rule

Lot consumption follows ascending receivedAt order (the oldest lot is depleted first) within {tenantId, sku, locationId}. If the variant requires expiration (inventoryTracking.trackExpiration), the order is ascending expirationDate and, on a tie, receivedAt. Only lots with status: 'active' count: an expired lot is not sold.

Consumption is partial: it spends what the lots hold and the rest of the sale comes out of stock without a lot, costed at the product's unitCost. If there is neither a lot nor a unitCost, the line is flagged costMissing: true and excluded from the order's total COGS until the cost is entered. Lots are spent once per line: retrying the same line of the same order does not spend twice.

A return does not create a lot: it puts the pieces back into the original lot, and a depleted lot that receives a return becomes active again. Stock reservation no longer lives on the lot: the reservedQuantity field was removed.

Not exposed as an endpoint

FIFO consumption is triggered internally (an order's sale, a transfer's receipt) — there is no public POST to invoke it directly. Do not document it as an operation you can execute yourself via the API.

Errors

CodeHTTPCause
not-found404No lot exists with that ID in your tenant. Also on PUT /inventory/lots/{id}/cost.
—400Missing locationId on GET /inventory/lots/sku/{sku}/valuation (required parameter).

See the Error Catalog for the errors common to the whole domain (authentication, permissions, missing tenant).

Examples

# Active lots for a SKU
curl -G https://api.fenicia.io/inventory/lots \
  -H "Authorization: Bearer fkapi_your_api_key" \
  --data-urlencode "sku=CAM-ROJO-M" \
  --data-urlencode "status=active"
 
# Detailed valuation by SKU + location
curl -G https://api.fenicia.io/inventory/lots/sku/CAM-ROJO-M/valuation \
  -H "Authorization: Bearer fkapi_your_api_key" \
  --data-urlencode "locationId=loc_cedis_cdmx"

Next steps