_rec_name is intended to define the record value used to display it in search for many2one , breadcrumbs and many other cases .
Size: 1.64 MB
Language: en
Added: May 10, 2024
Slides: 24 pages
Slide Content
Model Attribute _rec_name in Odoo 17 Enterprise
Introduction Enterprise _rec_name is intended to define the record value used to display it in search for many2one , breadcrumbs and many other cases .
Steps Enterprise First of all we have to create a model class for creating the wizard. Also, don't forget to include the model in the security file and provide the necessary rights.
Enterprise
Steps Enterprise Next, we must create a view. The view should always be opened as ir.actions—act_window data. A menu item or button action defined in Python or XML code . We can make a menu and action window to see if our new views .
Enterprise
Enterprise
Steps Enterprise Now if you go to the contacts you will see a new menu added called student requests .
Enterprise
Steps Enterprise Now you will see the corresponding tree and form views of our new model .
Enterprise
Enterprise
Steps Enterprise As you can see in the breadcrumb , the record is called student.request.1 which is a combination of model name and id . This is the default name assigned to a record if there is no _rec_name attribute specified and no ‘name’ field is specified .
Steps Enterprise Now if we change the _rec_name the to student_name you will see that the default name of the record will the be value in the student_name field .
Steps Enterprise
Steps Enterprise Now if we change the _rec_name the to student_id you will see that the default name of the record will the be value in the student_id field .
Steps Enterprise
Steps Enterprise Now let us also see how it affects the search in a many2one field of our new model . For this let us add a new many2one field to res.partner model and add it to our view
Enterprise
Enterprise
Steps Enterprise As you can see in the many2one’s search, the record are in the combination of model name and id . This is the default name assigned to a record if there is no _rec_name attribute specified and no ‘name’ field is specified .
Steps Enterprise Now if we change the _rec_name the to student_name you will see that the default name of the record will the be value in the student_name field .
Steps Enterprise Now if we change the _rec_name the to student_id you will see that the default name of the record will the be value in the student_id field .
For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com