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.

Sistema MRP uses SQLAlchemy ORM models as pure data definitions with no business logic. All business logic lives in the services layer.
These models are intentionally free of business logic. Never call methods on model instances to mutate state — always go through the corresponding service functions (e.g. inventory_service, requirement_service) and pass an explicit db: Session.
Represents a physical storage location. Every client has exactly one "principal" warehouse (the main stock store) and any number of "obra" (work-site) warehouses. The principal warehouse is resolved by matching owner_id and type == "principal".
ColumnTypeNullableDescription
idIntegerNoPrimary key.
nameStringNoHuman-readable warehouse name.
typeStringNo"principal" or "obra".
locationStringYesCity or district (informational).
addressStringYesPhysical street address (informational).
owner_idIntegerYesFK → users.id. NULL for legacy warehouses without an assigned owner.
Relationships
  • inventory → list of Inventory rows for this warehouse.
  • movements → list of Movement audit records for this warehouse.
A catalogue entry for a physical material or supply item. Codes must be globally unique. Both soles and dollar prices default to 0.0 and are used by budget cost calculations.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
codeStringNoUnique catalogue code.
nameStringNoDisplay name.
unitStringYesUnit of measure (e.g. "kg", "m", "pza").
descriptionStringYesOptional free-text description.
unit_priceFloatYesUnit price in Peruvian soles (defaults to 0.0).
unit_price_dolaresFloatYesUnit price in US dollars (defaults to 0.0).
Relationships
  • inventory → list of Inventory rows where this material appears.
  • movements → list of Movement records that reference this material.
Notesunit_price and unit_price_dolares feed budget cost projections. Keep both fields up to date so cost reports remain accurate in either currency.
Tracks the quantity of a specific material in a specific warehouse. Each row is scoped to a single (warehouse_id, material_id) pair.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
warehouse_idIntegerNoFK → warehouses.id.
material_idIntegerNoFK → materials.id.
stockIntegerNoTotal units on hand (defaults to 0).
reservedIntegerNoUnits held for pending requirements (defaults to 0).
budget_idIntegerYesFK → budgets.id. Optional link to the project this stock belongs to.
budget_nameStringYesDenormalised budget name for display without a join.
is_activeBooleanNoFalse when the linked project was deleted; stock is frozen until redirected (defaults to True).
last_updatedDateTimeYesUTC timestamp of the last stock change.
Relationships
  • warehouse → parent Warehouse.
  • material → parent Material.
  • budget → optional parent Budget.
Stock invariantavailable = stock − reserved. Before reserving, inventory_service verifies stock − reserved >= requested_qty. reserve_stock() mutates reserved but does not commit — the calling service commits after all items are processed.
A work-site request for materials from the principal warehouse. Created at an "obra" warehouse; the service layer resolves the correct principal warehouse via owner_id.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
warehouse_id_obraIntegerNoFK → warehouses.id (must be an "obra" warehouse).
statusStringNo"pending", "partial", "fulfilled", or "cancelled" (defaults to "pending").
budget_idIntegerYesFK → budgets.id. Project this requirement is charged to.
budget_nameStringYesDenormalised budget name for display without a join.
created_atDateTimeYesUTC creation timestamp.
notesStringYesFree-text operator notes.
Relationships
  • items → list of RequirementItem lines.
  • dispatches → list of Dispatch records fulfilling this requirement.
A single line in a Requirement, specifying how many units of one material are requested and how many have been fulfilled so far.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
requirement_idIntegerNoFK → requirements.id.
material_idIntegerNoFK → materials.id.
requested_qtyIntegerYesNumber of units originally requested.
fulfilled_qtyIntegerNoUnits dispatched so far (defaults to 0).
statusStringNo"pending", "reserved", "partial", or "fulfilled" (defaults to "pending").
Relationships
  • requirement → parent Requirement.
  • material → the requested Material.
Records a physical shipment sent from the principal warehouse to an obra site. Created from a Requirement that is fully or partially reserved.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
requirement_idIntegerNoFK → requirements.id.
dispatch_dateDateTimeYesUTC timestamp of dispatch (defaults to utcnow).
guia_numberStringYesFormatted guide number: GR-YYYYMMDD-{id:05d}. Generated after insert when the id is known.
user_idIntegerYesID of the user who created the dispatch (no FK constraint).
Relationships
  • items → list of DispatchItem lines.
  • requirement → parent Requirement.
  • receipt → single Receipt confirming arrival (one-to-one, optional).
NotesA PDF “Guía de Remisión” is generated by utils/pdf_generator.py and saved to storage/guides/<guia_number>.pdf at dispatch time.
A single line in a Dispatch, recording how many units of one material were physically sent.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
dispatch_idIntegerNoFK → dispatches.id.
material_idIntegerNoFK → materials.id.
dispatched_qtyIntegerYesNumber of units included in this shipment.
Relationships
  • dispatch → parent Dispatch (via backref).
  • material → the dispatched Material.
Confirms that a dispatched shipment has physically arrived at the obra site. Creating a receipt triggers an Inventory increment and a Movement(type="IN") at the destination warehouse.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
dispatch_idIntegerNoFK → dispatches.id (one-to-one).
receipt_dateDateTimeYesUTC timestamp of confirmation (defaults to utcnow).
user_idIntegerYesID of the user who confirmed receipt (no FK constraint).
Relationships
  • dispatch → parent Dispatch.
  • items → list of ReceiptItem lines (via backref).
ReceiptItem sub-modelEach receipt line records the actually received quantity and whether it has been confirmed:
ColumnTypeNullableDescription
idIntegerNoPrimary key.
receipt_idIntegerNoFK → receipts.id.
material_idIntegerNoFK → materials.id.
received_qtyIntegerYesUnits confirmed received.
confirmedBooleanNoTrue once the line has been verified (defaults to False).
An immutable audit record written every time stock changes anywhere in the system. Never modified after creation.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
warehouse_idIntegerNoFK → warehouses.id. Warehouse where the change occurred.
material_idIntegerNoFK → materials.id. Material affected.
qty_changeIntegerYesSigned quantity delta (positive = stock in, negative = stock out).
movement_typeStringYes"IN" (stock added) or "OUT" (stock removed).
reference_typeStringYesEntity that triggered the movement (e.g. "dispatch", "receipt").
reference_idIntegerYesPrimary key of the triggering entity.
user_idIntegerYesID of the user who triggered the change (no FK constraint).
timestampDateTimeYesUTC timestamp of the change (defaults to utcnow).
Relationships
  • warehouse → the affected Warehouse.
  • material → the affected Material.
NotesMovement rows form the complete stock audit trail. Do not delete or update them. All timestamps are stored in UTC; the UI converts to Lima/Peru time (UTC-5, no DST) for display.
Represents a project or obra that materials and costs are tracked against. Inventory rows and requirements can be linked to a budget for cost attribution.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
nameStringNoProject name.
budget_solesFloatNoApproved budget in Peruvian soles (defaults to 0.0).
budget_dolaresFloatNoApproved budget in US dollars (defaults to 0.0).
notesStringYesOptional free-text notes.
is_activeBooleanNoFalse freezes associated inventory rows until redirected (defaults to True).
is_finishedBooleanNoMarks the project as complete (defaults to False).
finished_atDateTimeYesUTC timestamp of project completion. NULL while active.
created_atDateTimeYesUTC creation timestamp.
NotesWhen a budget is deactivated (is_active = False), linked Inventory rows are also set to is_active = False, freezing that stock until it is manually redirected to another budget or warehouse.
An application user. Two roles exist: "superadmin" (single, non-deletable system account) and "cliente" (regular operator). All data queries are scoped by owner_id matching the authenticated user’s id.
ColumnTypeNullableDescription
idIntegerNoPrimary key.
usernameStringNoUnique login handle (indexed).
emailStringNoUnique email address (indexed).
password_hashStringNobcrypt hash (12 rounds). Never store or log plaintext passwords.
roleStringNo"superadmin" or "cliente" (defaults to "cliente").
is_activeBooleanNoFalse locks the account (defaults to True).
created_atDateTimeYesUTC creation timestamp.
NotesAccounts are locked automatically after 5 consecutive failed login attempts and unlocked after 15 minutes. Sessions expire after 30 minutes of inactivity (server-side check). The password_hash column stores the bcrypt digest — never the raw password.

Build docs developers (and LLMs) love