[FIX] website_sale: clear old pricelist in the session
On the ecommerce, we want the pricelist to be adapted to the user who is connected. If no user is logged in, the 'Public Pricelist' is used. To determine the pricelist that will be used (by default): https://github.com/odoo/odoo/blob/a3169ede4f609b56c83da04756d20b1c7a07251f/addons/website_sale/controllers/main.py#L350-L354 Therefore, if we have been to the shop as a 'Public user' and we decide to log in, we already have a pricelist in `request.session.get('website_sale_current_pl')`. So we have to clear the pricelist when we connect to determine the new pricelist of the user. opw-3228998 closes odoo/odoo#121074 X-original-commit: 71b2d817df93f0cc8c1f5c424a3555bcadf33b2d Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
This commit is contained in:
@@ -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 {}
|
||||
|
||||
@@ -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
|
||||
},
|
||||
]
|
||||
}
|
||||
);
|
||||
@@ -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="")
|
||||
|
||||
Reference in New Issue
Block a user