Overview
The Inventory API provides access to current stock levels across all products. Stock movements and the Kardex (stock movement ledger) are tracked automatically through theStockMovement model when products are sold, purchased, or adjusted.
Stock Movement Types
The system tracks stock changes through immutableStockMovement records:
- ENTRADA (Entry): Stock increases from purchases, returns, or adjustments
- SALIDA (Exit): Stock decreases from sales or adjustments
Movement Reasons
- VENTA: Sale transaction
- COMPRA: Purchase from supplier
- AJUSTE: Manual stock adjustment
- INICIAL: Initial stock load
- DEVOLUCION: Customer return
Get Inventory
Returns all active products with their current stock levels. This endpoint provides a snapshot of your complete inventory.Response
Returns an array of product objects with inventory information.Product identifier
Internal SKU code
Product name
Full product name (includes parent name for variants)
Net price
Whether inventory tracking is enabled for this product
Current available stock quantity
Minimum stock threshold for reorder alerts
Unit of measure (e.g., “unidad”, “kg”, “lt”)
Whether the product is active
Associated brand information
Example
Response Example
Stock Movement Model
While there’s no direct API endpoint for querying stock movements, theStockMovement model tracks all inventory changes:
StockMovement Attributes
| Field | Type | Description |
|---|---|---|
id | integer | Movement identifier |
product_id | integer | Product affected |
user_id | integer | User who generated the movement |
tipo | string | Movement type: ENTRADA or SALIDA |
motivo | string | Reason: VENTA, COMPRA, AJUSTE, INICIAL, DEVOLUCION |
cantidad | decimal | Absolute quantity moved |
fecha | datetime | Movement timestamp |
balance_after | decimal | Stock level after this movement (snapshot) |
description | string | Optional description |
sale_id | integer | Associated sale ID (if applicable) |
How Stock Movements Work
-
Automatic Creation: Stock movements are created automatically when:
- A sale is completed (creates
SALIDAwithmotivo=VENTA) - A purchase is received (creates
ENTRADAwithmotivo=COMPRA) - A return is processed (creates
ENTRADAwithmotivo=DEVOLUCION) - Manual adjustments are made (creates entry with
motivo=AJUSTE)
- A sale is completed (creates
- Immutable Records: Movements are never modified or deleted, providing complete audit trail
-
Balance Snapshot: Each movement records the resulting stock level in
balance_after - Kardex: The complete history of movements forms the Kardex, allowing reconstruction of stock history
Stock Control Behavior
Products with controla_stock = true
- Stock is validated before sales (prevents overselling)
- Stock is automatically decremented on sale
- Stock is automatically incremented on purchase or return
- Low stock alerts can be triggered when
stock_actual < stock_minimo
Products with controla_stock = false
- No stock validation occurs
- Useful for services, digital products, or items with unlimited availability
- Stock movements may still be recorded but not enforced
Use Cases
Check Stock Levels
Use the GET/inventory/ endpoint to:
- Display current inventory in admin dashboard
- Generate low stock alerts (where
stock_actual < stock_minimo) - Export inventory reports
- Monitor product availability
Stock Adjustments
To manually adjust stock:- Update the product’s
stock_actualvia PUT/products/{product_id} - The system should create a
StockMovementrecord withmotivo=AJUSTE
Audit Trail
TheStockMovement model provides:
- Complete history of all stock changes
- User accountability (who made each change)
- Point-in-time stock reconstruction via
balance_aftersnapshots - Reconciliation with sales and purchases
Integration with Other Endpoints
Inventory is automatically updated by:- Sales (
POST /sales/): Decrements stock when sale is completed - Purchases (
POST /purchases/): Increments stock when purchase is received - Returns (
POST /returns/): Increments stock when items are returned - Product Updates (
PUT /products/{id}): Manual stock adjustments