diff options
| author | Jeremy Kersten <jke@odoo.com> | 2018-03-14 17:34:47 +0100 |
|---|---|---|
| committer | Jeremy Kersten <jke@odoo.com> | 2018-03-15 12:35:24 +0100 |
| commit | 1cd63d81908511ee136f0ca2600d85eab48f258f (patch) | |
| tree | 7fb0f90aa23fde083f3019f5b9c1bb0d8958c3f8 | |
| parent | 07a73ce27ff3d6c679db7666f01cf27908f22acd (diff) | |
[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.
| -rw-r--r-- | addons/website_sale/controllers/main.py | 13 | ||||
| -rw-r--r-- | addons/website_sale_options/static/src/js/website_sale.test.js | 33 |
2 files changed, 45 insertions, 1 deletions
diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index e2806a837a3..ffc4452e790 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -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 diff --git a/addons/website_sale_options/static/src/js/website_sale.test.js b/addons/website_sale_options/static/src/js/website_sale.test.js index 5d729ce78d9..050101338c6 100644 --- a/addons/website_sale_options/static/src/js/website_sale.test.js +++ b/addons/website_sale_options/static/src/js/website_sale.test.js @@ -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'", |
