Skip to Content
Menu
This question has been flagged
1 Reply
3379 Views

in odoo v17 with the replacement of name_get by _compute_display_name, the default email sent  when assigning an object to a user doesn't include any overridden value of name (as it was before).

what should I include in _compute_display_name in order to fix this?


Avatar
Discard
Best Answer

In Odoo v17, 'the _compute_display_name' method is used to compute the 'display_name' field. If you want to include the overridden value of 'name' in the 'display_name', you can modify the '_compute_display_name' method accordingly.


Here’s an example of how you might override the '_compute_display_name' method:


from odoo import api, fields, models


class YourModel(models.Model):

    _inherit = 'your.model'  # replace with your model name


    display_name = fields.Char(compute='_compute_display_name')


    @api.depends('name', 'parent_id.name')  # depends on the fields that make up your name

    def _compute_display_name(self):

        for record in self:

            names = [record.parent_id.name, record.name]  # adjust this line based on your needs

            record.display_name = ' / '.join(filter(None, names))



In this example, 'display_name' is computed based on the 'name' field and the 'name' field of the 'parent_id'. You should adjust the 'names' list based on your needs.

Remember to replace 'your.model' with the actual name of your model and adjust the '@api.depends' decorator and the names list according to your requirements. The 'filter(None, names)' part is used to remove any 'None' values from the 'names' list before joining them.

This should ensure that the overridden value of 'name' is included in the 'display_name' and thus in the default email sent when assigning an object to a user. Please test this solution thoroughly to ensure it works as expected in your specific use case. If you encounter any issues, feel free to ask for further assistance.

Regards,
Maciej Burzymowski

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 23
7656
4
May 25
2439
2
May 25
5776
1
Mar 25
1622
4
Mar 25
4413