Skip to Content
Menu
This question has been flagged
2 Replies
4758 Views

hi,

I want to write name and department of user that push a button ,I write tender_approve function and to achieve user name i use 'uid ' ,but i don't  know what should use for department .can anyone help me? 

def tender_approve(self,cr,uid,ids,context = None):

    self.write(cr, uid, ids ,{'user' : uid ,'department' : ? })

return True


openerp v6

Avatar
Discard
Author Best Answer

hi,I solve my problem with below code   

def tender_approve(self, cr, uid, ids, context=None):

        self.write(cr, uid,ids,{'user' : uid})

         user = uid

        department= self.pool.get('res.users').browse(cr, uid,user, context=context).context_department_id.id

        self.write(cr, uid,ids,{'department' : department})

        return True


thanks

Avatar
Discard
Best Answer

Hi,

You can get the department only from the employee table, so what you have to do is that, search the hr.employee table and see for which employee this user is set as related user, then from that record you can get the department id.

employee = self.env['hr.employee'].search ([('user_id', '=', uid)], limit=1)

if employee: 

department= employee.department_id.id


You can change the search method according to your Odoo version.


Thanks

Avatar
Discard