← Back to Pull requests

[17.0][FIX] stock_inventory: link the applied move lines when they are created #2711

Open
unknown opened this pull request with 230 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 06, 2026 15:32 UTC
Author

After the moves are done, _apply_inventory links "the last move line" on each quant's product, lot and location to the inventory. That guess fails in two ways:

  • Validating the inventory moves can free a picking reservation on an emptied lot: _action_done reserves another lot of the same location, which creates a newer move line. The search then links that picking line to the inventory and prefixes its reference, and the inventory's own line stays unlinked. It's the symptom reported in #2499.

  • The search sorts on create_date, which every line of a transaction shares, so it can pick any line created in the same transaction. We saw lines linked to the wrong inventory, and inventories left with no lines.
  • Change

  • _get_inventory_move_values writes inventory_adjustment_id and "<inventory>: <move name>" on the move line values, so each line is linked when it is created. Only lines built through this method are linked, which covers what core creates when applying.

  • move_quants() builds its moves with the same method, so only the quants being applied are linked: _apply_inventory passes their ids in the context.

  • The search and its ValueError("No move lines have been created") are gone. A quant applied without an inventory no longer rewrites the line the search happened to find.

  • Linking used to write the inventory row through stock_move_ids. That made two concurrent applies of one inventory conflict, and the retried one saw every quant done and auto-completed it. _apply_inventory now writes the inventories when auto-complete is on, to keep that.
  • test_14 reproduces the re-reservation and fails without the fix. test_15 checks that relocating a quant under an in-progress inventory stays unlinked.

    AI assistance: prepared with Claude Code (Claude Opus 5.5); reviewed and tested by me.

    Diff: 230 lines (+172 / -58) across 2 files Reviewer: petrus-v Review duration: 35451m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.37) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.37 · 230 lines diff across 2 files
    0.37
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.326
    Real PR Conversation Timeline
    1 comments
    "Review active on #2711"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 37% (MEDIUM) · Higher = larger blast radius
    37%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 19.7% · Safe to merge
    19.7%