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

Autofill gives ID number not the field value?

By
Uppili Arivukkannu
on 7/23/16, 11:06 AM 313 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}}

else:

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

return res

XML :

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

The auto fill value is filled with

dent.year(1,)   

vals.make(123,)

car.model(144,)


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
0
Tuan
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

1 follower(s)

Stats

Asked: 7/23/16, 11:06 AM
Seen: 313 times
Last updated: 7/25/16, 5:01 AM