Overview
The Purchases API handles the registration of inventory purchases from providers. When a purchase is created, the system automatically:- Updates product stock quantities (for products with inventory control enabled)
- Updates product cost prices based on the latest purchase price
- Records stock movements for audit trails
- Calculates totals including IVA (19% tax for invoices)
Create Purchase
Request Body
ID of the provider from whom the purchase is made.
Document number (invoice or receipt number).
Document type. Options:
FACTURA, BOLETA, SIN_DOCUMENTO. Default: FACTURA.Array of purchase items. Each item contains:
product_id(integer, required): Product identifiercantidad(decimal, required): Quantity purchasedprecio_costo_unitario(decimal, required): Unit cost price (net amount)
Additional notes or observations about the purchase.
Purchase date. If not provided, current timestamp is used.
Response
Unique purchase identifier.
Provider identifier.
Document number.
Document type (FACTURA, BOLETA, or SIN_DOCUMENTO).
Purchase date.
Net amount (sum of all item subtotals).
IVA tax amount (19% for FACTURA, 0 for other document types).
Total amount (monto_neto + iva).
Additional notes.
Timestamp when the purchase was registered.
Nested provider object with complete provider information.
Array of purchase detail items, each containing product information, quantity, unit cost, and subtotal.
List Purchases
Response
Returns an array of purchase objects with full details including provider and items.Get Purchase
Path Parameters
Unique purchase identifier.
Response
Returns a single purchase object with complete details.Update Purchase
Path Parameters
Unique purchase identifier.
Request Body
Use the same structure as creating a purchase. All fields fromPurchaseCreate are accepted.
Behavior
When updating a purchase:- Old stock quantities are reversed (subtracted from inventory)
- Old purchase details are deleted
- New stock quantities are applied (added to inventory)
- New purchase details are created
- Product costs are updated based on new prices
- Stock movements are recorded for audit trail
Delete Purchase
Path Parameters
Unique purchase identifier.
Behavior
When deleting a purchase:- Stock quantities are reversed (subtracted from current inventory)
- Stock movements are recorded with “AJUSTE” (adjustment) reason
- Purchase and all its details are permanently deleted
Response
Returns no content on success.Get Purchase PDF
Path Parameters
Unique purchase identifier.
Response
Returns an HTML document formatted for printing, including:- Company (issuer) information
- Provider details
- Purchase items with quantities and prices
- Totals (net, IVA, total)
Purchase Flow & Inventory Updates
Automatic Stock Updates
When a purchase is created:- Product Validation: The system validates that products exist and don’t have variants (variant-parent products cannot be purchased directly)
- Cost Update: Each product’s
costo_unitariois updated to match the latestprecio_costo_unitariofrom the purchase - Stock Increment: For products with
controla_stock: true, thestock_actualis increased by the purchased quantity - Stock Movement: A
StockMovementrecord is created with:tipo: “ENTRADA” (incoming)motivo: “COMPRA” (purchase)cantidad: Purchased quantitybalance_after: New stock leveldescription: Purchase folio reference
IVA Calculation
- FACTURA: 19% IVA is applied to the net amount
- BOLETA or SIN_DOCUMENTO: No IVA (iva = 0)
Transaction Safety
All purchase operations are atomic:- If any item fails validation, the entire purchase is rolled back
- Stock updates and purchase records are committed together
- No partial purchases are possible