Odoo Help

1
2
Avatar

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
12614
| 6 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 

LinkedIn

Blog

Stackoverflow

ERP Harbor Consulting Services

Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Sudhir Arya (ERP Harbor Consulting Services)
On 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.

1
Avatar

Ray Carnes

--Ray Carnes--
20342
| 9 7 9
Keyport, United States
--Ray Carnes--

Senior ERP Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0 and 11.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
On 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
0

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
0
Dejan Dakovic
On 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

About This Community

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

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 12/25/13, 9:52 AM
Seen: 5917 times
Last updated: 12/7/18, 11:25 AM