← Back to Pull requests

feat(import): posted journal entries vs the re-run contract (#358) #367

Closed
unknown closed this pull request without merging on Nov 22, 2026 14:55 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 14:45 UTC
Author

Closes #358. Stacked on #364 (headless core contract); retarget to master once that merges.

Decision

1. Posting lives in a separate subcommand, fluvo workflow post-moves. It is not an import flag. --post-action is a single all-or-nothing RPC with no per-record accounting. A flow step is deferred.
2. posted_immutable is a named sub-reason of unaccounted, not a fourth stat. The identity and assert_reconciled stay unchanged. ReconStats.reasons and stats["unaccounted_reasons"] make the bucket legible, and the "dropped records" warning only fires for the unexplained remainder.
3. A draft that was posted in Odoo between runs takes the same path. Detection reads live state, the move is left untouched and counted, and import never calls button_draft.
4. Corrections and reversals are deferred.

What changed

  • lib/immutable.py: a pre-load guard for account.move (state) and account.move.line (parent_state).

  • - Rows targeting a posted record are taken out of the load. total is not shrunk.
    - Those rows are written to a _skipped.csv sidecar with a _SKIP_REASON column, never to the fail file, so --fail won't retry them forever.
    - With --o2m, the continuation rows follow their parent.
    - If the guard can't read state, it fails closed and aborts the run. Streaming is disabled for guarded models.
  • Preflight: a state column on a guarded model is refused. The fix is to drop it or pass --ignore state.

  • workflow post-moves:

  • - Posts with batch action_post, falling back to per-record on error.
    - The outcome is judged by re-reading state.
    - Returns a reconciled RunResult: created = posted now, failed = not found / not draft / refused (written to
    _post_fail.csv), unaccounted = already_posted or cancelled. Re-running it is safe.
  • assert_reconciled(expect_reasons=...): added for #359.

  • Docs: advanced_usage.md and odoo_workflows.md.
  • Deferred

  • Flow-step dispatch.

  • Reversals.

  • Drift detection on posted moves.

  • User-configurable rules (account.payment, stock.picking).

  • Folding skip-existing and skip-unchanged into named reasons.
  • Test plan

  • Unit tests in tests/test_immutable.py against a fake Odoo that upserts on external id. They cover the re-run identity, o2m partitioning, fail-closed abort, streaming fallback, every post-moves bucket, cancellation, and the preflight check.

  • Real Odoo 16, 17, 18 and 19 (throwaway compose stack), via tests/e2e/test_posted_moves_e2e.py: 2 passed, 1 xfailed on each version.

  • - Re-run contract: load as draft, post one move in Odoo, then re-run moves and lines. Drafts converge, the posted move and its lines are counted as posted_immutable, and there are no duplicates. post-moves posts the rest and is a no-op on re-run.
    - parent_state is readable on all four versions.
    - Finding: with check_move_validity: False, Odoo accepts a new line on a posted move, which unbalances posted books. Without the context it refuses. The account.move.line rule now also guards rows whose move_id/id or move_id/.id points at a posted move.
    - Pre-existing bug, pinned with a strict xfail: with --o2m, continuation rows are counted as failed and written to the fail file, although Odoo created the lines. A --fail re-run would then replay them as standalone records.

    Diff: 425 lines (+318 / -107) across 5 files Reviewer: bosd Review duration: 9m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.59)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 425 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 92% · Reviewer familiarity: 35%
    58%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #367"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.1% (MEDIUM) · Higher = larger blast radius
    45.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.5% · Lower = rushed or shallow review
    58.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.7% · Safe to merge
    18.7%
    Repository