RFC-0008: Compliance, Versioning, and Corrections

Viewed 107

Submitted documents in Framework M are strictly immutable. To handle real-world edits, complex temporal reporting, and external system integrations without breaking the ledger, we are proposing four formal patterns:

  1. The Sensible Default: Audit Timeline (AuditMixin)

    • Append-only global JSON log.
    • Provides out-of-the-box traceability ("Who changed what, when, and why") with minimal database footprint.
    • Ideal for UI rendering and indie deployments.
  2. The Enterprise Escalation: Shadow Tables (VersionedMixin)

    • Provisions dedicated _history SQL tables mirroring the primary schema.
    • Enables fast temporal SQL querying ("Time Travel") for high-compliance environments.
    • Crucially: Gated by Deployment-Level configuration (config.toml). Indie deployments face zero DB bloat unless they explicitly opt-in, at which point the DB Adapter handles routing and DDL.
  3. Sibling Extensions (Metadata Overlays)

    • Keep core financial documents locked.
    • Link an editable "Sibling" DocType for volatile, non-ledger metadata (Driver, Vehicle, ETA).
    • The UI overlays these fields so it feels like a single document, without causing race conditions or invalidating the ledger.
  4. The Correction Wizard (3 Regulated Flows)

    • Controlled via DocTypeMeta (correction_strategy):
      • Amend: The universal default. Cancels the document and creates a new Draft under a new incremented ID.
      • Restore: Rollback to a previous snapshot.
      • In-Place Edit (PK Acrobatics): For operational workflows (e-commerce, WMS integrations) where external systems crash if the machine id or human name changes. This executes a strict transaction: deep-copies the submitted row to _history, rolls the primary row back to Draft, and retains the exact same ID for external APIs.

Discussion MR: GitLab MR !111

Thoughts?

Edit: Track the progress here https://gitlab.com/castlecraft/framework-m/-/merge_requests/132

2 Answers

Following queries may need answers:

  • What does this document look like right now? - 99% use case
  • What changed in this document, and who changed it? - audit
  • What did this document look like at time T? - temporal query (e.g., what were payment terms as on 1st Jan?)
  • Show me all documents where field X changed after return filing - compliance reporting (eg: Invoice totals changing for invoices in Jan after it's return was filed)
  • Revert this document to a previous state - restore should create a new version
  • What automation triggered updates to the document? - debugging

One solution may not solve all problems. Keeping it configurable could be useful.

  • Table with diff change for timeline - just for visibility and checks
  • New rows in the table with version numbers - useful for quering and restoring
  • DB level audit trial

Edit after submit should ideally add new rows to the table, along with the diff changes to timeline. For non submittable docs, (eg: item / party masters), this can be configurable.

Different transitions possible:

  • Submit -> Cancel -> Amend (creates new document - ux to copy)
  • Submit -> Cancel -> Restore (reverts to submited state) - controller methods to restrict
  • Submit -> Edit -> Draft / Submit - controller methods to decide if cancel is necessary and if edit should be restricted.

Integration with different systems is possible and calling cancel and re-submit may not be a good idea at all times.