Skip to content
Permalink
Browse files

[FIX] website_sale: fix concurrent update on cart

shop page link and popover use the same route which make a write on db
to recompute coupon lines. Can lead to concurent updates if unlucky on
timing.

task-2070507
  • Loading branch information...
fja-odoo committed Sep 19, 2019
1 parent 50d404e commit ecb56fcf5fb611801e26a689576c6c2a1a369c94
Showing with 15 additions and 4 deletions.
  1. +15 −4 addons/website_sale/static/src/js/website_sale.js
@@ -7,6 +7,7 @@ odoo.define('website_sale.cart', function (require) {

var shopping_cart_link = $('ul#top_menu li a[href$="/shop/cart"]');
var shopping_cart_link_counter;
var popoverRpc;
shopping_cart_link.popover({
trigger: 'manual',
animation: true,
@@ -21,19 +22,19 @@ odoo.define('website_sale.cart', function (require) {
var self = this;
clearTimeout(shopping_cart_link_counter);
shopping_cart_link.not(self).popover('hide');
shopping_cart_link_counter = setTimeout(function(){
shopping_cart_link_counter = setTimeout(function() {
if($(self).is(':hover') && !$(".mycart-popover:visible").length)
{
$.get("/shop/cart", {'type': 'popover'})
popoverRpc = $.get("/shop/cart", {'type': 'popover'})
.then(function (data) {
$(self).data("bs.popover").options.content = data;
$(self).data("bs.popover").options.content = data;
$(self).popover("show");
$(".popover").on("mouseleave", function () {
$(self).trigger('mouseleave');
});
});
}
}, 100);
}, 300);
}).on("mouseleave", function () {
var self = this;
setTimeout(function () {
@@ -43,6 +44,16 @@ odoo.define('website_sale.cart', function (require) {
}
}
}, 1000);
}).on("click", function (ev) {
var target = ev.currentTarget;
if (!popoverRpc || popoverRpc.state() === 'resolved') {
return;
}
ev.preventDefault();
clearTimeout(shopping_cart_link_counter);
popoverRpc.then(function () {
window.location.href = target.href;
});
});
});

0 comments on commit ecb56fc

Please sign in to comment.
You can’t perform that action at this time.