Odoo Help


Autofill gives ID number not the field value?

Uppili Arivukkannu
on 7/23/16, 11:06 AM 1,025 views

I have many2one fields in one class. I have to auto fill this fields. I have written an on change function to auto fill. But the auto filled value are ID since it is a many2one field. How can I get the value in the many2one field.

First class:

class vansdent(osv.osv):

_name = "vans.dent"

_description = "Vans Dent"

_rec_name = 'service'

_description = "Vals Dent"

_columns = {

'year': fields.many2one('dent.year', 'Year', required=True, select=True),

'make': fields.many2one('vals.make','Make', required=True),

'model': fields.many2one('car.model','Model', required=True, select=True),

'service': fields.char('Service ID', required=True),

'customer': fields.char('Customer', required=True),


Second class:

class vansdent_bill(osv.osv):

_name = "vansdent.bill"

_description = "Vans Dent"

_columns = {

'name': fields.char('Year', required=True),

'make': fields.char('Make', required=True),

'model': fields.char('Model', required=True),

'customer': fields.char('Customer', required=True),

'serviceid': fields.many2one('vans.dent', 'Service ID', select=True),


Onchange function:

def vansdent_service(self, cr, uid, ids, serviceid=False, context=None):

res = {}

if serviceid:

service_obj = self.pool.get('vans.dent')

rec = service_obj.browse(cr, uid, serviceid)

res = {'value': {'name': rec.year, 'model': rec.model, 'make': rec.make, 'customer':rec.customer}}


res = {'value': {'name': False, 'model': False, 'make': False, 'customer': False}}

return res


<field name="serviceid" on_change="vansdent_service(serviceid)"/>

The auto fill value is filled with




How can I solve this?

I see in table that in many2one field the value is saved as ID number not as values. How can I save the many2one value as the value shown in UI and not as ID number in table

Uppili Arivukkannu
on 7/23/16, 11:39 AM
On 7/23/16, 9:27 PM

I see the "year", "make", "model" in "vans.dent" are many2one fields, so I think you could change this

from: res = {'value': {'name': rec.year, 'model': rec.model, 'make': rec.make, 'customer':rec.customer}}

to: res = {'value': {'name': rec.year.name, 'model': rec.model.name, 'make': rec.make.name, 'customer':rec.customer}}

(rec.year.name, ....)

and in 'dent.year', 'vals.make', 'car.model' we have to have a filed named `name`

hope it helps

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: 7/23/16, 11:06 AM
Seen: 1025 times
Last updated: 7/25/16, 5:01 AM