From e663077c119fd1bd02a3f16ec272b2a2bcd938e3 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 18 Feb 2022 14:40:42 +0000 Subject: [PATCH] [IMP] account: create hook to override searchbar sortings/filters With this commit we can now call a hook when we want to modify the code for this route. Before this commit the only way to modify/extend this would be by taking over a big part of the code. closes odoo/odoo#84907 Signed-off-by: Laurent Smet --- addons/account/controllers/portal.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/addons/account/controllers/portal.py b/addons/account/controllers/portal.py index 1d9e6294767..cb8b95dde25 100644 --- a/addons/account/controllers/portal.py +++ b/addons/account/controllers/portal.py @@ -33,6 +33,21 @@ class PortalAccount(CustomerPortal): def _get_invoices_domain(self): return [('move_type', 'in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))] + def _get_account_searchbar_sortings(self): + return { + 'date': {'label': _('Date'), 'order': 'invoice_date desc'}, + 'duedate': {'label': _('Due Date'), 'order': 'invoice_date_due desc'}, + 'name': {'label': _('Reference'), 'order': 'name desc'}, + 'state': {'label': _('Status'), 'order': 'state'}, + } + + def _get_account_searchbar_filters(self): + return { + 'all': {'label': _('All'), 'domain': []}, + 'invoices': {'label': _('Invoices'), 'domain': [('move_type', '=', ('out_invoice', 'out_refund'))]}, + 'bills': {'label': _('Bills'), 'domain': [('move_type', '=', ('in_invoice', 'in_refund'))]}, + } + @http.route(['/my/invoices', '/my/invoices/page/'], type='http', auth="user", website=True) def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw): values = self._prepare_my_invoices_values(page, date_begin, date_end, sortby, filterby) @@ -59,22 +74,13 @@ class PortalAccount(CustomerPortal): self._get_invoices_domain(), ]) - searchbar_sortings = { - 'date': {'label': _('Date'), 'order': 'invoice_date desc'}, - 'duedate': {'label': _('Due Date'), 'order': 'invoice_date_due desc'}, - 'name': {'label': _('Reference'), 'order': 'name desc'}, - 'state': {'label': _('Status'), 'order': 'state'}, - } + searchbar_sortings = self._get_account_searchbar_sortings() # default sort by order if not sortby: sortby = 'date' order = searchbar_sortings[sortby]['order'] - searchbar_filters = { - 'all': {'label': _('All'), 'domain': []}, - 'invoices': {'label': _('Invoices'), 'domain': [('move_type', '=', ('out_invoice', 'out_refund'))]}, - 'bills': {'label': _('Bills'), 'domain': [('move_type', '=', ('in_invoice', 'in_refund'))]}, - } + searchbar_filters = self._get_account_searchbar_filters() # default filter by value if not filterby: filterby = 'all'