← Back to Pull requests

[16.0][IMP] stock_picking_line_sequence: create moves in batch, renumber in sequence order #2464

Closed
unknown closed this pull request without merging on Oct 01, 2026 09:19 UTC
View on GitHub
unknown unknown commented on Sep 25, 2026 22:30 UTC
Author

This PR makes creating stock moves much faster with this module installed, and makes the renumbering of a picking's moves follow their sequence instead of the state of the cache.

Faster batch create

stock.move.create() was declared with @api.model, so Odoo split every batch create into one create() per move, for all modules below it in the MRO. After each of these creates, the whole picking was renumbered, and every move of the picking was written again, even when its number stayed the same. Creating n moves in a picking therefore cost n creates and about n²/2 writes.

Odoo creates moves in batch in its most frequent flows:

  • pull rules, for example the delivery of a confirmed sale order (stock.rule._run_pull());

  • the receipt of a confirmed purchase order (purchase.order.line._create_stock_moves());

  • saving a picking with new lines in the form.
  • create() now uses @api.model_create_multi and renumbers the pickings of the batch once, after all moves exist. _reset_sequence() only writes a number that changes. This avoids the full stock.move.write() for every unchanged move, which runs the logic of stock and of every module that extends it.

    Renumbering order

    The moves were renumbered in the order of the cache, not in the order of their sequence. When the moves of a picking were already loaded, the ORM added a new move at the end of that list, whatever its sequence. The result depended on whether the picking had been read before in the same transaction.

    This matters wherever moves are created with an explicit sequence. Purchase, for example, copies the sequence of the order line into the move, so a line added later between the others could get the last number in the receipt, although a fresh read of the picking showed it between them.

    _reset_sequence() now renumbers in the (sequence, id) order of stock.move, which is its _order and the order the database returns. Moves created with the default sequence (9999) still go to the end in the order they were created, as before. Virtual records of an onchange are still skipped.

    Compatibility

  • Unchanged: the numbering of moves created with the default sequence, the keep_line_sequence context (copying a picking, backorders on validation) and the signatures of create() and _reset_sequence().

  • Changed: a move created with an explicit sequence into a picking gets its place by that sequence, whether or not the picking's moves were loaded before.

  • Modules that override stock.move.create() with @api.model keep working, but they still split the batch for the modules below them. They benefit once they switch to @api.model_create_multi too.
  • Measured

    On 16.0 with only this module and its dependencies installed:

    | Case | Before | After |
    |---|---|---|
    | Creating a picking with 100 moves | 545 queries | 248 queries |
    | Adding 100 moves to an existing picking in one call | 433 queries | 136 queries |

    The resulting sequences are the same in both cases. Most of the remaining queries come from creating the moves themselves in stock, not from this module. The sort runs on values that are already loaded and adds no query.

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

    Diff: 413 lines (+309 / -104) across 5 files Reviewer: dreispt Review duration: 7848m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 413 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: 100% · Reviewer familiarity: 35%
    60%
    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.361
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2464"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.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: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    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: 60.5% · Lower = rushed or shallow review
    60.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: 17.7% · Safe to merge
    17.7%