Odoo Help


onchange many2one field [Closed]

on 6/21/16, 12:08 AM 912 views

The Question has been closed for reason: not in english

on 06/21/2016 03:35:26

hi all

in my form Approval Timesheet

i have field 'account_id': many2one

and field 'approver':many2one

i want when i fill 'account_id' its onchange to 'approver

approver can be filled in other object 'project.project'

if  'account_analytic_id' == 'user_id'

i have use this code

def onchange_approver(self, cr, uid, ids, account_id):

    pm = self.pool.get('project.project').search(cr, uid, [('analytic_account_id','=','user_id')])

    if account_id:

        return {'value':{ 'approver':pm}}

and xml

<xpath expr="//field[@name='account_id']" position="attributes">

        <attribute name="on_change">onchange_approver(account_id)</attribute>


but nothing has changed.. anyone can help me please :)

--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 6/21/16, 2:59 AM


most probably this is because the return of the search function ...

Since you need search for one record that will meet your search query you can modify your search query to be something as:

 pm = self.pool.get('project.project').search(cr, uid, [('analytic_account_id','=','user_id')], limit=1)
 pm = pm and pm[0] or False

Btw: where the user_id comes from ?

hope this could helps

user_id come from object project.project. I want to fill the field of 'approver' from the 'user_id' field in project.project if when I select the contents of the fields account_id. thanks before

on 6/21/16, 3:05 AM

i already succes using code def onchange_approver(self, cr, uid, ids, account_id, context=None):

account = self.pool.get('account.analytic.account')

if not account_id:

return {'value': {

'approver': False,


name = account.browse(cr, uid, account_id, context=context)

return {'value': {

'approver': name.manager_id.id,

}} .

thanks before

on 6/21/16, 3: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: 6/21/16, 12:08 AM
Seen: 912 times
Last updated: 6/21/16, 3:35 AM