summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/views/basic_model_tests.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-05-15 10:19:44 +0200
committerAaron Bohy <aab@odoo.com>2017-05-16 08:49:26 +0200
commit55de60db6e2fb7851526c258f1801f7d321974b7 (patch)
tree7eacd147983167a8be904f55294ceaf2014e595a /addons/web/static/tests/views/basic_model_tests.js
parent5f13b7f019a0aa56dabd426bb33b3be93f2954b0 (diff)
[FIX] web: BasicModel: missing fields in data for x2m
The 'data' attribute of exported datapoints (using 'get') must contain a value for each field in the view, and the default value is false when those fields are unset. The code manipulating those datapoints supposes that this is the case and it makes it easier and clean. However, it wasn't the case for x2manys in new records for which the default value contains CREATE commands with missing fields: in that case, those missing fields weren't added in data. This caused a crash in the Employee form view, in edit, if the user clicked on 'Create and Edit' of the 'Working hours' field, because some code in field_utils assumes that if the value of a date field isn't false, it means that it is a moment instance (but in that particular case it was undefined).
Diffstat (limited to 'addons/web/static/tests/views/basic_model_tests.js')
-rw-r--r--addons/web/static/tests/views/basic_model_tests.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/addons/web/static/tests/views/basic_model_tests.js b/addons/web/static/tests/views/basic_model_tests.js
index 5f4f94352df..180d38668c7 100644
--- a/addons/web/static/tests/views/basic_model_tests.js
+++ b/addons/web/static/tests/views/basic_model_tests.js
@@ -1331,4 +1331,44 @@ QUnit.module('Views', {
"there should be only one read");
model.destroy();
});
+
+ QUnit.test('data should contain all fields in view, default being false', function (assert) {
+ assert.expect(1);
+
+ this.data.partner.fields.product_ids.default = [
+ [6, 0, []],
+ [0, 0, {name: 'new'}],
+ ];
+ this.data.product.fields.date = { string: "Date", type: "date" };
+
+ var params = {
+ fieldNames: ['product_ids'],
+ modelName: 'partner',
+ fields: this.data.partner.fields,
+ fieldsInfo: {
+ form: {
+ product_ids: {
+ fieldsInfo: { list: { name: {}, date: {} } },
+ viewType: 'list',
+ }
+ },
+ },
+ res_id: undefined,
+ type: 'record',
+ viewType: 'form',
+ };
+
+ var model = createModel({
+ Model: BasicModel,
+ data: this.data,
+ });
+
+ model.load(params).then(function (resultID) {
+ var record = model.get(resultID);
+ assert.strictEqual(record.data.product_ids.data[0].data.date, false,
+ "date value should be in data, and should be false");
+ });
+
+ model.destroy();
+ });
});});