diff options
| author | Jeremy Kersten <jke@odoo.com> | 2017-01-12 13:31:45 +0100 |
|---|---|---|
| committer | Jeremy Kersten <jke@odoo.com> | 2017-02-24 08:51:26 +0100 |
| commit | c5d2d78aa77eaed54453f154b7c85e42630d6276 (patch) | |
| tree | 8128e7ff170e63e0a2d88e900db50762b23fc7ec /addons/website_project_issue | |
| parent | 561d68bafda9caef7dd9bf9dc7e1ef6456c83558 (diff) | |
[IMP] website_project_issue: add search input in searchbar.
Allow to search issues with criteria: content, message, customer
Diffstat (limited to 'addons/website_project_issue')
| -rw-r--r-- | addons/website_project_issue/controllers/main.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/addons/website_project_issue/controllers/main.py b/addons/website_project_issue/controllers/main.py index 715c83e30eb..36232d2a93c 100644 --- a/addons/website_project_issue/controllers/main.py +++ b/addons/website_project_issue/controllers/main.py @@ -6,6 +6,7 @@ from collections import OrderedDict from odoo import http, _ from odoo.addons.website_portal.controllers.main import website_account, get_records_pager from odoo.http import request +from odoo.osv.expression import OR class WebsiteAccount(website_account): @@ -22,7 +23,7 @@ class WebsiteAccount(website_account): return response @http.route(['/my/issues', '/my/issues/page/<int:page>'], type='http', auth="user", website=True) - def my_issues(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, **kw): + def my_issues(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, search=None, search_in='content', **kw): values = self._prepare_portal_layout_values() # portal users can't see the privacy_visibility, fetch the domain for them in sudo portal_projects = request.env['project.project'].sudo().search([('privacy_visibility', '=', 'portal')]) @@ -37,6 +38,12 @@ class WebsiteAccount(website_account): searchbar_filters = { 'all': {'label': _('All'), 'domain': []}, } + searchbar_inputs = { + 'content': {'input': 'content', 'label': _('Search <span class="nolabel"> (in Content)</span>')}, + 'message': {'input': 'message', 'label': _('Search in Messages')}, + 'customer': {'input': 'customer', 'label': _('Search in Customer')}, + 'all': {'input': 'all', 'label': _('Search in All')}, + } # extends filterby criteria with project (criteria name is the project id) projects = request.env['project.project'].search([('privacy_visibility', '=', 'portal')]) for proj in projects: @@ -58,6 +65,17 @@ class WebsiteAccount(website_account): if date_begin and date_end: domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)] + # search + if search and search_in: + search_domain = [] + if search_in in ('content', 'all'): + search_domain = OR([search_domain, ['|', ('name', 'ilike', search), ('description', 'ilike', search)]]) + if search_in in ('customer', 'all'): + search_domain = OR([search_domain, [('partner_id', 'ilike', search)]]) + if search_in in ('message', 'all'): + search_domain = OR([search_domain, [('message_ids.body', 'ilike', search)]]) + domain += search_domain + # issue count issue_count = request.env['project.issue'].search_count(domain) # pager @@ -82,9 +100,12 @@ class WebsiteAccount(website_account): 'default_url': '/my/issues', 'pager': pager, 'searchbar_sortings': searchbar_sortings, + 'searchbar_inputs': searchbar_inputs, 'sortby': sortby, 'searchbar_filters': OrderedDict(sorted(searchbar_filters.items())), 'filterby': filterby, + 'search_in': search_in, + 'search': search, }) return request.render("website_project_issue.my_issues", values) |
