Odoo Help


how can difine a function field and its function?

on 7/24/16, 5:30 AM 720 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


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


'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


  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'


--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 7/24/16, 8:19 AM


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
             res[rec.id] = False
    return res

Hope this could helps

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?!!


on 7/24/16, 10:12 AM

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]

Ahmed M.Elmubarak
on 7/26/16, 2:34 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 7/24/16, 5:30 AM
Seen: 720 times
Last updated: 7/24/16, 10:30 AM