Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
10125 Widoki

why name_get method is deprecated in odoo 17 ? and which method can we use instead of name_get?

Awatar
Odrzuć

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

Najlepsza odpowiedź

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


Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lut 25
3681
1
sty 24
1491
2
lut 25
5964
1
gru 24
1493
1
kwi 23
4117