Odoo Help

4 Answers

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 7 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




ERP Harbor Consulting Services

Website: http://www.erpharbor.com
Sudhir Arya (ERP Harbor Consulting Services)
12/28/13, 12:58 PM

many2one field by default displays either name field or the field which is defined in _rec_name. If you want to display value of other fields then you need to override name_get method in your object.

For example I want to display two fields (name, name2) in my many2one field:

def name_get(self, cr, uid, ids, context=None):
    if not len(ids):
        return []
    res = [(r['id'], r['name'] and '%s [%s]' % (r['name'], r['name2']) or r['name'] ) for r in self.read(cr, uid, ids, ['name', 'name2'], context=context) ]
    return res

You may refer: ORM Method: name_get.


Ray Carnes

--Ray Carnes--
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Business Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0, 11.0 and 12.0.

Completed Odoo Functional and Technical Training.

Functional Areas:

  • CRM/Sales

  • Inventory

  • Manufacturing

  • Accounting

  • Purchasing

Major Skills:

  • Business Process Reengineering

  • Efficiency Consulting

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

I am a skilled Communicator and I only take the serious things seriously!

Ray Carnes
12/25/13, 6:42 PM

You need to override the name_get function for the class.

By default this function returns either the value of name or the value of the field specified in _rec_name.

Product Category gets composite values this way.

image description

There is a function, overriding the default, at \addons\product\product.py:

def name_get(self, cr, uid, ids, context=None):
    if isinstance(ids, (list, tuple)) and not len(ids):
        return []
    if isinstance(ids, (long, int)):
        ids = [ids]
    reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
    res = []
    for record in reads:
        name = record['name']
        if record['parent_id']:
            name = record['parent_id'][1]+' / '+name
        res.append((record['id'], name))
    return res

You can use a computed field:

class Test(models.Model):
_name = 'coding.test'
_rec_name = 'combination'

field1 = fields.Char(default='Bob')
field2 = fields.Char(default='Sponge')
combination = fields.Char(string='Combination', compute='_compute_fields_combination')

@api.depends('field1', 'field2')
def _compute_fields_combination(self):
for test in self:
test.combination = test.field1 + ' ' + test.field2
Dejan Dakovic
12/7/18, 5:30 AM
I've tried in several ways,
but it always shows me this error

TypeError: name_get() takes at least 4 arguments (1 given)

Do I need something to include?

class komReon(models.Model):
_name = 'kom.reon'
_description = 'Sifarnik Reona'

reon_id = fields.Integer(string='Sifra reona')
name = fields.Char(string='Naziv reona')
parent_id = fields.Many2one('kom.reon')
parent_left = fields.Integer(string='Roditelj lijevo')
parent_right = fields.Integer(string='Roditelj desno')

    def name_get(self,cr,uid,ids,context={}):
    if isinstance(ids, (list, tuple)) and not len(ids):
    return []
    if isinstance(ids, (long, int)):
    ids = [ids]
    reads = self.read(cr, uid, ids, ['name', 'parent_id'], context=context)
    res = []
    for record in reads:
    name = record['name']
    if record['parent_id']:
    name = record['parent_id'][1] + ' / ' + name
    res.append((record['id'], name))
    return res

Ask a Question
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