[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) <nim@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user