Skip to content
Snippets Groups Projects
Commit 2beb6b1b authored by Adrien Widart's avatar Adrien Widart
Browse files

[FIX] website_sale_stock: include WH in SO's context

In a multi-warehouses environment, editing the quantities of the cart
products can lead to incorrect behaviors.

To reproduce the issue:
(Let WH01 be the default company's warehouse)
1. Create a second warehouse WH02
2. In Settings > Website > Products:
    - Inventory > Warehouse: WH01
3. Create a product P:
    - Type: Storable
    - Availability: Show inventory on website and prevent sales if not
enough stock
    - Available on eShop
4. Update P's quantity:
    - Location: WH01/Stock, Qty: 10
5. Create a sale order SO:
    - Lines:
        - 100 x P
    - Warehouse: WH02
6. Confirm SO
7. Go on eShop
8. Add P to the cart
9. On cart page, increase the quantity of P

Error: The quantity becomes -90 (then the product is automatically
removed from the cart)

The quantity maximum that the user can select is defined thanks to:
https://github.com/odoo/odoo/blob/8d2fd05382705d4b3987ebac4c842d8507ede9cf/addons/website_sale_stock/views/website_sale_stock_templates.xml#L12

When computing all the quantities (in `_compute_quantities_dict`), if
there isn't any warehouse in the context, the quantities will be
calculated on the basis of all warehouses:
https://github.com/odoo/odoo/blob/48698838dd47442145395d3d4396b64b6901dba1/addons/stock/models/product.py#L238-L248


As a result, in the above case, `virtual_available` will be equal to
`10 - 100 = -90`. However, a SO is linked to a specific warehouse, so
the computations should be based on this warehouse. That way,
`virtual_available` will be 10 and, when editing the quantities in the
cart, the maximum value will be correctly computed.

OPW-2667470

closes odoo/odoo#78823

Signed-off-by: default avatarRomain Derie (rde) <rde@odoo.com>
parent b8201b7a
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment