summaryrefslogtreecommitdiff
path: root/addons/project/controllers/portal.py
diff options
context:
space:
mode:
authorXavierDo <xdo@odoo.com>2018-03-20 12:48:44 +0100
committerXavierDo <xdo@odoo.com>2018-04-19 17:22:00 +0200
commitdea07fc29116c36c8a3773eec0fce526a972ba08 (patch)
treedf24b42ac8fe25a4346b1616d069b5c1fd6fcbb1 /addons/project/controllers/portal.py
parentb8bf945335f2e52dbd07f2560108f2ee4637598d (diff)
[IMP] project, portal: group tasks by project on portal.
The portal view for tasks previously listed all task of all projects without grouping them. It was a problem, mainly when we want to make the distinction on project label_tasks, to make the difference between tasks, issues, ... Grouping task by project by default allows to show the label_tasks before each project. Grouping the tasks removes the possibility to define a primary ordering. We want to be able to ungroup the tasks in some cases. The implentation was done in the portalsearch bar adding a group by option. The portal proposes two grouping options, project (by default) and none (to keep strict ordering). Task: #1827950 PR #23769
Diffstat (limited to 'addons/project/controllers/portal.py')
-rw-r--r--addons/project/controllers/portal.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/addons/project/controllers/portal.py b/addons/project/controllers/portal.py
index e847875f2d1..105e90e9fba 100644
--- a/addons/project/controllers/portal.py
+++ b/addons/project/controllers/portal.py
@@ -2,10 +2,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from collections import OrderedDict
+from operator import itemgetter
from odoo import http, _
from odoo.http import request
from odoo.addons.portal.controllers.portal import get_records_pager, CustomerPortal, pager as portal_pager
+from odoo.tools import groupby as groupbyelem
from odoo.osv.expression import OR
@@ -78,6 +80,7 @@ class CustomerPortal(CustomerPortal):
@http.route(['/my/tasks', '/my/tasks/page/<int:page>'], type='http', auth="user", website=True)
def portal_my_tasks(self, page=1, date_begin=None, date_end=None, sortby=None, filterby=None, search=None, search_in='content', **kw):
+ groupby = kw.get('groupby', 'project') #TODO master fix this
values = self._prepare_portal_layout_values()
searchbar_sortings = {
'date': {'label': _('Newest'), 'order': 'create_date desc'},
@@ -95,6 +98,10 @@ class CustomerPortal(CustomerPortal):
'stage': {'input': 'stage', 'label': _('Search in Stages')},
'all': {'input': 'all', 'label': _('Search in All')},
}
+ searchbar_groupby = {
+ 'none': {'input': 'none', 'label': _('None')},
+ 'project': {'input': 'project', 'label': _('Project')},
+ }
# extends filterby criteria with project (criteria name is the project id)
# Note: portal users can't view projects they don't follow
projects = request.env['project.project'].sudo().search([('privacy_visibility', '=', 'portal')])
@@ -142,22 +149,31 @@ class CustomerPortal(CustomerPortal):
step=self._items_per_page
)
# content according to pager and archive selected
+ if groupby == 'project':
+ order = "project_id, %s" % order # force sort on project first to group by project in view
tasks = request.env['project.task'].search(domain, order=order, limit=self._items_per_page, offset=pager['offset'])
request.session['my_tasks_history'] = tasks.ids[:100]
+ if groupby == 'project':
+ grouped_tasks = [request.env['project.task'].concat(*g) for k, g in groupbyelem(tasks, itemgetter('project_id'))]
+ else:
+ grouped_tasks = [tasks]
values.update({
'date': date_begin,
'date_end': date_end,
'projects': projects,
- 'tasks': tasks,
+ 'tasks': tasks, #TODO master remove this, grouped_tasks is enough
+ 'grouped_tasks': grouped_tasks,
'page_name': 'task',
'archive_groups': archive_groups,
'default_url': '/my/tasks',
'pager': pager,
'searchbar_sortings': searchbar_sortings,
+ 'searchbar_groupby': searchbar_groupby,
'searchbar_inputs': searchbar_inputs,
'search_in': search_in,
'sortby': sortby,
+ 'groupby': groupby,
'searchbar_filters': OrderedDict(sorted(searchbar_filters.items())),
'filterby': filterby,
})