Odoo Help


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.


Function Many2One with two values (like Value1 | Value2)

on 9/19/13, 7:16 AM 1,083 views


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""")
        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'),

But I'm getting the following error:

AttributeError: 'str' object has no attribute 'func_name'

On 9/19/13, 8:31 AM


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.

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

0 follower(s)


Asked: 9/19/13, 7:16 AM
Seen: 1083 times
Last updated: 3/16/15, 8:10 AM