Files
odoo_source/addons/purchase_stock
Touati Djamel (otd) 5968480dfa [FIX] stock: apply only quant with inventory quantity set
Steps to reproduce the bug:
- Create a storable product “P1”
- Create a purchase order with 3 unit of “P1”
- Confirm the PO and receive the delivery
- Go to inventory > operation > Inventory Adjustments
- Select the “quant” of “P1”:
    - quantity = 3
    - inventory_quantity = 0
- Click on “Apply”
- Apply the wizard

Problem:
The quantity is updated to 0

When the `_apply_inventory` function is called, a move is created and
validated to ensure that the quantity matches its corresponding
`inventory_quantity`:
https://github.com/odoo/odoo/blob/15.0/addons/stock/models/stock_quant.py#L606-L611

`inventory_diff_quantity` is equal to -3 in this case, since it's the
result of computing `inventory_quantity` - `quantity`, which is (0 - 3).
Since we add a minus sign to `inventory_diff_quantity`, the final result
becomes `3`.

Afterward, we call the `_update_available_quantity` function with a
minus sign as well, so the value becomes -3:
https://github.com/odoo/odoo/blob/e1cea2640fc064a56b0dba4f79e6b8a91a48b4fc/addons/stock/models/stock_move_line.py#L307

As a result, when we add `quant.quantity`, which is 3, the final result
becomes 0 (3 - 3):
https://github.com/odoo/odoo/blob/9d34c72b2c7bc187c5aac771e9e8cbddd7ead5f2/addons/stock/models/stock_quant.py#L635

Solution:
If no inventory_quantity set, ignore the apply of inventory for this
quant.

opw-3268542

closes odoo/odoo#119867

X-original-commit: 4bedeb514652f5f4a9fd8fa0914d07c8ccba3952
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
2023-04-27 07:06:15 +02:00
..
…