Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] stock: try to reassign stolen transfer #164606

Open
wants to merge 3 commits into
base: 15.0
Choose a base branch
from

Conversation

amoyaux
Copy link
Contributor

@amoyaux amoyaux commented May 6, 2024

Sometimes people do internal transfer to move a package inside a sub location.
Use case:

  • Enable multi locations + packages
  • Create a product and put 1 unit in stock with a package PACK1
  • Do a delivery (planned transfer) for this product
  • Create an internal transfer and move the package from WH/stock to WH/stock/shelf1

It's due to _free_reservation method. During the internal transfer the product is not free for usage but it exists in inventory. So it will remove the reservation from delivery and move it to the new location (+ recompute the state of reservation).

However the destination location of the internal transfer could still under the delivery's source location (and could keep the reservation). We improve it by keeping in memory the move that were unreserve and we try to reverve them again after moving stuff in the internal picking

WIP still need to manage it for write and create method of sml

Description of the issue/feature this PR addresses:

Current behavior before PR:

Desired behavior after PR is merged:


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented May 6, 2024

Pull request status dashboard.

@C3POdoo C3POdoo requested a review from a team May 6, 2024 15:49
@C3POdoo C3POdoo added the RD research & development, internal work label May 6, 2024
@amoyaux amoyaux force-pushed the 15.0-fix-stolen-reservation-arm branch from ffff138 to 7abf4a7 Compare May 7, 2024 14:31
Sometimes people do internal transfer to move a package inside a
sub location.
Use case:
- Enable multi locations + packages
- Create a product and put 1 unit in stock with a package PACK1
- Do a delivery (planned transfer) for this product
- Create an internal transfer and move the package from WH/stock to
  WH/stock/shelf1

It's due to `_free_reservation` method. During the internal transfer
the product is not free for usage but it exists in inventory. So it
will remove the reservation from delivery and move it to the new
location (+ recompute the state of reservation).

However the destination location of the internal transfer could still
under the delivery's source location (and could keep the reservation).
We improve it by keeping in memory the move that were unreserve and
we try to reverve them again after moving stuff in the internal picking

WIP still need to manage it for write and create method of sml
@amoyaux amoyaux force-pushed the 15.0-fix-stolen-reservation-arm branch from 7abf4a7 to 9eb033a Compare May 7, 2024 16:26
Comment on lines 269 to 271
move = self.env['stock.move'].browse(vals['move_id'])
vals['picking_id'] = move.picking_id.id
vals['company_id'] = move.company_id.id
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is not related to the issue but when you create a stock.move.line with a move but not the picking. The stock.move.line and the stock.picking are not linked and it could result in strange error when doing picking.move_line_ids

Copy link
Contributor

Choose a reason for hiding this comment

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

seems like this part could be part of the valid sml data commit

Usecase:
- Create a product with one unit available in WH/Shelf1
- Do an internal transfer for this product from WH/Shelf1 to WH/Shelf2
- Do a delivery and reserve
- Go back on the internal transfer and unlock
- Modify the location_dest from Shelf2 to Shelf1

Current behavior:
The delivery still reserve the piece in Shelf2 and the quant has 1unit
reserve but no stock

Expected behavior:
The delivery has the reservation to Shelf1 and only one quant exist in
Shelf1
@amoyaux amoyaux force-pushed the 15.0-fix-stolen-reservation-arm branch from 9a2b848 to 1c971e4 Compare May 8, 2024 11:18
It's possible to create a `stock.move.line` with both
keys `picking_id` and `move_id` set but with a move not
in the picking. It results in an inconcistent state
@amoyaux amoyaux force-pushed the 15.0-fix-stolen-reservation-arm branch from bab08a5 to 214de21 Compare May 8, 2024 16:42
Copy link
Contributor

@ticodoo ticodoo left a comment

Choose a reason for hiding this comment

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

A couple of nitpicks and I found a couple of potential bad flows with this change: https://drive.google.com/file/d/1zp9GvWmBOf-oUQzlMvTvZzT4eU9X3scy/view?usp=sharing

But otherwise it seems fine to me

Comment on lines +765 to +769
moves_stolen = self.env['stock.move']
if stolen_move_ids:
moves_stolen = self.env['stock.move'].browse(stolen_move_ids)
moves_stolen._recompute_state()
return moves_stolen
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick

Suggested change
moves_stolen = self.env['stock.move']
if stolen_move_ids:
moves_stolen = self.env['stock.move'].browse(stolen_move_ids)
moves_stolen._recompute_state()
return moves_stolen
stolen_moves = self.env['stock.move']
if stolen_move_ids:
stolen_moves = self.env['stock.move'].browse(stolen_move_ids)
stolen_moves._recompute_state()
return stolen_moves

@@ -971,7 +971,6 @@ def button_validate(self):
for picking in self:
if not picking.move_lines and not picking.move_line_ids:
pickings_without_moves |= picking

Copy link
Contributor

Choose a reason for hiding this comment

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

whoopsies (unnecessary diff)

Comment on lines +268 to +269
move = self.env['stock.move'].browse(vals['move_id'])
picking = self.env['stock.picking'].browse(vals['picking_id'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
move = self.env['stock.move'].browse(vals['move_id'])
picking = self.env['stock.picking'].browse(vals['picking_id'])
move = self.env['stock.move'].browse(vals['move_id']) if vals.get('move_id') else False
picking = self.env['stock.picking'].browse(vals['picking_id']) if vals.get('picking_id') else False

Comment on lines 269 to 271
move = self.env['stock.move'].browse(vals['move_id'])
vals['picking_id'] = move.picking_id.id
vals['company_id'] = move.company_id.id
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like this part could be part of the valid sml data commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RD research & development, internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants