[FIX] website_sale: dont show variant option when not active
Before this commit, a user that ccick 'Customize' on th eproduct page see the 'List View of Variants' aven if option 'Variants' in settings was disabled. Now we hide this view if the group for variants is not enabled in the settings. This commit closes #23398 That means that a user that enable the view while the variants was enable, need to disable the view before disable the variants.
This commit is contained in:
@@ -10,6 +10,7 @@ from odoo.addons.base.ir.ir_qweb.fields import nl2br
|
||||
from odoo.addons.http_routing.models.ir_http import slug
|
||||
from odoo.addons.website.controllers.main import QueryURL
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons.website.controllers.main import Website
|
||||
from odoo.addons.website_form.controllers.main import WebsiteForm
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
@@ -116,7 +117,19 @@ class WebsiteSaleForm(WebsiteForm):
|
||||
return json.dumps({'id': order.id})
|
||||
|
||||
|
||||
class Website(Website):
|
||||
@http.route()
|
||||
def get_switchable_related_views(self, key):
|
||||
views = super(Website, self).get_switchable_related_views(key)
|
||||
if key == 'website_sale.product':
|
||||
if not request.env.user.has_group('product.group_product_variant'):
|
||||
view_product_variants = request.env.ref('website_sale.product_variants')
|
||||
views[:] = [v for v in views if v['id'] != view_product_variants.id]
|
||||
return views
|
||||
|
||||
|
||||
class WebsiteSale(http.Controller):
|
||||
|
||||
def _get_compute_currency_and_context(self):
|
||||
pricelist_context = dict(request.env.context)
|
||||
pricelist = False
|
||||
|
||||
@@ -47,8 +47,39 @@ tour.register('shop_customize', {
|
||||
},
|
||||
{
|
||||
content: "open customize menu",
|
||||
trigger: '#customize-menu > a',
|
||||
trigger: '#customize-menu',
|
||||
extra_trigger: "#product_detail",
|
||||
run: function() {
|
||||
// ENABLE VARIANT GROUP
|
||||
$('body').addClass('notReady');
|
||||
var ajax = odoo.__DEBUG__.services['web.ajax'];
|
||||
var get_group_payload = {
|
||||
model: 'ir.model.data',
|
||||
method: 'xmlid_to_res_id',
|
||||
args: ['product.group_product_variant', false],
|
||||
kwargs: {}
|
||||
};
|
||||
ajax.jsonpRpc('/web/dataset/call_kw', 'call', get_group_payload).then(function(group_id) {
|
||||
ajax.jsonpRpc('/web/dataset/call_kw', 'call', {
|
||||
model: 'res.groups',
|
||||
method: 'write',
|
||||
args: [group_id, {'users': [[4, 1]]}],
|
||||
kwargs: {}
|
||||
}).then(function() {
|
||||
location.reload(true);
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
content: "open customize menu",
|
||||
trigger: '#customize-menu > a',
|
||||
extra_trigger: 'body:not(.notReady)',
|
||||
},
|
||||
{
|
||||
content: "check page loaded after enable variant group",
|
||||
trigger: '#customize-menu a:contains(List View of Variants)',
|
||||
run: function () {}, // it's a check
|
||||
},
|
||||
{
|
||||
content: "click on 'List View of Variants'",
|
||||
|
||||
Reference in New Issue
Block a user