[FIX] website_sale_wishlist: allow deletion of wishlist item when not connected

Add controller to remove (archive) an item from the wishlist.
Rpc cannot be used because user can be public

Adding tour test

task-1834888
This commit closes #24135
This commit is contained in:
Valentin Löfberg
2018-04-11 20:54:55 +02:00
committed by Jeremy Kersten
parent 8b8815f44c
commit 80029cae36
6 changed files with 151 additions and 11 deletions
@@ -39,3 +39,8 @@ class WebsiteSaleWishlist(WebsiteSale):
return request.redirect("/shop")
return request.render("website_sale_wishlist.product_wishlist", dict(wishes=values))
@http.route(['/shop/wishlist/remove/<model("product.wishlist"):wish>'], type='json', auth="public", website=True)
def rm_from_wishlist(self, wish, **kw):
wish.active = False
return True
@@ -0,0 +1,130 @@
odoo.define('website_sale_wishlist.tour', function (require) {
'use strict';
var tour = require("web_tour.tour");
var base = require("web_editor.base");
tour.register('shop_wishlist', {
test: true,
url: '/shop',
wait_for: base.ready(),
},
[
{
content: "click on add to wishlist",
trigger: '.o_add_wishlist',
},
{
content: "go to wishlist",
extra_trigger: ".label:contains(1)",
trigger: 'a[href="/shop/wishlist"]',
},
{
content: "remove first item in whishlist",
trigger: 'a.o_wish_rm:first',
},
{
content: "go back to the store",
trigger: "a[href='/shop']"
},
{
content: "click on add to wishlist",
trigger: '.o_add_wishlist',
},
{
content: "check value of wishlist and go to login",
extra_trigger: ".my_wish_quantity:contains(1)",
trigger: 'a[href="/web/login"]',
},
{
content: "submit login",
trigger: ".oe_login_form",
run: function (){
$('.oe_login_form input[name="login"]').val("admin");
$('.oe_login_form input[name="password"]').val("admin");
$('.oe_login_form input[name="redirect"]').val("/shop");
$('.oe_login_form').submit();
},
},
{
content: "check that logged in and search for ipad",
extra_trigger: 'li span:contains(Administrator)',
trigger: 'form input[name="search"]',
run: "text ipad retina",
},
{
content: "submit search",
trigger: 'form:has(input[name="search"]) .oe_search_button',
},
{
content: "click on ipad",
trigger: '.oe_product_cart a:contains("iPad Retina Display")',
},
{
content: "select ipad 32GB",
extra_trigger: '#product_detail',
trigger: 'label:contains(32 GB) input',
},
{
content: "click on add to wishlist",
trigger: '#product_detail .o_add_wishlist_dyn',
},
{
content: "check that wishlist contains 2 items and go to wishlist",
extra_trigger: ".label:contains(2)",
trigger: 'a[href="/shop/wishlist"]',
},
{
content: "remove Ipad",
trigger: 'tr:contains("iPad Retina Display") a.o_wish_rm:first',
},
{
content: "check that wishlist contains 1 item",
trigger: ".my_wish_quantity:contains(1)",
run: function() {},
},
{
content: "check B2B wishlist mode",
trigger: "input#b2b_wish",
},
{
content: "add item to cart",
trigger: 'a.o_wish_add:first',
},
{
content: "check that cart contains 1 item",
trigger: ".my_cart_quantity:contains(1)",
run: function() {},
},
{
content: "check that wishlist contains 1 item",
trigger: ".my_wish_quantity:contains(1)",
run: function() {},
},
{
content: "remove B2B wishlist mode",
trigger: "input#b2b_wish",
},
{
content: "add last item to cart",
trigger: 'a.o_wish_add:first',
},
{
content: "check that user is redirect - wishlist is empty",
trigger: "h2:contains('Shopping Cart')",
run: function() {},
},
{
content: "check that cart contains 2 items",
trigger: ".my_cart_quantity:contains(2)",
run: function() {},
},
{
content: "check that wishlist is empty and no more visible",
trigger: ":not(:has(.my_wish_quantity:visible))",
run: function() {},
},
]
);
});
@@ -3,11 +3,9 @@ odoo.define('website_sale_wishlist.wishlist', function (require) {
require('web.dom_ready');
var ajax = require('web.ajax');
var rpc = require('web.rpc');
var Widget = require('web.Widget');
var base = require('web_editor.base');
var website_sale_utils = require('website_sale.utils');
var weContext = require('web_editor.context');
if(!$('.oe_website_sale').length) {
return $.Deferred().reject("DOM doesn't contain '.oe_website_sale'");
@@ -71,7 +69,7 @@ var ProductWishlist = Widget.extend({
});
},
add_new_products:function($el, e){
add_new_products: function($el, e){
var self = this;
var product_id = parseInt($el.data('product-product-id'), 10);
if (!product_id && e.currentTarget.classList.contains('o_add_wishlist_dyn')) {
@@ -112,14 +110,9 @@ var ProductWishlist = Widget.extend({
var product = tr.data('product-id');
var self = this;
rpc.query({
model: 'product.wishlist',
method: 'write',
args: [[wish], { active: false }, weContext.getExtra()],
})
.then(function(){
$(tr).hide();
});
ajax.jsonRpc('/shop/wishlist/remove/' + wish).done(function () {
$(tr).hide();
});
this.wishlist_product_ids = _.without(this.wishlist_product_ids, product);
if (this.wishlist_product_ids.length === 0) {
@@ -0,0 +1 @@
from . import test_wishlist_process
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import odoo.tests
@odoo.tests.common.at_install(False)
@odoo.tests.common.post_install(True)
class TestUi(odoo.tests.HttpCase):
def test_01_wishlist_tour(self):
self.phantom_js("/", "odoo.__DEBUG__.services['web_tour.tour'].run('shop_wishlist', 1000)", "odoo.__DEBUG__.services['web_tour.tour'].tours.shop_wishlist.ready")
@@ -5,6 +5,7 @@
<xpath expr="." position="inside">
<link type="text/less" rel='stylesheet' href='/website_sale_wishlist/static/src/less/website_sale_wishlist.less'/>
<script type="text/javascript" src="/website_sale_wishlist/static/src/js/website_sale_wishlist.js"></script>
<script type="text/javascript" src="/website_sale_wishlist/static/src/js/website_sale_tour_wishlist.js"></script>
</xpath>
</template>