[FIX] web: handle context in ControlPanel <filter>

The `context` key wasn't correctly taken into account when computing the search
query for `filter``tags.

It is now correctly handled.

Task 1917628

closes odoo/odoo#29529
This commit is contained in:
Martin Geubelle
2018-12-17 10:39:03 +00:00
parent 0794a3c956
commit ae2dbc60c5
4 changed files with 43 additions and 4 deletions
@@ -645,10 +645,7 @@ var ControlPanelModel = mvc.Model.extend({
* @returns {Object} context
*/
_getFilterContext: function (filter) {
var context = {};
if (filter.type === 'favorite') {
_.extend(context, filter.context);
}
var context = filter.context || {};
// the following code aims to restore this:
// https://github.com/odoo/odoo/blob/master/addons/web/static/src/js/views/search/search_inputs.js#L498
// this is required for the helpdesk tour to pass
@@ -143,6 +143,7 @@ var ControlPanelView = Factory.extend({
'Ω';
if (filter.type === 'filter') {
filter.domain = attrs.domain;
filter.context = pyUtils.eval('context', attrs.context);
if (attrs.date) {
filter.fieldName = attrs.date;
filter.fieldType = this.fields[attrs.date].type;
@@ -198,6 +199,7 @@ var ControlPanelView = Factory.extend({
var groupOfGroupBys = [];
var groupNumber = 1;
_.each(preFilters, function (preFilter) {
if (preFilter.attrs && preFilter.attrs.invisible) {
return;
@@ -120,6 +120,7 @@ QUnit.module('Views', {
assert.deepEqual(
controlPanelFactory.loadParams.groups,
[[{
context: {},
description: "Hello",
groupNumber: 2,
domain: "[]",
@@ -198,6 +199,7 @@ QUnit.module('Views', {
controlPanelFactory.loadParams.groups,
[[
{
"context": {},
"description": "Hello One",
"domain": "[]",
"groupNumber": 2,
@@ -205,6 +207,7 @@ QUnit.module('Views', {
"type": "filter"
},
{
"context": {},
"description": "Hello Two",
"domain": "[('bar', '=', 3)]",
"groupNumber": 2,
@@ -233,6 +236,7 @@ QUnit.module('Views', {
[
[
{
context: {},
description: "Hello One",
domain: "[]",
groupNumber: 2,
@@ -242,6 +246,7 @@ QUnit.module('Views', {
],
[
{
context: {},
description: "Hello Two",
domain: "[('bar', '=', 3)]",
groupNumber: 4,
@@ -267,6 +272,7 @@ QUnit.module('Views', {
[
[
{
context: {},
description: "Hello",
domain: "[]",
groupNumber: 2,
@@ -2,6 +2,7 @@ odoo.define('web.search_view_tests', function (require) {
"use strict";
var FormView = require('web.FormView');
var ListView = require('web.ListView');
var testUtils = require('web.test_utils');
var createActionManager = testUtils.createActionManager;
@@ -694,6 +695,39 @@ QUnit.module('Search View', {
window.Date = RealDate;
});
QUnit.test('`context` key in <filter> is used', function (assert) {
assert.expect(3);
this.archs['partner,4,search'] = '<search>'+
'<filter string="AAA" name="some_filter" context="{\'coucou_1\': 1}"></filter>' +
'</search>';
var actionManager = createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
mockRPC: function (route, args) {
if (route === '/web/dataset/search_read') {
assert.step(JSON.stringify(args.context));
}
return this._super.apply(this, arguments);
},
});
actionManager.doAction(5);
// select filter
testUtils.dom.click($('.o_search_options .fa-filter'));
testUtils.dom.click($('.o_menu_item:contains(AAA)'));
assert.verifySteps([
"{}",
"{\"coucou_1\":1}",
]);
actionManager.destroy();
});
QUnit.module('Favorites Menu');
QUnit.test('dynamic filters are saved dynamic', function (assert) {