From b8c1571d948e593779b83ba78130c341f1e427cd Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Wed, 14 Jun 2017 14:35:38 +0200 Subject: [FIX] web: prevent crash when giving wrong id in url The mock server had to be modified in order to test this behavior since it used to throw an error for invalid ids, while the actual server just ignores it and continues forth with the other ids. --- addons/web/static/src/js/views/basic/basic_model.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 d897a74c696..1ace44be50f 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1399,7 +1399,8 @@ var BasicModel = AbstractModel.extend({ * @param {string} [optinos.viewType] the type of view for which the record * is fetched (usefull to load the adequate fields), by defaults, uses * record.viewType - * @returns {Deferred -> Object} resolves to the record + * @returns {Deferred -> Object} resolves to the record or is rejected in + * case no id given were valid ids */ _fetchRecord: function (record, options) { var self = this; @@ -1412,6 +1413,9 @@ var BasicModel = AbstractModel.extend({ context: _.extend({}, record.context, {bin_size: true}), }) .then(function (result) { + if (result.length === 0) { + return $.Deferred().reject(); + } result = result[0]; record.data = _.extend({}, record.data, result); }) -- cgit v1.2.3 From c62a4edcb04fb1e3d65dea056123cece72425b7e Mon Sep 17 00:00:00 2001 From: Martin Geubelle Date: Wed, 21 Jun 2017 16:43:21 +0200 Subject: [FIX] web: set 0 as default value for numeric fields When creating a new record, the numeric field default value should be 0 in order to avoid manually setting mandatory fields to 0. This behaviour has been removed with the new views but one wants to restore it. The `mockRead` function has also been adapted in this commit because the server returns 0 for unset numeric fields. --- addons/web/static/src/js/views/basic/basic_model.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 1ace44be50f..716624f368b 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -2198,12 +2198,6 @@ var BasicModel = AbstractModel.extend({ if (!field || field.name === 'id') { continue; } - if (field.type === 'float' || - field.type === 'integer' || - field.type === 'monetary') { - context[fieldName] = context[fieldName] || 0; - continue; - } if (field.type === 'date' || field.type === 'datetime') { if (context[fieldName]) { context[fieldName] = JSON.parse(JSON.stringify(context[fieldName])); @@ -2449,7 +2443,11 @@ var BasicModel = AbstractModel.extend({ var fieldName = fieldNames[i]; if (!(fieldName in result)) { var field = params.fields[fieldName]; - if (field.type === 'one2many' || field.type === 'many2many') { + if (field.type === 'float' || + field.type === 'integer' || + field.type === 'monetary') { + result[fieldName] = 0; + } else if (field.type === 'one2many' || field.type === 'many2many') { result[fieldName] = []; } else { result[fieldName] = null; -- cgit v1.2.3