CafeteriaPM tracks ingredient stock in real time. Each ingredient has a current stock level, a minimum threshold for low-stock alerts, and a unit cost. Products are linked to ingredients through recipe entries — when an order is markedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/123048152-JJDS/CafeteriaPM_S203/llms.txt
Use this file to discover all available pages before exploring further.
listo, the API automatically deducts the ingredient quantities defined in each product’s recipe from stock_actual. This keeps your inventory accurate without any manual intervention after order preparation.
Ingredients
Each ingredient in theingredientes table has the following fields:
| Field | Type | Description |
|---|---|---|
nombre | string | Ingredient name (e.g., "Café molido", "Leche entera") |
unidad | string | Unit of measurement (e.g., "gramos", "litros", "unidades") |
stock_actual | decimal | Current quantity on hand; enforced >= 0 at the database level |
stock_minimo | decimal | Threshold below which a low-stock alert is triggered |
costo_unitario | decimal | Unit cost used for product profitability margin calculations |
Ingredient Endpoints
List all ingredients —GET /productos/ingredientesReturns all ingredients ordered by ID ascending. Any authenticated user. Get a single ingredient —
GET /productos/ingredientes/{id}Returns one ingredient by ID. Any authenticated user. Low-stock alert list —
GET /productos/ingredientes/stock-bajoReturns every ingredient where
stock_actual <= stock_minimo. Use this endpoint to drive reorder notifications. Any authenticated user.
Create ingredient — POST /productos/ingredientes (admin, cocina)All fields are required. Example:
PATCH /productos/ingredientes/{id} (admin, cocina)Accepts any subset of the ingredient fields. Only supplied fields are updated (
exclude_none=True).
Manual stock adjustment — PATCH /productos/ingredientes/{id}/ajustar-stock?cantidad=<float> (admin, cocina)Adds
cantidad to the ingredient’s current stock. Pass a positive value to increase stock and a negative value to decrease it. Returns 400 Bad Request if the resulting stock would go below zero.
{"message": "Stock actualizado", "stock_actual": <new_value>}
Delete ingredient — DELETE /productos/ingredientes/{id} (admin only)Blocked with
400 if the ingredient is referenced by any product recipe (producto_ingrediente) or purchase record (compras_suministros). Remove those associations first before deleting.
Product Recipes
A product’s recipe defines how much of each ingredient is consumed when one unit of that product is prepared. Recipes are set when creating a product viaPOST /productos/ using the ingredientes array. Roles: admin, cocina.
id_ingrediente— the ingredient to consumecantidad— the amount of that ingredient consumed per single unit of the product
GET /productos/{id} — it returns the ProductDetailOut schema which includes the ingredientes array with each ingredient’s name, unit, and quantity.
Automatic Stock Deduction
When an order is transitioned to thelisto state via PATCH /pedidos/{id}/estado, the API automatically calls descontar_ingredientes() before committing the state change.
The service works as follows:
- Aggregates requirements — for each line item in the order, it multiplies
detalle.cantidad(units ordered) by each recipe ingredient’scantidad(amount per unit). If the same ingredient appears in multiple products, its totals are summed. - Validates stock — before touching any ingredient, it checks that every required ingredient has sufficient
stock_actual. If any ingredient falls short, the entire transition is rejected with400 Bad Requestlisting the ingredient name, available stock, and required amount. - Applies deductions atomically — only after all ingredients pass the stock check are the deductions written to the database via
db.flush(), ensuring no partial updates occur.
Registering Purchases
When you receive a supply delivery, record it withPOST /compras/. This simultaneously creates an audit record in compras_suministros and increments the ingredient’s stock_actual by the purchased quantity. Roles: admin, cocina.
| Field | Type | Description |
|---|---|---|
id_ingrediente | integer | The ingredient being restocked |
cantidad | decimal | Units received (must be > 0) |
costo_total | decimal | Total purchase cost for this delivery |
fecha | date | Date of the purchase (ISO 8601 date, not datetime) |
id_usuario.
To list all purchase history, call GET /compras/. Roles: admin, cocina.
Low-Stock Alerts
Two entry points surface low-stock information: Operational check:GET /productos/ingredientes/stock-bajo returns the full ingredient objects for all ingredients where stock_actual <= stock_minimo. Use this in dashboards or monitoring scripts.
Dashboard KPI: GET /stats/dashboard returns a stock_bajo count — the number of ingredients currently at or below their minimum threshold — alongside today’s sales and active orders.
Full inventory status: GET /stats/inventario-estado (admin, cocina) returns a comprehensive inventory snapshot including:
total_items— total number of ingredientscriticos— count of ingredients at or below minimumingredientes— array of all ingredients with anestadofield set to either"Crítico"or"Ok"movimientos— the 10 most recent purchase records with ingredient name, quantity, cost, and timestamp