Odoo Help


on_change doesnt get id of many2one field

on 3/11/14, 2:48 PM 2,242 views

Hello, I am trying to create an on_change method that uses an id of a many2one field. When I change the value of the many2one field, it doesnt pass in the id as the parameter like i need it to. Here is an example of my code

def on_change_sql_min_max_ver(self, cr, uid, prod_ver_id, context=None):
    sql_ver_dictionary = {}
    prod_ver_rec = self.pool.get('product.version').browse(cr, uid, prod_ver_id)
    sql_ver_dictionary['sql_min_ver'] = prod_ver_rec.sql_min_ver
    sql_ver_dictionary['sql_max_ver'] = prod_ver_rec.sql_max_ver
    return {'value': sql_ver_dictionary }

Here is the xml field

<field name="product_version_id" on_change="on_change_sql_min_max_ver(product_version_id)"/>

Does anyone know why the Id wouldnt be passed in when I change the many2one field? When I run this code this is the error that I see, and I know its because the Id is not being passed in

Client Traceback (most recent call last): File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\http.py", line 204, in dispatch File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\controllers\main.py", line 1128, in call_kw File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\controllers\main.py", line 1120, in _call_kw File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\session.py", line 42, in proxy File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\session.py", line 30, in proxy_method File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\session.py", line 103, in send

Server Traceback (most recent call last): File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\web\session.py", line 89, in send File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\netsvc.py", line 292, in dispatch_rpc File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\service\web_services.py", line 626, in dispatch File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 188, in execute_kw File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 131, in wrapper File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 197, in execute File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server.\openerp\osv\osv.py", line 185, in execute_cr File "C:\Program Files (x86)\OpenERP 7.0-20130722-231026\Server\server\openerp\addons\sale_custom\sale_custom.py", line 44, in on_change_sql_min_max_ver AttributeError: 'browse_record_list' object has no attribute 'sql_min_ver'


Sudhir Arya (SA)

--Sudhir Arya (SA)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow




Sudhir Arya (SA)
On 3/13/14, 12:40 PM

Your method syntax is wrong. You need to add ids parameter in your method.

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

ids contains list of ids if your record exist in database (It is saved and you are updating the field), if you are creating a new record then ids will contains blank list.

Thank you so much. You have answered a few of my questions, all of which have been correct. I appreciate your help!

on 3/13/14, 1:18 PM
On 3/13/14, 12:26 PM

Try adding an "ids" parameter in your function definition:

def on_change_sql_min_max_ver(self, cr, uid, prod_ver_id, context=None):


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

Thank you so much. That worked.

on 3/13/14, 1:17 PM

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

0 follower(s)


Asked: 3/11/14, 2:48 PM
Seen: 2242 times
Last updated: 3/16/15, 8:10 AM