Odoo Help


_rec_name - predefined fields

on 5/17/13, 9:07 AM 15,361 views

Hai Friends ,

 First I thank everyone who give good guideline for newbie in OpenERP . I have question regards predefined fields - _rec_name  in OpenERP .
  1. Its not clear for me , _rec_name predefined fields in OpenERP . Friends can you please explain with sample module .It more useful for clear understanding .

Thanks & Regards OMPRAKASH.A


Sudhir Arya (ERP Harbor Consulting Services)

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




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 5/17/13, 12:12 PM

_name is used to define object like account.invoice, sale.order, purchase.order, res.users.

When you have name field in your columns, you don't need to define field in _rec_name. OpenERP takes name field by default.

You have seen name in any form when you select many2one field. For example in Sale Order when you select Customer, you can see Customer's Name in that many2one field. Now if you want to show Customer's Phone Number in many2one field, you have to define phone field in _rec_name like this: _rec_name = 'phone'

If your columns don't have any name field then you have to define any field in _rec_name.

There are other reasons which Prakash described in his answer.

Hi Sudhir Arya, Thanks for your reply . I am new for OpenERP , If my question are very silly please don't mistake . I am very interest to know about OpenERP . 1. > From your point I can understand that _rec_name not needed until _name is defined . But if i create a <objectname>.py class _name is mandatory . So I must declare the _name fields . 2.> If i define _rec_name how can i make use .

on 5/18/13, 5:35 AM

This is my sample code please explain with this ...< Test.py > from osv import fields,osv class test(osv.osv): _name = 'sodexis' _rec_name = 'data_id' _columns = { 'name' : fields.char('name' , required = 1 , size = 30 ), 'age' : fields.integer('age' , store = False), 'data_id':fields.many2one('test', 'data_id', required=False) } test()

on 5/18/13, 5:37 AM

Please explain with this example , And once i thank you both for such guideline ... Thanks regards ----OMPRAKASH.A

on 5/18/13, 5:38 AM

I am talking about name field in _columns not _name. There is nothing to do with _name.

Sudhir Arya (ERP Harbor Consulting Services)
on 5/18/13, 7:00 AM

In your code you have defined name field

`name`: fields.char('name', required=1, size=30)

So you don't need to define _rec_name because OpenERP takes name field by by default.

Sudhir Arya (ERP Harbor Consulting Services)
on 5/18/13, 7:03 AM

Hi Suhir Arya , Thanks for your reply ..

on 5/20/13, 11:45 AM
On 1/20/17, 12:31 PM


I have another doubt here.I want to know the way to find which field is applied in _rec_name in the particular model.

I have taken that model id from ir.model table and also I could find all the fields list created in that model through ir.model.fields table.But I could not find which field is used in _rec_name

Could you please help me?




| 5 5 7
Bikaner, India

OpenERP Developer at SunARC Technology

On 5/17/13, 9:19 AM

In fields.many2one("table.name", output)

Default name_get method return the output value "name" field value in the table.

suppose in the table contain no "name" field then we can use _rec_name = field_name

Now in name_get method return _rec_name field value.

Hi Prakash , Thanks for your reply . I have doubt , _name is mandatory then how can I use _rec_name ? If you explain with sample code , It make more useful for me & once again thanks for your reply

on 5/17/13, 11:38 AM

Hi omprakash, Here is the sample code.

Class Test(models.Model):

_name = 'test'

_rec_name = field_1

field_1 = fields.Many2one('object',"Field 1")

field_2 = fields.Many2one('object',"Field 2")

date = fields.Date("Date")

As you can see no "name" field is there in above model.

So here we have 2 option :

Option 1: set rec_name :- Here field which is set in rec_name works as Model name field.

Option 2: override name_get method :- We need to override name_get method.(here we can concate more than 2 fields and create name for model)


@api.depends('field_1', 'date')

def name_get(self):

result = []

for test in self:

name = test.field_1 + ' ' + account.date

result.append((test.id, name))

return result

Aktiv Software, Jainesh Shah
on 6/7/17, 1:15 AM

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

Question tools

2 follower(s)


Asked: 5/17/13, 9:07 AM
Seen: 15361 times
Last updated: 7/13/17, 12:56 PM