What are Batches?
Batches track individual stock purchases with their associated costs, quantities, and metadata. The system uses FIFO (First In, First Out) logic, prioritizing items closest to expiration when processing sales.Key Concepts
Batch Lifecycle
- Creation: A batch is created when receiving inventory via the
/receiveendpoint - Tracking: Each batch maintains its available quantity separate from initial quantity
- Depletion: When products are sold, quantities are deducted from the oldest batches first
- Expiration: Batches with expiration dates are prioritized for depletion
Batch Attributes
| Attribute | Type | Description |
|---|---|---|
id | string | Unique batch identifier (UUID) |
product_id | string | Reference to the product |
initial_quantity | integer | Quantity received in this batch |
available_quantity | integer | Remaining quantity available for sale |
unit_cost | float | Cost per unit paid to supplier |
purchase_date | datetime | When the batch was received |
expiration_date | datetime | Optional expiration date |
supplier_id | string | Optional supplier reference |
entry_transaction_ref | string | Reference to the entry movement |
Relationship to Products
Each batch belongs to exactly one product. A product can have multiple active batches simultaneously. When inventory is sold:- The system queries all active batches for the product
- Batches are sorted by expiration date (earliest first), then purchase date
- Quantities are deducted across batches until the order is fulfilled
Authentication & Authorization
All batch endpoints require authentication via Bearer token.Role Requirements
- Receive Inventory (
POST /receive):adminorgestor - List Batches (
GET /product/{product_id}):admin,gestor, orconsultor
The
consultor role can view batches but cannot create or modify them.Common Use Cases
Receiving Inventory
Viewing Product Batches
Retrieve all batches for a product to:- Audit inventory costs
- Monitor expiration dates
- Track supplier performance
- Calculate average cost basis
FIFO Exit Processing
Next Steps
Create Batch
Receive inventory and create a new batch
List Batches
View all batches for a product