Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to use groups policies in qweb templates?

By
Alejandro Santana
on 1/26/15, 1:51 PM 2,373 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.

1

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2993
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 1/26/15, 4:19 PM

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

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.

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 1/27/15, 6:22 PM

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.

Jérémy Kersten (jke)
on 1/28/15, 4:21 AM

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

Anubía, soluciones en la nube, S.L., Alejandro Santana
on 2/11/15, 12:43 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/26/15, 1:51 PM
Seen: 2373 times
Last updated: 7/14/15, 8:42 AM