This question has been flagged
1 Reply
3101 Views

I want define a function that say:

forexample in project form (that has a field by name : "department_id") :

if field 'department_id' s manager s user_id  IS == with login user

so

a variable for example 'x' set to 'True'

else

'x' set to 'False'

-------------------------------------

my openerp version : 6.1  and use old api

I think that I have use a function field ( 'x' : fields.function(_compute_el , type='boolean'), )

and write a function.

but I don't know how?

--------------------------------------------my code is:

def _compute_el(self, cr, uid, ids , x , department_id, context=None):

  x = False

if department_id.manager_id.user_id == user.id:

  x = True

else:

  x = False

return {'value': {'x' : x}}


_columns = {

'x' : fields.function(_compute_el),

'department_id': fields.many2one('hr.department', 'Department'),

...... }


-------------------------------------------------

I write this: ( if department_id.manager_id.user_id == user.id: )

but does not work. error:

if department_id.manager_id.user_id == user.id:

AttributeError: 'NoneType' object has no attribute 'manager_id'


-----------------------Thanks



Avatar
Discard
Best Answer

Hello,

try to define the field as:

'is_dpt_manager': fields.function(_compute_el, string='Department Manager?'),

Then try to define the _compute_el as:


def _compute_el(self, cr, uid, ids, field_name, arg, context=None):
    res = {}
    for rec in self.browse(cr, uid, ids, context=context):
         if rec.department_id.manager_id.user_id == uid:
             res[rec.id] = True
         else:
             res[rec.id] = False
    return res


Hope this could helps

Avatar
Discard
Author

yes.thanks so much

but my now my problem is that I have error :

if rec.department_id.manager_id.user_id == uid:

AttributeError: 'NoneType' object has no attribute 'user_id'

I don't know why?! :(

plz help

I know each department in openerp has a manager and each manager has a user_id. so what is problem?!!

thanks

Hi, is there a manager defined for the chosen department ? to me this should works fine with just few checks. I've checked the code of HR 6.1 [https://github.com/odoo/odoo/blob/6.1/addons/hr/hr.py]