Search code examples
odooodoo-16

How do I sort customer column by name?


Does odoo 16 offer the option of sorting the customer list alphabetically in ascending or descending order? In the module res.partner (view_type=list) I can sort the entries by all columns, but not by name. Is this a setting in the configuration or do I have to create a module extension somewhere that then generates a corresponding “Name” field for sorting?


Solution

  • That's because the column is a computed non-stored field and only stored fields can be sorted. So you have atleast to easy possibilities:

    1. Make the field stored.
    class ResPartner(models.Model):
        _inherit = "res.partner"
    
        translated_display_name = fields.Char(store=True)
    

    If you use more than one language in Odoo, i wouldn't do that, because otherwise Company invoice, delivery and other addresses without name would never be translated again after saving.

    1. Change the list column from field translated_display_name to display_name, because the second is already stored in database.