Reputation: 340
Since Many2one field only displays one field, I thought about wrote a function to display in Many2one two fields, like this way:
def get_services(self, cr, uid, ids, context=None):
values = cr.execute("""SELECT name, entity
FROM services WHERE id = 3""")
values.fetchall()
for value__ in values:
if value__:
return {'value': {'service_id': value__[0] + " | " + value__[1]},} # Example: "Service 1 | Google"
First of all, is it possible? Is there any module which does this? So I could see it.
Then, I call the function this way:
_columns = {
'service_id':fields.function(get_services, type = 'many2one', obj = 'services_getservices_function', method = True, string = 'Service'),
I'm not getting any error, but the field doesn't display on the screen.
Upvotes: 0
Views: 843
Reputation: 323
What you need is overwriting name_get
on service model.
see https://doc.openerp.com/trunk/server/api_models/#openerp.osv.orm.BaseModel.name_get
Upvotes: 1
Reputation: 340
Solved.
I created another field which would contain the name plus the entity.
'name_plus_entity':fields.char('All', size = 300),
Then I created a function "onchange", so whenever the field 'name' OR the field 'entity' was changed, the field 'name_plus_entity' would get: 'name' + " | " + entity.
Also, I hide the field 'name_plus_entity' in the form XML.
Upvotes: 0