diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index c8a5de9e0b4..c63f2c5e242 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -126,6 +126,13 @@ class WebsiteSaleForm(WebsiteForm): class Website(main.Website): + + def _login_redirect(self, uid, redirect=None): + # If we are logging in, clear the current pricelist to be able to find + # the pricelist that corresponds to the user afterwards. + request.session.pop('website_sale_current_pl', None) + return super()._login_redirect(uid, redirect=redirect) + @http.route() def autocomplete(self, search_type=None, term=None, order=None, limit=5, max_nb_chars=999, options=None): options = options or {} diff --git a/addons/website_sale/static/tests/tours/website_sale_shop_pricelist_tour.js b/addons/website_sale/static/tests/tours/website_sale_shop_pricelist_tour.js new file mode 100644 index 00000000000..6b5c105be72 --- /dev/null +++ b/addons/website_sale/static/tests/tours/website_sale_shop_pricelist_tour.js @@ -0,0 +1,37 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; + +registry.category("web_tour.tours").add( + "website_sale.website_sale_shop_pricelist_tour", + { + test: true, + url: '/shop', + steps: [ + { + content: "Check pricelist", + trigger: ".o_pricelist_dropdown .dropdown-toggle:not(:contains('User Pricelist'))", + run: function() {} // Check + }, + { + content: "Go to login page", + trigger: ".nav-link:contains('Sign in')" + }, + { + content: "Submit login", + trigger: '.oe_login_form', + run: function () { + $('.oe_login_form input[name="login"]').val("toto"); + $('.oe_login_form input[name="password"]').val("long_enough_password"); + $('.oe_login_form input[name="redirect"]').val("/shop"); + $('.oe_login_form').submit(); + } + }, + { + content: "Check pricelist", + trigger: ".o_pricelist_dropdown .dropdown-toggle:contains('User Pricelist')", + run: function() {} // Check + }, + ] + } +); diff --git a/addons/website_sale/tests/test_website_sale_pricelist.py b/addons/website_sale/tests/test_website_sale_pricelist.py index 9a95da7e483..92aa3b50126 100644 --- a/addons/website_sale/tests/test_website_sale_pricelist.py +++ b/addons/website_sale/tests/test_website_sale_pricelist.py @@ -599,3 +599,36 @@ class TestWebsitePriceListMultiCompany(TransactionCaseWithUserDemo): # The test is here: while having access only to self.company2 records, # archive should not raise an error self.c2_pl.with_user(self.demo_user).with_context(allowed_company_ids=self.company2.ids).write({'active': False}) + +@tagged('post_install', '-at_install') +class TestWebsiteSaleSession(HttpCaseWithUserPortal): + + def test_update_pricelist_user_session(self): + """ + The objective is to verify that the pricelist + changes correctly according to the user. + """ + website = self.env.ref('website.default_website') + test_user = self.env['res.users'].create({ + 'name': 'Toto', + 'login': 'toto', + 'password': 'long_enough_password', + }) + user_pricelist, _ = self.env['product.pricelist'].create([ + { + 'name': 'User Pricelist', + 'website_id': website.id, + 'code': 'User_pricelist', + 'selectable': True, + 'sequence': 40, # Be sure not to use it by default + }, + { + 'name': 'Other Pricelist', + 'website_id': website.id, + 'code': 'Other_pricelist', + 'selectable': True, + 'sequence': 30, + } + ]) + test_user.partner_id.property_product_pricelist = user_pricelist + self.start_tour("/shop", 'website_sale.website_sale_shop_pricelist_tour', login="")