The dispatch service converts a fulfilled or partially-reserved requirement into a physical stock movement. It follows a strict two-phase approach: all validations are performed first, and no database changes are applied until every check passes. A successful dispatch decrementsDocumentation 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.
Inventory.stock and Inventory.reserved across the principal warehouse’s budget records (FIFO), writes an OUT movement, and generates a GR-YYYYMMDD-{id:05d} guide number. Reversing a dispatch via delete_dispatch restores all affected stock and removes the linked receipt if one exists.
create_dispatch
GR-YYYYMMDD-{dispatch_id:05d} guide number is generated and returned.
The guide number is formatted as GR- followed by the UTC date of dispatch (YYYYMMDD) and the zero-padded dispatch ID (five digits). Example: GR-20250318-00042.
Active SQLAlchemy session. Commits internally on success.
ID of the requirement being dispatched against.
Materials and quantities to dispatch. Each entry must correspond to a line item on the requirement.
ID of the user creating the dispatch. Recorded on the
Dispatch record and the Movement log entries.True when the dispatch was created successfully.On success: the guide number string (e.g.
"GR-20250318-00042"). On failure: a descriptive error message.itemslist must not be empty.- Requirement and its associated warehouses must exist.
- For each item: dispatched quantity must not exceed remaining unfulfilled quantity.
- For each item: the requirement line item must have status
reserved(notpending). - For each item: total principal-warehouse stock must be sufficient.
- Creates the
Dispatchrecord and flushes to obtain an ID. - Assigns the guide number.
- For each item: decrements
stockandreservedacross budget records in FIFO order. - Updates each
RequirementItem.fulfilled_qtyand status (fulfilledorpartial). - Sets the parent
Requirement.statustofulfilledorpartial. - Writes
Movement(type="OUT", reference_type="dispatch")entries.
get_dispatches
Dispatch records from the database without filtering or pagination.
Active SQLAlchemy session.
List of all
Dispatch ORM objects.get_dispatch_detail
Dispatch record by ID. Returns None when not found.
Active SQLAlchemy session.
ID of the dispatch to retrieve.
The
Dispatch ORM object, including related items, requirement, and receipt via lazy loading. Returns None if no matching record exists.cancel_dispatch
cancelled and reverts stock at the obra warehouse. For each dispatch item, the quantity is added back to the obra inventory record linked to the requirement’s project.
Active SQLAlchemy session. Commits internally.
ID of the dispatch to cancel.
True when the dispatch was found and cancelled; False otherwise.delete_dispatch
owner_id so clients cannot delete dispatches belonging to other accounts. If the dispatch has an associated receipt, the receipt is deleted first.
Reversal steps performed for each dispatch item:
- Restores
stockandreservedon the principal-warehouse inventory record. - If a receipt exists, decrements
stockon the obra-warehouse inventory record (floored at zero). - Decrements
RequirementItem.fulfilled_qtyand recalculates its status (fulfilled,partial, orreserved). - Deletes all
Movementrecords withreference_type="dispatch"andreference_id=dispatch_id. - Deletes all
DispatchItemrecords. - Deletes the
Dispatchrecord.
Active SQLAlchemy session. Commits internally.
ID of the dispatch to permanently delete.
Client user ID. The dispatch is only returned for deletion when it belongs to a warehouse owned by this user.
True when the dispatch was found and deleted; False when not found.Empty string on success;
"Despacho no encontrado." when not found.