diff options
| author | Khoi Nguyen <bng@odoo.com> | 2017-07-26 16:03:39 +0200 |
|---|---|---|
| committer | Khoi Nguyen <bng@odoo.com> | 2017-07-27 17:11:41 +0200 |
| commit | 4e12edc023dd20d435f5575b5517a3c11deb8421 (patch) | |
| tree | 7ee68152a3b9eed274ecb31f67cbcce84ce829ec /addons/web/static/src/js | |
| parent | 1efca8d0738a259fbb7ebc12738e088908f53542 (diff) | |
[FIX] web: correct domain when using 'all' filters
Since the switch to the new views, 'all' filters such as "Everybody's
calendar" did not work as intended (activating the filter would
sometimes lead to fewer events being shown).
This commit corrects the way 'all' switches affect a domain.
More precisely, the conversion from filters to domain has been changed
in the following way.
- Ticking all visible checkboxes associated with a filter no longer
means the same as ticking the 'all' checkbox. The former choice was
particularly problematic when a filter only had one visible checkbox,
in which case it was not possible to see the list of records
only associated with that one filter.
- The conversion used to contain an impossible case in which we convert
a filter into a 'not in' domain. All the related logic has now been
deleted.
- Minor changes (renaming variables etc.) to make the code more
readable.
Diffstat (limited to 'addons/web/static/src/js')
| -rw-r--r-- | addons/web/static/src/js/views/calendar/calendar_model.js | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js index 73868a93fdb..ec3ff8940a7 100644 --- a/addons/web/static/src/js/views/calendar/calendar_model.js +++ b/addons/web/static/src/js/views/calendar/calendar_model.js @@ -302,44 +302,38 @@ return AbstractModel.extend({ // Private //-------------------------------------------------------------------------- + /** + * Converts this.data.filters into a domain + * + * @private + * @returns {Array} + */ _getFilterDomain: function () { - var domain = []; + // List authorized values for every field + // fields with an active 'all' filter are skipped + var authorizedValues = {}; + _.each(this.data.filters, function (filter) { + // Skip 'all' filters because they do not affect the domain if (filter.all) return; - var nb = {}; - var not = {}; - var contains = {}; + + // Loop over subfilters to complete authorizedValues _.each(filter.filters, function (f) { - if (!contains[filter.fieldName]) { - contains[filter.fieldName] = []; - not[filter.fieldName] = []; - nb[filter.fieldName] = 0; - } - if (f.value === 'all' && f.active) { - contains[filter.fieldName].all = true; - } else { - nb[filter.fieldName]++; - } + if (!authorizedValues[filter.fieldName]) + authorizedValues[filter.fieldName] = []; - if (f.active && contains[filter.fieldName].indexOf(f.value) === -1) { - contains[filter.fieldName].push(f.value); - } - if (!f.active && not[filter.fieldName].indexOf(f.value) === -1) { - not[filter.fieldName].push(f.value); + if (f.active) { + authorizedValues[filter.fieldName].push(f.value); } }); - - for (var field in contains) { - if (contains[field].all || contains[field].length === nb[field]) { - continue; - } - if (contains[field].length) { - domain.push([field, 'in', contains[field]]); - } else if (not[field].length && not[field].length !== nb[field]) { - domain.push([field, 'not in', not[field]]); - } - } }); + + // Compute the domain + var domain = []; + for (var field in authorizedValues) { + domain.push([field, 'in', authorizedValues[field]]); + } + return domain; }, /** |
