Files
alla-allaos-fullstack/docs/implementation/task-f2-approval-matrix-foundation.md
phaichayon 052677fa2c task f.3
2026-06-26 11:03:25 +07:00

4.5 KiB

Task F.2: Approval Matrix Foundation

Summary

This task adds approval-matrix based workflow resolution for quotation submission so the system no longer relies on a single static workflow code.

Delivered

Matching Rules

  • Scope filters consider organization, entity type, active state, and soft delete.
  • productType, branchId, and currency match exact values or null wildcard.
  • amount respects minAmount and maxAmount when those bounds exist.
  • Specific rules outrank default rules.
  • Specificity scoring prefers:
    • product type match
    • branch match
    • currency match
    • amount-range match
  • Lower priority value wins after specificity.
  • If specificity and priority tie, the newest active rule wins.
  • If candidates still tie on the same creation timestamp, the resolver throws a deterministic configuration conflict.
  • If no specific rule matches, the resolver falls back to an active default rule.

Submit Approval Integration

  • Quotation submit approval now:
    1. loads the quotation
    2. enforces CRM scoped access
    3. resolves the approval matrix
    4. submits approval using the resolved workflowId
    5. writes audit data for the resolution
  • Existing approve, reject, return, and cancel flows remain unchanged.

Audit

  • Matrix CRUD uses entityType = crm_approval_matrix.
  • Matrix maintenance actions:
    • create_approval_matrix
    • update_approval_matrix
    • delete_approval_matrix
  • Quotation submission writes resolve_approval_matrix with:
    • quotationId
    • approvalRequestId
    • matrixId
    • workflowId
    • matchReason
    • productType
    • branchId
    • amount
    • currency

Seed Behavior

  • Foundation seed creates or refreshes one active default quotation matrix pointing to quotation_standard_approval.
  • This preserves legacy quotation approval behavior until organization-specific rules are added.
  • Sample non-default matrices were intentionally not seeded because additional workflows such as executive approval are not yet guaranteed in every environment.

Known Limitations

  • F.2 adds API and service foundations only. No matrix admin UI is included.
  • Overlapping active rules are allowed. Resolver handles them deterministically, but configuration hygiene still matters.
  • Matrix branch, product, and currency values currently assume the same ids already stored on quotation records.