Skip to content

Commit

Permalink
[FIX] website_sale: dont show variant option when not active
Browse files Browse the repository at this point in the history
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 odoo#23398

That means that a user that enable the view while the variants was enable,
need to disable the view before disable the variants.
  • Loading branch information
JKE-be committed Mar 15, 2018
1 parent 07a73ce commit 1cd63d8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
13 changes: 13 additions & 0 deletions addons/website_sale/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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__)
Expand Down Expand Up @@ -116,7 +117,19 @@ def website_form_saleorder(self, **kwargs):
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
Expand Down
33 changes: 32 additions & 1 deletion addons/website_sale_options/static/src/js/website_sale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down

0 comments on commit 1cd63d8

Please sign in to comment.