[16.0] [FIX] stock_move_location: prevent picking type reset on origin change#2553
Open
alvaro-gmz wants to merge 1 commit intoOCA:16.0from
Open
[16.0] [FIX] stock_move_location: prevent picking type reset on origin change#2553alvaro-gmz wants to merge 1 commit intoOCA:16.0from
alvaro-gmz wants to merge 1 commit intoOCA:16.0from
Conversation
9d67cb5 to
462c226
Compare
…tination The picking_type_id field was defined as a stored computed field depending on origin_location_id. Every write to the wizard triggered the compute and overwrote the user's manual selection, so the operation type was reset when changing origin or clicking "Immediate/Planned Transfer". Additionally, lines created from the onchange on origin could end up with an empty destination_location_id (the user hadn't set it yet at that point), leading to a NOT NULL constraint error when creating the stock.move on transfer execution. Changes: - Restore picking_type_id as a regular Many2one field with a simple default (first internal or outgoing picking type for the company), which matches the behaviour the module had before the compute-based variant was introduced. The user's manual selection is now preserved throughout the whole wizard lifecycle and the outgoing picking types added by the ACSONE improvement are still supported as default. - Add a safeguard in action_move_location that propagates the wizard's destination_location_id to any line that lacks one before creating the picking, so "Planned Transfer" no longer fails when lines were built before the destination was set. - Add regression tests covering both fixes.
462c226 to
552e929
Compare
sergiobstoj
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The move location wizard (
wiz.stock.move.location) had two related issues that caused user-entered data to be silently overwritten or lost:picking_type_id) was reset whenever the user changed the origin location or saved the wizard (e.g. clicking "Immediate Transfer" or "Planned Transfer"), discarding any manual selection the user had made.stock.move.location_dest_idwhen the transfer was executed.Root cause
1. Picking type reset
The combination of
compute+store=True+readonly=Falsewith a dependency onorigin_location_idmeans the user could edit the field in the UI, but any write to the record (including button clicks that save the wizard) re-triggered the compute and silently overwrote the manual selection.Before this behaviour was introduced, the module used a plain
defaultthat returned the first internal picking type of the company. The computed variant was added to auto-pick a type based on the origin location, but the side effect of losing the user's input was never intended.2. Destination missing on lines
When the origin location changes,
onchange_origin_locationcalls_reset_stock_move_location_lines, which builds lines usingself.destination_location_id. If the user sets the origin before the destination, the lines end up with no destination. The line-level onchange for the destination propagates the value to the existing lines afterwards, but there is no safeguard when the flow gets the wizard into a state where at least one line reaches the picking creation step without a destination.Fix
picking_type_idto a regularMany2onefield with a simpledefault=_get_default_picking_type_idreturning the first internal or outgoing picking type of the company. This matches the original module behaviour before the compute-based change (stable user selection) while keeping the support for outgoing picking types added later in the compute variant.action_move_locationthat copiesself.destination_location_idto any line lacking one before the picking is created, so a transfer no longer fails on a NOT NULL constraint when lines were built before the destination was set.Existing tests that instantiate the wizard via
create(...)keep working thanks to the default, and all flows that already setdestination_location_idon the lines via onchange are unaffected by the safeguard.Steps to reproduce
1. Picking type reset
2. Destination missing
IntegrityError: null value in column "location_dest_id" of relation "stock_move" violates not-null constraint.Changes
stock_move_location/wizard/stock_move_location.py:picking_type_idto a regular field withdefault=_get_default_picking_type_id(first internal or outgoing picking type).action_move_locationto filldestination_location_idon lines missing it.stock_move_location/tests/test_move_location.py:test_picking_type_preserved_on_origin_changeto assert the user's manual picking type is not overwritten when the origin location changes.test_destination_propagated_to_lines_without_destto assert the safeguard fills the destination on lines lacking one before creating the picking.