Skip to main content

Document Model

Every document in penquify consists of three parts:
Document
  +-- header: DocHeader     # metadata, emitter, receiver, references
  +-- items: [DocItem]      # line items with quantities and prices
  +-- observations: str     # handwritten notes (simulated)

DocHeader

The header contains all metadata fields for a logistics document. Every field beyond doc_type, doc_number, and date is optional (defaults to empty string).
FieldTypeDescription
doc_typestrTemplate type: guia_despacho, factura, purchase_order, bill_of_lading
doc_numberstrDocument number
datestrDate string (YYYY-MM-DD or DD/MM/YYYY for display)
FieldTypeDescription
emitter_namestrCompany name
emitter_rutstrTax ID (Chilean RUT format)
emitter_girostrBusiness activity
emitter_addressstrAddress
emitter_phonestrPhone number
emitter_emailstrEmail
FieldTypeDescription
receiver_namestrCompany name
receiver_rutstrTax ID
receiver_girostrBusiness activity
receiver_addressstrAddress
receiver_contactstrContact person
FieldTypeDescription
oc_numberstrPurchase order number
oc_datestrPurchase order date
payment_termsstrPayment terms
solpe_numberstrSAP SolPe number
FieldTypeDescription
dispatch_datestrDispatch date
vehicle_platestrVehicle license plate
driver_namestrDriver name
driver_rutstrDriver tax ID
transport_typestrTransport type (default: "Venta")
temperaturestrTemperature at dispatch
FieldTypeDescription
sii_officestrSII regional office
sii_resolutionstrSII authorization resolution
received_bystrPerson who received the goods
received_rutstrReceiver’s personal tax ID
received_datestrDate of receipt

DocItem

Each line item in the document.
FieldTypeDefaultDescription
posintLine position (1-based)
codestrProduct/material code
descriptionstrProduct description
qtyfloatQuantity
unitstrUnit of measure (UN, KG, CJ, L, etc.)
unit_pricefloat0Price per unit
totalfloat0Line total
batchstr""Batch/lot number
sap_materialstr""SAP material number
sap_qtyfloat0SAP quantity (may differ from document qty)
sap_unitstr""SAP unit of measure

Computed Properties

The Document class computes totals automatically:
doc.subtotal  # sum of item totals (or qty * unit_price)
doc.iva       # subtotal * 0.19 (Chilean VAT)
doc.total     # subtotal + iva

JSON Schema

A complete document as JSON:
{
  "header": {
    "doc_type": "guia_despacho",
    "doc_number": "00054321",
    "date": "15/04/2026",
    "emitter_name": "ACME FOODS S.A.",
    "emitter_rut": "76.123.456-7",
    "emitter_address": "Av. Industrial 1200, Santiago",
    "receiver_name": "DISTRIBUIDORA CENTRAL LTDA.",
    "receiver_rut": "77.987.654-3",
    "oc_number": "4500001234",
    "vehicle_plate": "ABCD-12",
    "driver_name": "Juan Perez"
  },
  "items": [
    {
      "pos": 1,
      "code": "AF-1001",
      "description": "HARINA DE TRIGO PREMIUM 25KG",
      "qty": 40,
      "unit": "UN",
      "unit_price": 12500,
      "total": 500000
    }
  ],
  "observations": "1 pallet. Lote 2026-03."
}

Template System

Documents are rendered to HTML using Jinja2 templates. The default template is guia_despacho.html (Chilean dispatch guide). Templates receive the full document dict via doc.to_dict():
  • header.* — all header fields
  • items[] — array of item dicts
  • observations — observation text
  • subtotal, iva, total — computed values
Templates are standard HTML+CSS files stored in penquify/templates/. See the Custom Template guide to create your own.