From 8e69a3cc73168f8b5c8856bc2b84bdc676a3e32f Mon Sep 17 00:00:00 2001 From: vava-odoo Date: Tue, 7 Nov 2023 12:18:40 +0100 Subject: [PATCH] [FIX] website_sale_stock: fix warning message if unavailable Before this commit, the warning to inform the user that a product has become unavailable was the same, whether the user was on the cart or on the product page. This commit makes sure that the message is adapted to the context. closes odoo/odoo#139332 Signed-off-by: Victor Feyens (vfe) --- .../i18n/website_sale_stock.pot | 7 +++++++ addons/website_sale_stock/models/sale_order.py | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/addons/website_sale_stock/i18n/website_sale_stock.pot b/addons/website_sale_stock/i18n/website_sale_stock.pot index b4918377c23..1a2410a8298 100644 --- a/addons/website_sale_stock/i18n/website_sale_stock.pot +++ b/addons/website_sale_stock/i18n/website_sale_stock.pot @@ -189,6 +189,13 @@ msgstr "" msgid "The following product is now available." msgstr "" +#. module: website_sale_stock +#. odoo-python +#: code:addons/website_sale_stock/models/sale_order.py:0 +#, python-format +msgid "The item has not been added to your cart since it is not available." +msgstr "" + #. module: website_sale_stock #. odoo-python #: code:addons/website_sale_stock/models/product_product.py:0 diff --git a/addons/website_sale_stock/models/sale_order.py b/addons/website_sale_stock/models/sale_order.py index 386fd599109..373433291ec 100644 --- a/addons/website_sale_stock/models/sale_order.py +++ b/addons/website_sale_stock/models/sale_order.py @@ -41,12 +41,21 @@ class SaleOrder(models.Model): order_line._set_shop_warning_stock(total_cart_qty, available_qty) else: self._set_shop_warning_stock(total_cart_qty, available_qty) + returned_warning = order_line.shop_warning or self.shop_warning else: # 0 or negative allowed_qty # if existing line: it will be deleted # if no existing line: no line will be created - self.shop_warning = _( - "Some products became unavailable and your cart has been updated. We're sorry for the inconvenience.") - return allowed_line_qty, order_line.shop_warning or self.shop_warning + if order_line: + self.shop_warning = _( + "Some products became unavailable and your cart has been updated. We're" + " sorry for the inconvenience." + ) + returned_warning = self.shop_warning + else: + returned_warning = _( + "The item has not been added to your cart since it is not available." + ) + return allowed_line_qty, returned_warning return super()._verify_updated_quantity(order_line, product_id, new_qty, **kwargs) def _get_cart_and_free_qty(self, product, line=None):