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.

0

how can difine a function field and its function?

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



0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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

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

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

nasim
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

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: 7/24/16, 5:30 AM
Seen: 279 times
Last updated: 7/24/16, 10:30 AM