Ajuda

0

_rec_name - predefined fields

Avatar
omprakash

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

1 Comentário
Avatar
Descartar
Avatar
Odoo Mates
-

See this video to understand use of the rec_name and how to set it for a model: https://www.youtube.com/watch?v=d_cyPsVc7vg

12 Respostas
9

_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.

6 Comentários
Avatar
Descartar
Avatar
omprakash
-

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 .

Avatar
omprakash
-

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()

Avatar
omprakash
-

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

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

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.

Avatar
omprakash
-

Hi Suhir Arya , Thanks for your reply ..

0
Avatar
subbarao
Melhor Resposta

_rec_name name by default looks for name field, if name field is not available then it will display like your model_name,db_id , so we have to pass at least one field to _rec_name in case of no name field.

Avatar
Descartar
0
Avatar
Nivas
Melhor Resposta

Hi,

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?


Avatar
Descartar
0
Avatar
Prakash
Melhor Resposta

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.

2 Comentários
Avatar
Descartar
Avatar
omprakash
-

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

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.multi

@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