Community mailing list archives

Re: Accessing user from qweb template in view

Naresh Soni
- 03/20/2015 09:26:29
Hi Torvald,

You can do it like this:

add one field in your model
check_group_xxxx = fields.Boolean(compute='check_check_group_xxxx', string='Group available')

in the function:
 def check_check_group_xxxx(self):
      self.check_group_xxxx = self.env['res.users'].has_group('group id')

then in the view use like this:

<field name="check_group_xxxx" invisible="1"/> 
<field name="FIELD NAME" attrs="{ 'readonly': [('check_group_xxxx', '=', False)]}" />

I think this should help you !


On 20 March 2015 at 17:18, Torvald Baade Bringsvor <> wrote:

I'm trying to solve the following:

A field should be editable for members of one group only, it should be read only for everyone else.

Using the group attribute in the field tag in the view doesn't work since we need to display the field for the users who are not members.
So I tried adding a little qweb template to the view to be able to do a t-if on the group membership if the users, but I can't find anywhere in the docs what kind of data you have available when you are in a regular view (not a website view).

Can anyone shed some light on this? Or is there some way to resolve this in plain XML view lingo?


Torvald Baade Bringsvor
Bringsvor Consulting AS - Odoo (formerly OpenERP) implementation partner

Post to:

Naresh Soni
ODOO(Formerly OpenERP) Support & OPW(Team Leader),
TinyERP Pvt. Ltd. 
16 & 17 IT Tower - I
Infocity Gandhinagar, 
Gujarat, 382009, India