odoo/odoo#222034
Created by Mohammadmahdi Alijani (malj)
Statuses:
- legal/cla: Contributor License Agreement check
- ci/runbot: Odoo Test Suite
- ci/upgrade_enterprise: Test upgrades for enterprise master
- ci/template: Contact runbot team on discord for help.
- ci/style: Optional style check. Ignore it only if strictly necessary.
- ci/security: Required security check. Can only be ignored by security team.
- ci/documentation: (runtime 694s)
- label
- odoo-dev:17.0-opw-4964561-fix_move_picked_after_package_undone-malj
- head
- 638d89fae5ccb28d24bff282e009c8a052e96b8a
- merged
- 8 months ago by Logistics, William Henrotin (whe)
| odoo/odoo | |
|---|---|
| 18.0 | #222034 |
| saas-18.2 | #230281 |
| saas-18.3 | #230317 |
| saas-18.4 | #230347 |
| 19.0 | #230374 |
[FIX] stock: move picked not being updated after package undone
Issue:
To reproduce the bug:
1. Activate Packages settings in Inventory:
2. Activate Move entire packages on picking type delivery orders
3. Create new product Test move package
4. Update quantity in WH/Stock with a newly created package and a qty (eg 5)
5. Go to the delivery orders and create a new picking with the created product and a quantity of 5
6. Click on Mark as Todo, the picking is set as ready and a package level is created automatically to move the quantity we did put in stock in the package.
7. Mark the checkbox Done on the package level (this will mark the move line and the move as picked)
8. Unmark the checkbox Done on the package level.
The package level is deleted, as well as the stock move line,
but the stock move still has the checkbox picked that is
marked.
The picking is then in waiting state and we cannot check
availability again.
Currently to be able to check the availability, the picked
check should be undone manually.
Cause of issue
Currently, in _compute_picked in stock_move, we don't
update value of move.picked if there is no move_line_ids
present which is wrong.
Fix:
In the fix, picked is set to False when there no
move_line_ids
Issue 2
This fix cause another issue, in which the move loses its picked status after manually setting the done quantity when no stock was initially available,
Cause of issue 2
To be more specific this fix on _compute_picked
- elif move.move_line_ids:
move.picked = False
+ else:
move.picked = False
has the following side effect:
- On a confirmed picking, pick a move with a quantity of 0 then change the quantity to 10 the move is unpicked -> undesirable.
After you picked the move, when you set the quantity, you will set move_line_ids on your move to match the quantity increase here:
https://github.com/odoo/odoo/blob/57c0ce5f0af9b46c037759d85205bc3e88890af7/addons/stock/models/stock_move.py#L2157-L2165
However,self._set_quantity_done_prepare_vals(qty) does not return a stock.move.line record set but a Command.create whose values do not contain any info on the picked value of the move line:
https://github.com/odoo/odoo/blob/57c0ce5f0af9b46c037759d85205bc3e88890af7/addons/stock/models/stock_move.py#L1497-L1507
The fact that the move_line_ids is set on the move to this command.create, flags the picked field of the stock move to dirty and adds it to the field to recompute because of the dependency move_line_ids.state:
https://github.com/odoo/odoo/blob/57c0ce5f0af9b46c037759d85205bc3e88890af7/addons/stock/models/stock_move.py#L208-L209
https://github.com/odoo/odoo/blob/57c0ce5f0af9b46c037759d85205bc3e88890af7/odoo/api.py#L795-L800
THEN, the creation of the move.line happends and since the value of the picked was not set in the command.create, we populate it based on the picked value of the move:
https://github.com/odoo/odoo/blob/57c0ce5f0af9b46c037759d85205bc3e88890af7/addons/stock/models/stock_move_line.py#L347-L348
However, at this point since the picked value of the move has been flagged as dirty it is recomputed using the compute_method modified in our fix.
And since the move does not have any move line at this stage, it is computed to be picked = False resetting the picked value.
Fix of Issue 2:
We should set the picked values in the vals here:
https://github.com/odoo/odoo/blob/57c0ce5f0af9b46c037759d85205bc3e88890af7/addons/stock/models/stock_move.py#L1497-L1507
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr