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 dispatch converts reserved stock into an actual outbound movement. It takes one or more items from a requirement that has reserved stock, decrements both stock and reserved in the principal warehouse, records an OUT movement, and generates a numbered Guía de Remisión document.

Creating a dispatch from a requirement

Only requirements with status pending or partial that have at least one item with reserved stock appear in the dispatch selector. To generate a dispatch:
1

Open the Dispatches page

Navigate to Despachos in the sidebar.
2

Select the requirement

Choose a requirement from the Selecciona requerimiento dropdown. The list shows requirement ID, creation date (Lima time), and current status.
3

Review the items

Each item with pending quantity is shown with its available-to-dispatch amount. Adjust quantities if you want a partial dispatch (minimum 1, maximum remaining pending quantity per item).
4

Generate

Click Generar Despacho. The service call is:
create_dispatch(db, requirement_id, items, user_id=owner_id)
# items format:
# [{"material_id": 1, "qty": 5}, {"material_id": 2, "qty": 3}]
# Returns (True, guia_number) or (False, error_message)

Dispatch validation

create_dispatch() runs a two-phase approach: it validates everything before touching the database. For each item in the dispatch request it checks:
  1. Quantity does not exceed pending amountqty <= (requested_qty - fulfilled_qty).
  2. Item has reserved stockreq_item.status != "pending". Items still in pending cannot be dispatched.
  3. Principal warehouse has enough physical stocksum(inv.stock) >= qty across all inventory records for that material.
Materials with RequirementItem.status == "pending" (no reserved stock) cannot be dispatched. The error message is: "Material '{name}' no tiene stock reservado. Ve a Inventario para agregar stock al almacén principal." Add stock to the principal warehouse first; reprocess_requirements() will then reserve it automatically.

What happens on dispatch

Once validation passes, create_dispatch() applies all changes atomically in a single db.commit():
  1. Stock decrementedInventory.stock -= qty distributed FIFO across budget records.
  2. Reserved decrementedInventory.reserved -= qty distributed FIFO across budget records.
  3. OUT movement loggedMovement(movement_type="OUT", reference_type="dispatch", reference_id=dispatch.id).
  4. RequirementItem updatedfulfilled_qty += qty; status becomes fulfilled if fully dispatched, partial otherwise.
  5. Requirement status updatedfulfilled if all items are now fully dispatched, partial if any remain.

Guía de Remisión

Each dispatch receives a unique Guía de Remisión number assigned at creation time:
The guia number format is GR-YYYYMMDD-{dispatch_id:05d}, for example GR-20260518-00042. The date component is derived from datetime.utcnow() at the time of dispatch creation. The PDF is generated by utils/pdf_generator.py (using fpdf2) and saved to storage/guides/<guia_number>.pdf.
From the dispatch history, click PDF next to any dispatch to download an HTML version of the Guía de Remisión. Open it in a browser and use Ctrl+P to print or save as PDF.

Cancelling a dispatch

Click the 🗑 button in the dispatch history and confirm the deletion prompt. delete_dispatch() reverses all inventory changes:
  • Returns qty to Inventory.stock and Inventory.reserved in the principal warehouse.
  • Resets RequirementItem.fulfilled_qty and status accordingly.
  • Deletes any associated receipt if one had been created.
  • Removes the OUT movement records for the dispatch.

Build docs developers (and LLMs) love