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

onchange many2one field [Closed]

By
Susi
on 6/21/16, 12:08 AM 294 views

The Question has been closed for reason: not in english

by
Susi
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>

</xpath>


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

1

Ahmed M.Elmubarak

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


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

Hello,

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

Susi
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

Susi
on 6/21/16, 3:34 AM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/21/16, 12:08 AM
Seen: 294 times
Last updated: 6/21/16, 3:35 AM