Skip to content

Approvals & Sequences

Backend domains:

RBAC Paths: APPROVAL_CONFIGS, AUTO_SEQUENCES.

Approval configurations

ApprovalConfig rules route documents to approvers when they exceed a threshold or match a condition. Today this is wired only on purchase_requisitions/, but the framework is generic — any domain can call into it.

Each config carries:

  • document_typePURCHASE_REQUISITION (more to come).
  • condition — currently amount >= threshold.
  • approver_user_ids — one or more users who must approve.
  • approval_modeANY_ONE or ALL.
  • escalation_after_hours — optional time-based escalation.

Key mutations: createApprovalConfig, updateApprovalConfig, deleteApprovalConfig.

Key queries: getAllApprovalConfigs, getApprovalConfig.

When a PR is submitted, purchase_requisitions/services/ looks up the matching config, creates approval records for each approver, and emits a notification (today email-only; WhatsApp planned). The PR cannot convert to a PO until the approval policy is satisfied.

Auto sequences (document numbering)

Every numbered document — quote, order, invoice, receipt, payment, PR, PO, JE, credit, supplier invoice, supplier credit — pulls its number from auto_sequences/. This is the centralised, concurrency-safe counter for the tenant.

An AutoSequence carries:

  • document_typeQUOTE, ORDER, INVOICE, RECEIPT, PAYMENT, PURCHASE_REQUISITION, PURCHASE_ORDER, JOURNAL, CREDIT, SUPPLIER_INVOICE, SUPPLIER_CREDIT, …
  • prefix — e.g. INV-, PO-.
  • padding — pad-to-N zeros, e.g. 500001.
  • current_value — last issued integer.
  • reset_strategyNEVER, YEARLY, MONTHLY.
  • branch_code — optional per-branch sub-sequence.

Key mutations: createAutoSequence, updateAutoSequence, deleteAutoSequence, resetAutoSequenceCounter.

Key queries: autoSequences, autoSequence.

Sequences are reserved transactionally — concurrent invoice creations cannot collide on the same number. Numbers are never re-issued, even if the document is deleted (so audit trails stay clean).

Frontend notes

  • Settings UI for both lives under "Configuración → Documentos".
  • A PYME owner should be able to configure a one-step approval ("anything over $500 → me") in under a minute.
  • Approval-pending counts should surface on the home dashboard for any user who is an approver.