The inventory service is the lowest-level component of the MRP stock layer. All other services—requirement, dispatch, and receipt—delegate stock mutations to these functions. Each inventory record is scoped to aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ElthonJohan/Sistema-MRP/llms.txt
Use this file to discover all available pages before exploring further.
(warehouse, material, budget) triple, so materials purchased under different projects appear as distinct cards. The reserve_stock function is intentionally non-committing: the caller accumulates all reservations for a requirement and issues a single db.commit() at the end.
add_stock
(warehouse_id, material_id, budget_id), creating the record if it does not yet exist. Writes a Movement(type="IN", reference_type="manual"), commits, then calls reprocess_requirements to satisfy any pending demand automatically.
SQLAlchemy session. The caller opens and owns the session; this function commits internally.
ID of the principal warehouse receiving the stock.
ID of the material being added.
Units to add. Must be a positive integer.
ID of the user performing the operation, recorded in the movement log.
Project ID. When provided, the stock is recorded under a project-scoped inventory card. When
None, stock goes to the project-free card.Display name for the project. Used only when a new inventory record is created. Ignored if the record already exists.
List of
Requirement ORM objects whose items all transitioned from pending to reserved as a result of the new stock. Empty when no requirements were newly satisfiable.remove_stock
(warehouse, material) pair using FIFO order (lowest id first). Returns False without modifying anything when total on-hand stock is less than qty. Writes a Movement(type="OUT", reference_type="manual") on success.
Active SQLAlchemy session.
Warehouse to remove stock from.
Material to reduce.
Units to remove.
Recorded in the movement log.
True when the removal succeeded; False when there is insufficient total stock.reserve_stock
Inventory.reserved across all active records for the material using FIFO order. Only succeeds when sum(stock - reserved) >= qty across all records.
Active SQLAlchemy session. Must be committed by the caller.
Principal warehouse to reserve from.
Material to reserve.
Units to reserve.
True when the reservation was applied in-memory; False when available stock is insufficient.release_reservation
Inventory.reserved across active records in FIFO order and commits. Called by cancel_requirement when a requirement is cancelled to return the reserved stock to available.
Active SQLAlchemy session. This function commits internally.
Warehouse holding the reservation.
Material whose reservation is being released.
Units to release.
get_or_create_inventory
(warehouse_id, material_id, budget_id), or creates a new one with stock=0, reserved=0 when none exists. When budget_id is None, queries for a record where budget_id IS NULL.
Active SQLAlchemy session.
Target warehouse.
Target material.
Project scope. Pass
None for project-free records.Used only when a new record is inserted. Has no effect when the record already exists.
The ORM
Inventory instance, either fetched or freshly created and committed.delete_inventory_record
DeletedInventory snapshot capturing the record’s last known values (stock, total_value, unit_price, warehouse/material names). The snapshot has status="pending" so it can be reviewed or resolved later. Returns False when the record does not exist.
Active SQLAlchemy session. Commits internally.
ID of the inventory record to delete.
Client user ID stored in the
DeletedInventory snapshot for filtering. Pass None when not applicable.True when the record was found and deleted; False otherwise.redirect_frozen_inventory
is_active=True. Used after a project is deleted to move leftover stock to a replacement project. Returns False when the inventory record does not exist, is already active, or new_budget_id does not match any budget.
Active SQLAlchemy session. Commits internally.
ID of the frozen inventory record.
ID of the destination project.
True on success; False when the record or budget is not found.unfreeze_inventory
budget_id=None, budget_name=None). Returns False when the record does not exist or is already active.
Active SQLAlchemy session. Commits internally.
ID of the frozen inventory record to reactivate.
True when the record was unfrozen; False otherwise.