Skip to main content

Documentation 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.

A requirement is the starting point of every material movement in Sistema MRP. It captures which materials are needed at a specific obra warehouse, how many units are requested, and which project (budget) the consumption belongs to. As soon as a requirement is saved, the system attempts to reserve stock from the principal warehouse for each item.

Creating a requirement

Selecting a project is mandatory. create_requirement() returns (False, "Debes seleccionar un proyecto. El proyecto es obligatorio.") if budget_id is not provided. The project must also exist and be active.
1

Open the Requirements page

Navigate to Requerimientos in the sidebar. You need at least one obra warehouse, one principal warehouse, at least one material with stock in the principal warehouse, and one active project before the creation form is shown.
2

Select the obra warehouse

Choose the work-site warehouse that will receive the materials.
3

Select the project

Choose the active project (Proyecto *). This links the requirement to a budget for cost tracking.
4

Add items

Set Cantidad de materiales to the number of distinct materials needed. For each row, select a material and enter the required quantity. A real-time stock indicator shows availability in the selected project and in total.
5

Submit

Click Crear Requerimiento. The service call is:
create_requirement(db, warehouse_id, items, budget_id=project_id)
# items format:
# [{"material_id": 1, "qty": 10}, {"material_id": 2, "qty": 5}]

Automatic stock reservation

Immediately after the Requirement row is inserted, create_requirement() iterates over each item and calls:
reserved = reserve_stock(db, principal_warehouse.id, material_id, qty)
Each RequirementItem is then set to one of two statuses:
Item statusMeaning
reservedreserve_stock() returned True; Inventory.reserved was incremented.
pendingInsufficient stock at reservation time; the item is waiting.
The parent Requirement always starts with status = "pending" regardless of item statuses. It advances to partial or fulfilled only when a dispatch is created.

Requirement statuses

StatusMeaning
pendingCreated; no dispatch has been issued yet.
partialAt least one dispatch exists but not all requested quantities have been dispatched.
fulfilledEvery item has been fully dispatched (fulfilled_qty >= requested_qty for all items).
cancelledManually cancelled; all reservations have been released.

Cancelling a requirement

Requirements with status pending or partial can be cancelled. Cancellation:
  1. Iterates over all items with status reserved.
  2. Calls release_reservation(db, principal.id, item.material_id, item.requested_qty) for each, decrementing Inventory.reserved.
  3. Sets Requirement.status = "cancelled".
A requirement that is already fulfilled cannot be cancelled through the UI.

Auto-reprocessing

Whenever add_stock() is called, it triggers reprocess_requirements(db) at the end:
def reprocess_requirements(db: Session):
    requirements = db.query(Requirement).filter(
        Requirement.status.in_(["pending", "partial"])
    ).all()
    for req in requirements:
        for item in req.items:
            if item.status == "pending":
                success = reserve_stock(db, principal.id, item.material_id, item.requested_qty)
                if success:
                    item.status = "reserved"
    db.commit()
Requirements where all items transition to reserved (or fulfilled) are returned by reprocess_requirements() and surfaced as info messages in the Inventory page. The parent requirement status (pending/partial) does not change here — only dispatching advances it.

Build docs developers (and LLMs) love