[16.0][IMP] stock_picking_line_sequence: create moves in batch, renumber in sequence order #2464
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
dreispt
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 onecreate()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:
stock.rule._run_pull());purchase.order.line._create_stock_moves());create()now uses@api.model_create_multiand renumbers the pickings of the batch once, after all moves exist._reset_sequence()only writes a number that changes. This avoids the fullstock.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 ofstock.move, which is its_orderand 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
keep_line_sequencecontext (copying a picking, backorders on validation) and the signatures ofcreate()and_reset_sequence().stock.move.create()with@api.modelkeep working, but they still split the batch for the modules below them. They benefit once they switch to@api.model_create_multitoo.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.