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.

The receipt service is the final step in the MRP fulfillment cycle. Once materials leave the principal warehouse via a dispatch, a receipt confirms their physical arrival at the obra (work-site) warehouse. Creating a receipt increments the obra’s inventory stock for each dispatched material, writes a Movement(type="IN", reference_type="receipt") entry, and timestamps everything in Lima time (UTC−5, no daylight saving). Duplicate receipts for the same dispatch are rejected.

create_receipt

create_receipt(db, dispatch_id, user_id=1) -> tuple[bool, str]
Creates a receipt against an existing dispatch. The function looks up the dispatch, verifies it has not already been received, then for each dispatch item:
  1. Calls get_or_create_inventory on the obra warehouse, scoping the record to the requirement’s budget_id when present.
  2. Adds the dispatched quantity to inventory.stock.
  3. Inserts a ReceiptItem(confirmed=True).
  4. Inserts a Movement(type="IN", reference_type="receipt").
All changes are committed in a single db.commit() at the end. Timestamp behavior: The Receipt.receipt_date and movement timestamps use Lima local time (datetime.now(UTC-5)). The timezone offset is applied in the helper _now_lima() and the tzinfo is stripped before storage so the value is stored as a naive datetime in Lima wall-clock time.
db
Session
required
Active SQLAlchemy session. The caller opens and closes the session; this function commits internally.
dispatch_id
int
required
ID of the dispatch being confirmed as received.
user_id
int
default:"1"
ID of the user confirming receipt. Recorded on both the Receipt record and each Movement entry.
[0]
bool
True when the receipt was created successfully.
[1]
str
On success: "Recepción registrada correctamente". On failure: one of:
  • "Despacho no existe"dispatch_id not found.
  • "Este despacho ya fue recibido" — a receipt already exists for this dispatch.
from database import SessionLocal
from services.receipt_service import create_receipt

db = SessionLocal()
try:
    ok, msg = create_receipt(db, dispatch_id=42, user_id=3)
    if ok:
        print("Receipt recorded:", msg)
    else:
        print("Could not record receipt:", msg)
finally:
    db.close()

What gets written to the database

RecordAction
ReceiptCreated with dispatch_id, receipt_date (Lima time), user_id
ReceiptItemOne row per dispatch item with received_qty and confirmed=True
Inventory (obra)stock += dispatched_qty, scoped to the requirement’s project when budget_id is set
Movementtype="IN", reference_type="receipt", warehouse_id=obra, Lima timestamp

Project-scoped inventory at obra

When the originating requirement has a budget_id, the obra inventory is looked up and created as a project-scoped record (budget_id + budget_name). This mirrors the structure used in the principal warehouse and ensures cost tracking remains consistent per project at both ends of the supply chain.
# Internally, create_receipt calls:
inventory = get_or_create_inventory(
    db,
    warehouse_obra,
    material_id,
    budget_id=req_budget_id,      # from requirement
    budget_name=req_budget_name,  # from requirement
)
inventory.stock += qty

Build docs developers (and LLMs) love