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

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?


Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lis 23
7695
4
maj 25
2472
2
maj 25
5811
1
mar 25
1648
4
mar 25
4434