[FIX] website_sale_wishlist: manage warning in return value

Similar to https://github.com/odoo/odoo/blob/11.0/addons/website_sale/static/src/js/website_sale.js#L173

It is particulary interesing when website_sale_stock return warning.
Until now, the end user had no info about the failed add_to_cart
This commit is contained in:
Jeremy Kersten
2017-10-20 16:27:41 +02:00
parent f6c89de81e
commit e5ff47df58
3 changed files with 12 additions and 3 deletions
+2 -1
View File
@@ -400,9 +400,10 @@ class WebsiteSale(http.Controller):
return {}
value = order._cart_update(product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty)
if not order.cart_quantity:
request.website.sale_reset()
return {}
return value
order = request.website.sale_get_order()
value['cart_quantity'] = order.cart_quantity
@@ -25,9 +25,10 @@ class SaleOrder(models.Model):
# Make sure line still exists, it may have been deleted in super()_cartupdate because qty can be <= 0
if line.exists() and new_val['quantity']:
line.warning_stock = _('You ask for %s products but only %s is available') % (cart_qty, new_val['quantity'])
values['warning'] = line.warning_stock
else:
self.warning_stock = _("Some products became unavailable and your cart has been updated. We're sorry for the inconvenience.")
values['warning'] = self.warning_stock
return values
@api.multi
@@ -134,7 +134,14 @@ var ProductWishlist = Widget.extend({
});
add_to_cart.then(function(resp) {
$('.my_cart_quantity').text(resp.cart_quantity || '* 1');
if (resp.warning) {
if (! $('#data_warning').length) {
$('.wishlist-section').prepend('<div class="mt16 alert alert-danger alert-dismissable" role="alert" id="data_warning"></div>');
}
var cart_alert = $('.wishlist-section').parent().find('#data_warning');
cart_alert.html('<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> ' + resp.warning);
}
$('.my_cart_quantity').html(resp.cart_quantity || '<i class="fa fa-warning" /> ');
});
return add_to_cart;
},