From fb786296a5031d2259681bc862b48162f8673bd2 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 27 Oct 2020 13:14:06 +0000 Subject: [PATCH] [FIX] website_sale_stock: products in multiple warehouses - Create 2 warehouses A & B - In the website settings, set the `inventory_availability` as `always`, but do not set a warehouse - Create a Product P, make some stock in warehouse A - Create a Product Q, make some stock in warehouse B - Publish the products - Go to `/shop` => both products have availability - Add P in the cart => it works - Add Q in the cart Error: 'Some products became unavailable and your cart has been updated...'. This happens because the availability is checked on the warehouse of the SO, not the warehouse of the website (not set in this case). opw-2361768 closes odoo/odoo#60895 X-original-commit: 6b05fb2b21a3b58cfef3f280941d985eec158b78 Signed-off-by: Nicolas Martinelli (nim) --- addons/website_sale_stock/models/sale_order.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/website_sale_stock/models/sale_order.py b/addons/website_sale_stock/models/sale_order.py index 391ad44b4af..169f97cba60 100644 --- a/addons/website_sale_stock/models/sale_order.py +++ b/addons/website_sale_stock/models/sale_order.py @@ -17,8 +17,11 @@ class SaleOrder(models.Model): for line in self.order_line: if line.product_id.type == 'product' and line.product_id.inventory_availability in ['always', 'threshold']: cart_qty = sum(self.order_line.filtered(lambda p: p.product_id.id == line.product_id.id).mapped('product_uom_qty')) - if cart_qty > line.product_id.with_context(warehouse=self.warehouse_id.id).virtual_available and (line_id == line.id): - qty = line.product_id.with_context(warehouse=self.warehouse_id.id).virtual_available - cart_qty + # The quantity should be computed based on the warehouse of the website, not the + # warehouse of the SO. + website = self.env['website'].get_current_website() + if cart_qty > line.product_id.with_context(warehouse=website.warehouse_id.id).virtual_available and (line_id == line.id): + qty = line.product_id.with_context(warehouse=website.warehouse_id.id).virtual_available - cart_qty new_val = super(SaleOrder, self)._cart_update(line.product_id.id, line.id, qty, 0, **kwargs) values.update(new_val)