Skip to Content
Menu
This question has been flagged
12 Replies
6325 Views

Hello

Sorry for my poor english i'm french ;-)

So.. I would like to hide fields based on curent user login.

I have some 10 employee and 10 users associate.

- i want that all users can see the 10 employee data but exept one (or more) field for exemple the field "phone"

- I want just the users login can modifiy is own employee data

I don't know how to do!!!

i try to put the condition this condition on the field but it doesn't work!

{'invisible': [('user_id','!=','user_id')]}

How can i give the user login and compare it to the related user of the employee?


Avatar
Discard

i tried this but the result is : name 'uid' is not defined I'm on odoo 8, i think this work on openerp 6 but not now!!!!

I have a solution for you, let me write it

see my updated answer

The users can see all the fields of their own employee data? And they can see only limited fields of other employees, but can't modify. You need to have like this?

Best Answer

Jermoe,

You can do this by having a record rule for hr.employee object in which you can have domain like:
[('user_id','=',user.id)]

and remember to allow this rule for WRITE permission only(uncheck create/read/delete boxes)

and assign this to employee group.

Hope it helps!    

Avatar
Discard
Best Answer

You need to define a field function that return the uid of the user:

class test_x(osv.osv):
    _name = 'model_x'
    def _get_uid(self, cr, uid, ids, field_name, args, context=None):
        return dict([(idx, uid) for idx in ids])
    _columns = {
        'user_uid': fields.function(_get_uid, type='integer', string='User UID'),
    }
    _defaults = {
        'user_uid': lambda self, cr, uid, c: uid,
    }

Try like this:

<field name="user_uid" invisible="1"/>
<field name="field_x" attrs="{'invisible': [('user_id','!=',user_uid)]}"/>


Avatar
Discard
Author Best Answer

hello Axel

thank you, I think it's the good solution.

I try this, i create a new module but i have an error when i update my module list:

    'user_uid': fields.function(_get_uid, type='integer', string='User UID'),

    AttributeError: 'module' object has no attribute 'function'

Can you help me?


this is my hr_employee_cu.py

from openerp.osv import osv, fields

class HrEmployeeCu(osv.osv):

_inherit = 'hr.employee'

def _get_uid(self, cr, uid, ids, field_name, args, context=None):

return dict([(idx, uid) for idx in ids])

_columns = {

'user_uid': fields.function(_get_uid, type='integer', string='User UID'),

}

_defaults = {

'user_uid': lambda self, cr, uid, c: uid,

}


Hello Axel

Sorry but i don’t understand ?

What it fixed?

Avatar
Discard

It's fixed in your own answer

Author

you have modify my code directly in my code? Sorry but i don't see the difference! It's late in france my eye nor really open ;-)

let me put the changes in bold

Author

OK now the module installing whitout error but my field 'user_uid' doesn't create in database! from openerp import models, fields class HrEmployeeCu(models.Model): _inherit = 'hr.employee' user_uid = fields.Integer(string='User UID', compute='_get_uid') def _get_uid(self, cr, uid, ids, field_name, args, context=None): return dict([(idx, uid) for idx in ids]) _defaults = { 'user_uid': lambda self, cr, uid, c: uid, }

Best Answer

Best way is to use *Groups* for different users, then put on your field the following attribute (for example: Salesman group only sees this field): groups="sale.group_sale_salesman" You can refer to the *Security* documentation section to know how to create new group from *data.xml* and assign users to it.

Avatar
Discard