[18.0][OU-FIX] stock: adapt location_final_id#5088
Conversation
|
see ForgeFlow#27 |
|
@MiquelRForgeFlow are you going to continue here or should I? |
|
I plan to continue |
24000f7 to
4fe8194
Compare
|
CI is green. |
5aae5c4 to
2d7b668
Compare
2d7b668 to
84c82d0
Compare
9a4554b to
7ab5ca0
Compare
7ab5ca0 to
fe0a5d6
Compare
|
Let's merge this, as the module was done already. If some error is detected in the future,we will fix it later. |
carlos-lopez-tecnativa
left a comment
There was a problem hiding this comment.
ping @MiquelRForgeFlow @hbrunn
| 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') | ||
| """, | ||
| ) |
There was a problem hiding this comment.
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.
Fresh database in v18
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.

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).
There was a problem hiding this comment.
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

Fixes
stock_move.location_final_id.