why name_get method is deprecated in odoo 17 ? and which method can we use instead of name_get?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
Hello,
Reason for Deprecation:
The name_get method was deprecated in Odoo 17 (commit #122085) in favor of a more standardized approach using the display_name field. This change aims to improve code maintainability and consistency across different models.
Alternative Method:
Instead of name_get, you should now access the display_name field directly. This field is designed to provide a human-readable representation of a record, often combining multiple fields for better context.
Here's how to use display_name:
record = self.env['your_model_name'].browse(record_id) record_name = record.display_name
And override _compute_display_name method:
- Create a method named _compute_display_name decorated with @api.depends
- Inside the method, define the logic for generating the display name. You can access other fields of the record (self) and combine them as needed.
- Finally, assign the generated string to self.display_name.
#=== COMPUTE METHODS ===#
@api.depends('partner_id')
@api.depends_context('sale_show_partner_name')
def _compute_display_name(self):
if not self._context.get('sale_show_partner_name'):
return super()._compute_display_name()
for order in self:
name = order.name
if order.partner_id.name:
name = f'{name} - {order.partner_id.name}'
order.display_name = name And override _compute_display_name method: regards
Hope it helps
Regards
Here is explain by odoo why they have removed it and replace it with _compute_display_nam https://github.com/odoo/odoo/commit/3c62ca1eb96d571b2b686b5caee370324c589ab4 . You can try do the guilde above by Lex to replace your name_get with _compute_display_name. Hope this help.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Feb 25
|
3448 | ||
|
1
Jan 24
|
1274 | ||
|
2
Feb 25
|
5709 | ||
|
1
Dec 24
|
1324 | ||
|
1
Apr 23
|
3984 |
Enhance the functionality of Many2One fields in Odoo with dynamic multi-field Search and Get capabilities. This app allows users to search and get records within Many2One fields using multiple fields. With a user-friendly configuration interface, you can easily specify the fields to be included in the search criteria, making it more efficient and flexible for finding records as well as displaying the records based on multiple fields instead of only name field.
https://apps.odoo.com/apps/modules/17.0/mh_dynamic_name_get_many2one