Skip to Content
Menu
This question has been flagged
1 Reply
17465 Views

When extending a qweb template in v8, is it possible to add the groups policies to elements as in views*? How?
(*) Adding groups="my_module.my_security_group"

I have tried to hide the im_chat button at the top and show it only to some managers group, but it doesn't work as expected and has no result. The code:

<?xml version="1.0" encoding="UTF-8"?>

<templates xml:space="preserve">
<t t-extend="im_chat.ImTopButton">
    <t t-jquery="li" t-operation="replace">
        <li t-att-title='_t("Display Instant Messaging")' groups="my_module.group_my_module_manager">
            <a href="#">
                  <i id="oe_topbar_imbutton_icon" class="fa fa-comments-o"/>
            </a>
        </li>
    </t>
</t>
</templates>

I have also tried to specify the groups policy through t-field-options, with no luck.

<li t-att-title='_t("Display Instant Messaging")' t-field-options='{"groups": "crm_ticket_platforms.group_crm_ticket_platforms_manager"}'>

UPDATE:

Reading more, I have tried using tag "t-att-groups", as explained in official documentation (a-att-$name), but without result. As that expression is documented and supposed to work, I have opened an issue in Github: https://github.com/odoo/odoo/issues/5058 

Let's see how it ends.

 

UPDATE 2:

With some comments on issue https://github.com/odoo/odoo/issues/5058 it is clear I was missunderstanding the purpose of qweb t-att-$name attributes. It is intended for html attributes only (width, href, etc.), not for Odoo meta-data as group security policy.

It is stated I could use t-if, but haven't tested it yet. It surely uses some akward domain, as usual.

Avatar
Discard
Best Answer

Hello,

I'm not sure that  you can use groups in Qweb js.

Why not use the same code that in im_chat.js

    if (openerp.web && openerp.web.Model) {
        // Put the ImTopButton widget in the systray menu if the user is an employee
        var Users = new openerp.web.Model('res.users');
        Users.call('has_group', ['base.group_user']).done(function(is_employee) {
            if (is_employee) {
                openerp.web.SystrayItems.push(openerp.im_chat.ImTopButton);
            }
        });
    }

Good luck

Avatar
Discard
Author

Aaaaahhh... I just don't know a bit of javascript (yet). Is there any documentation on how to extend/override that in Odoo? I could change the group there, but I don't know how to use inheritance in Odoo js.

You can find a tuto here : https://www.odoo.com/documentation/8.0/howtos/web.html And Js documentation here : https://www.odoo.com/documentation/8.0/reference/javascript.html The simple way for you (not the more elegant way), will be to remove the button if not respected your conditions. The code from previous Answer is from master, take a look in im_chat from version 8.

Author

I finally solved it as explained here: https://www.odoo.com/es_ES/forum/help-1/question/how-to-override-js-code-in-odoo-75335

Related Posts Replies Views Activity
0
May 16
4786
2
Jul 15
6698
2
Mar 15
20905
1
Jun 21
7934
1
Oct 18
6086