summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/list
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-05-28 09:17:30 +0000
committerThibault Delavallée <tde@odoo.com>2020-06-11 15:17:52 +0000
commit574dd61351f71dcc074b45523ca55ee1e59f8f75 (patch)
treef1f7902950507576850f663a745732486e291710 /addons/web/static/src/js/views/list
parent4c2db92aecc10103d2c8ef0269d342d20b61e979 (diff)
[HACK] crm: allow ordering on my activities deadline
RATIONALE Activities are a way to organize our daily pipe. Notably in a sales pipeline salesmen may have multiple leads with activities to perform in the next few days. We would like to be able to have a list view displaying a list of leads with "my" deadline, and to order leads based on this field. PURPOSE As activities are linked to records through a one2many and as my activities are only a subset of those activities, it is impossible to store a field on lead model. Indeed it would depend on the current user which makes storing it impossible. However ordering on a column in list view asks for a stored field. As it is not possible, this commit proposes to hijack the web client and search of lead model in order to allow it. SPECIFICATIONS Introduce a activity_date_deadline_my field, computed and searchable that behaves like activity_date_deadline. It is filtered on current user activities instead of being global to the record activities. "My" deadline is the earliest deadline of my activities, even in the past. Ordering through web client calls search_read with an order parameter set. Search_read then calls search. In this commit we therefore override search to intercept a search without count with an order on activity_date_deadline_my. In that case we do the search in two steps. First step: fill with deadline-based results * Perform a read_group on my activities to get a mapping lead_id / deadline Remember date_deadline is required, we always have a value for it. Only the earliest deadline per lead is kept. * Search leads linked to those activities that also match the asked domain and order from the original search request. * Results of that search will be at the top of returned results. Use limit None because we have to search all leads linked to activities as ordering on deadline is done in post processing. * Reorder them according to deadline asc or desc depending on original search ordering. Finally take only a subset of those leads to fill with results matching asked offset / limit. Second step: fill with other results. If first step does not gives results enough to match offset and limit parameters we fill with a search on other leads. We keep the asked domain and ordering while filtering out already scanned leads to keep a coherent results. All other search and search_read are left untouched by this commit to avoid side effects. Search_count is not affected by this commit. As web client order availability is simply based on field being stored we have to allow hijacking its value. A new option 'allow_order' is added that display the order icon in list view column headers. It allows calling search_read with an order based on the column but nothing more. Using it on a not-stored field will give a warning log and ORM ignores it by default. LIMITATIONS At least following limitations apply * search on "my activities" gives a list of ids that is used for searching and ordering. It means that having too much activities on a given user can result in poor performances. -> we consider that activities assigned to a given user should be kept under control. Leads with activities for a given user should be a small subset of leads without activities. * ordering on activity_date_deadline_my always put those records on the top (deadline asc or desc) whatever the actual ordering of order items given to search. This is done to avoid complex implementation where deadline would be used to order records within groups ordered by another field. -> for example: order = 'priority DESC, activity_date_deadline_my ASC' actually behaves like 'activity_date_deadline_my ASC, priority DESC'. WARNING This implementation is a hack. It has been done by professionals. Do not try to do it at home. More seriously this is hackish and should be avoided. IN our case we consider that the use of activities in sales pipeline is mainly driven by "my activities deadline", which is not necessarily the case with longer processes like tasks. Moreover user tests tend to show that this feature could be interesting. It will improve quality of Odoo CRM and its adoption by improving its daily use. A framework solution has to be found. Until this is done we keep this hack and hope it is not duplicated in other applications. LINKS Task ID 2276011 Prepares Task ID 2243124 (My activities in CRM) PR #52232 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/web/static/src/js/views/list')
-rw-r--r--addons/web/static/src/js/views/list/list_renderer.js2
1 files changed, 1 insertions, 1 deletions
diff --git a/addons/web/static/src/js/views/list/list_renderer.js b/addons/web/static/src/js/views/list/list_renderer.js
index 42b31bc2e3c..5fb716e48dc 100644
--- a/addons/web/static/src/js/views/list/list_renderer.js
+++ b/addons/web/static/src/js/views/list/list_renderer.js
@@ -891,7 +891,7 @@ var ListRenderer = BasicRenderer.extend({
.attr('tabindex', -1)
.toggleClass('o-sort-down', isNodeSorted ? !order[0].asc : false)
.toggleClass('o-sort-up', isNodeSorted ? order[0].asc : false)
- .addClass(field.sortable && 'o_column_sortable');
+ .addClass((field.sortable || this.state.fieldsInfo.list[name].options.allow_order || false) && 'o_column_sortable');
if (isNodeSorted) {
$th.attr('aria-sort', order[0].asc ? 'ascending' : 'descending');