summaryrefslogtreecommitdiff
path: root/addons/web/static/test/views/basic_model_tests.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-02-28 11:48:00 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit5804ed100ec790a36c5ff30a217914950cd78098 (patch)
treea9f7ecf403cc8682c52ecce354ba082e9dee1a7c /addons/web/static/test/views/basic_model_tests.js
parente5740270568404d71a3bc093074a085c9c2eded8 (diff)
[IMP] web, *: compute contexts and domains from datapoint
This commit tries to refactore the management of contexts and domains in the webclient. - Get rid of CompoundDomain: use standard array manipulation to join multiple domains or use the Domain class (to be improved) - Get rid of data.js build_domain and build_context methods - Link this.record to the data point from the basic model for all fields (not only relational fields) - Add a getContext and a getDomain function to the basic model data point (localData element) so that AbstractField implementations can use them thanks to their this.record element. - Remove the autocontext binding for field RPCs (see FieldManagerMixin)
Diffstat (limited to 'addons/web/static/test/views/basic_model_tests.js')
-rw-r--r--addons/web/static/test/views/basic_model_tests.js60
1 files changed, 59 insertions, 1 deletions
diff --git a/addons/web/static/test/views/basic_model_tests.js b/addons/web/static/test/views/basic_model_tests.js
index 5fba6cd4444..0fb7876063d 100644
--- a/addons/web/static/test/views/basic_model_tests.js
+++ b/addons/web/static/test/views/basic_model_tests.js
@@ -638,7 +638,6 @@ QUnit.module('Views', {
model.destroy();
});
-
QUnit.test('write commands on a one2many', function (assert) {
assert.expect(4);
@@ -835,5 +834,64 @@ QUnit.module('Views', {
model.destroy();
});
+ QUnit.test('contexts and domains can be properly fetched', function (assert) {
+ assert.expect(8);
+
+ this.data.partner.fields.product_id.context = "{'hello': 'world', 'test': foo}";
+ this.data.partner.fields.product_id.domain = "[['hello', 'like', 'world'], ['test', 'like', foo]]";
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ this.params.fieldNames = ['product_id', 'foo'];
+
+ model.load(this.params).then(function (resultID) {
+ var recordPartner = model.get(resultID);
+ assert.strictEqual(typeof recordPartner.getContext, "function",
+ "partner record should have a getContext function");
+ assert.strictEqual(typeof recordPartner.getDomain, "function",
+ "partner record should have a getDomain function");
+ assert.deepEqual(recordPartner.getContext(), {},
+ "asking for a context without a field name should fetch the session/user/view context");
+ assert.deepEqual(recordPartner.getDomain(), [],
+ "asking for a domain without a field name should fetch the session/user/view domain");
+ assert.deepEqual(
+ recordPartner.getContext({fieldName: "product_id"}),
+ {hello: "world", test: "gnap"},
+ "asking for a context with a field name should fetch the field context (evaluated)");
+ assert.deepEqual(
+ recordPartner.getDomain({fieldName: "product_id"}),
+ [["hello", "like", "world"], ["test", "like", "gnap"]],
+ "asking for a domain with a field name should fetch the field domain (evaluated)");
+ });
+ model.destroy();
+ // Try again with xml override of field domain and context
+ model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ this.params.fieldAttrs = {
+ product_id: {
+ context: "{'hello2': 'world', 'test2': foo}",
+ domain: "[['hello2', 'like', 'world'], ['test2', 'like', foo]]",
+ },
+ };
+
+ model.load(this.params).then(function (resultID) {
+ var recordPartner = model.get(resultID);
+ assert.deepEqual(
+ recordPartner.getContext({fieldName: "product_id"}),
+ {hello2: "world", test2: "gnap"},
+ "field context should have been overriden by xml attribute");
+ assert.deepEqual(
+ recordPartner.getDomain({fieldName: "product_id"}),
+ [["hello2", "like", "world"], ["test2", "like", "gnap"]],
+ "field domain should have been overriden by xml attribute");
+ });
+ model.destroy();
+ });
});});