Skip to content

[18.0][OU-FIX] stock: adapt location_final_id#5088

Merged
MiquelRForgeFlow merged 4 commits into
OCA:18.0from
ForgeFlow:18.0-fix-stock
Jun 20, 2025
Merged

[18.0][OU-FIX] stock: adapt location_final_id#5088
MiquelRForgeFlow merged 4 commits into
OCA:18.0from
ForgeFlow:18.0-fix-stock

Conversation

@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor

Fixes stock_move.location_final_id.

@MiquelRForgeFlow MiquelRForgeFlow added this to the 18.0 milestone Jun 2, 2025
@MiquelRForgeFlow MiquelRForgeFlow mentioned this pull request Jun 2, 2025
1 task
@MiquelRForgeFlow MiquelRForgeFlow requested a review from hbrunn June 2, 2025 15:23
@hbrunn

hbrunn commented Jun 9, 2025

Copy link
Copy Markdown
Member

see ForgeFlow#27

@hbrunn

hbrunn commented Jun 16, 2025

Copy link
Copy Markdown
Member

@MiquelRForgeFlow are you going to continue here or should I?

@MiquelRForgeFlow

MiquelRForgeFlow commented Jun 16, 2025

Copy link
Copy Markdown
Contributor Author

I plan to continue when finishing point_of_sale, but feel free to continue it if you want.

@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 18.0-fix-stock branch 4 times, most recently from 24000f7 to 4fe8194 Compare June 16, 2025 16:25
@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor Author

CI is green.

Comment thread openupgrade_scripts/scripts/stock/18.0.1.1/pre-migration.py Outdated
Comment thread openupgrade_scripts/scripts/stock/tests/test_migration.py Outdated
@MiquelRForgeFlow MiquelRForgeFlow force-pushed the 18.0-fix-stock branch 3 times, most recently from 5aae5c4 to 2d7b668 Compare June 17, 2025 10:11
@MiquelRForgeFlow

Copy link
Copy Markdown
Contributor Author

Let's merge this, as the module was done already. If some error is detected in the future,we will fix it later.

@MiquelRForgeFlow MiquelRForgeFlow merged commit ce9ae79 into OCA:18.0 Jun 20, 2025
4 checks passed
@MiquelRForgeFlow MiquelRForgeFlow deleted the 18.0-fix-stock branch June 20, 2025 09:43

@carlos-lopez-tecnativa carlos-lopez-tecnativa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +58 to +75
WITH RECURSIVE sub AS (
(SELECT rel.move_orig_id, rel.move_dest_id
FROM stock_move_move_rel rel
LEFT JOIN stock_move_move_rel rel2 ON rel.move_dest_id = rel2.move_orig_id
WHERE rel2.move_orig_id IS NULL)
UNION
(SELECT rel.move_orig_id, sub.move_dest_id
FROM stock_move_move_rel rel
JOIN sub ON sub.move_orig_id = rel.move_dest_id)
)
UPDATE stock_move sm2
SET location_final_id = sm.location_final_id
FROM stock_rule sr, stock_move sm
JOIN sub ON sub.move_dest_id = sm.id
WHERE sm2.rule_id = sr.id AND sub.move_orig_id = sm2.id
AND sr.action IN ('push', 'pull_push')
""",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I have a case where a database from v17 was migrated to v18.

The stock.rule records are marked with location_dest_from_rule=True, but I don’t understand why this is done. Could you please explain the reason? I see that when Odoo creates a new database and generates the warehouse routes, this field is not marked as True.

I imagine this should only be applied when the warehouse is configured to use more than one delivery step. However, if you create a delivery and then return it, the moves are related through move_origin_ids and move_dest_ids, so this SQL query returns values even though the warehouse uses a single-step delivery flow.

Database migrated from v17
Image

Fresh database in v18

Image

What is the problem with location_dest_from_rule=True?

For example, when I install the purchase_sale_stock_inter_company module and create a purchase from C1 to C2:

When reviewing the delivery in C2, the stock.picking becomes Stock -> Customer, but the stock.move is Stock -> Intercompany Location.
If you perform the same test in a fresh database, or set location_dest_from_rule=False, the stock.picking becomes Stock -> Intercompany Location, and the stock.move uses the same locations.
Image

This inconsistency between the locations in stock.picking and stock.move causes problems, for example with the stock_barcodes module, which expects both records to have the same location. When you scan a product, instead of modifying the current line, it tries to create a new stock.move.

Please explain the reason for setting this field to True based on stock_move_move_rel. I think a better approach would be to set it to True only when the warehouse uses two- or three-step routes (although Odoo itself does not set this field in those cases either).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my intention was to keep previous behavior (as that was my analysis of this flag at the time) in cases where it's used. If that doesn't work for you, that's a problem indeed.

Please provide a PR for adding v18 test data + a v19 test that fails with the current code, then we can discuss there how to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants