summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-04-07 10:43:30 +0200
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitf0ee1e2be579904495b2a78d56c314960392e94f (patch)
treee3157bb5d24764dc49b20f8f7c259b9185208e9c /addons
parent0cb500594627c4cbe94d4e8c86d69f74ca031f35 (diff)
[FIX] web: add session user_context in the evalcontext
When evaluating a domain, we need to add the user context, so domains can use a key such as uid.
Diffstat (limited to 'addons')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js6
-rw-r--r--addons/web/static/test/fields/relational_fields_tests.js41
2 files changed, 45 insertions, 2 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index 7badafa43c5..e5e7da7867b 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1915,6 +1915,10 @@ var BasicModel = AbstractModel.extend({
* Returns the evaluation context that should be used when evaluating the
* context/domain associated to a given element from the localData.
*
+ * It is actually quite subtle. We need to add some magic keys: active_id
+ * and active_ids. Also, the session user context is added in the mix to be
+ * sure. This allows some domains to use the uid key for example
+ *
* @param {Object} element - an element from the localData
* @returns {Object}
*/
@@ -1932,7 +1936,7 @@ var BasicModel = AbstractModel.extend({
}
_.extend(evalContext, {parent: parent.data});
}
- return evalContext;
+ return _.extend({}, session.user_context, evalContext);
},
/**
* Returns the list of field names of the given element according to its
diff --git a/addons/web/static/test/fields/relational_fields_tests.js b/addons/web/static/test/fields/relational_fields_tests.js
index eba4d57d012..86e569fdbb5 100644
--- a/addons/web/static/test/fields/relational_fields_tests.js
+++ b/addons/web/static/test/fields/relational_fields_tests.js
@@ -31,6 +31,7 @@ QUnit.module('relational_fields', {
},
date: {string: "Some Date", type: "date"},
datetime: {string: "Datetime Field", type: 'datetime'},
+ user_id: {string: "User", type: 'many2one', relation: 'user'},
},
records: [{
id: 1,
@@ -43,6 +44,7 @@ QUnit.module('relational_fields', {
turtles: [2],
timmy: [],
trululu: 4,
+ user_id: 17,
}, {
id: 2,
display_name: "second record",
@@ -56,6 +58,7 @@ QUnit.module('relational_fields', {
product_id: 37,
date: "2017-01-25",
datetime: "2016-12-12 10:55:05",
+ user_id: 17,
}, {
id: 4,
display_name: "aaa",
@@ -119,7 +122,19 @@ QUnit.module('relational_fields', {
turtle_qux: 9.8,
partner_ids: [],
}],
- }
+ },
+ user: {
+ fields: {
+ name: {string: "Name", type: "char"}
+ },
+ records: [{
+ id: 17,
+ name: "Aline",
+ }, {
+ id: 19,
+ name: "Christine",
+ }]
+ },
};
}
}, function () {
@@ -3102,6 +3117,30 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('static statusbar widget on many2one field with domain', function (assert) {
+ assert.expect(1);
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch:'<form string="Partners">' +
+ '<header><field name="trululu" domain="[(\'user_id\',\'=\',uid)]" widget="statusbar"/></header>' +
+ '</form>',
+ mockRPC: function (route, args) {
+ if (args.method === 'search_read') {
+ assert.deepEqual(args.args[0], ['|', ['id', '=', 4], ['user_id', '=', 17]],
+ "search_read should sent the correct domain");
+ }
+ return this._super.apply(this, arguments);
+ },
+ res_id: 1,
+ session: {user_context: {uid: 17}},
+ });
+
+ form.destroy();
+ });
+
QUnit.test('clickable statusbar widget on many2one field', function (assert) {
assert.expect(3);