Skip to Content
Menu
This question has been flagged
2 Replies
3476 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?


Avatar
Discard
Author

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

Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 18
13305
1
Apr 20
4023
1
Jun 18
2563
1
Nov 17
5884
1
Aug 17
2972