From 3ff7ff3e94e4fe34ec09a45fda04f0c8de33cd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Tue, 4 Apr 2017 15:08:00 +0200 Subject: [FIX] web: properly evaluate unset numeric values in domain Before this commit, when a numeric value was not set (for example, a new record with no default_get value), then it was not properly evaluated as 0 in a domain. We also slightly refactored the code so we always use the same method to compute the evaluation context. --- addons/web/static/src/js/views/basic/basic_model.js | 11 ++++++++++- 1 file changed, 10 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 0642fd6842c..f59cf96a881 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -268,6 +268,8 @@ var BasicModel = AbstractModel.extend({ * @param {boolean} [options.env=false] if true, will only return res_id * (if record) or res_ids (if list) * @param {boolean} [options.raw=false] if true, will not follow relations + * @param {boolean} [options.noUnsetNumeric=false] if true, will set numeric + * values to 0 if not set * @returns {Object} */ get: function (id, options) { @@ -311,6 +313,13 @@ var BasicModel = AbstractModel.extend({ if (!field) { continue; } + if (options.noUnsetNumeric) { + if (field.type === 'float' || + field.type === 'integer' || + field.type === 'monetary') { + element.data[fieldName] = element.data[fieldName] || 0; + } + } // get relational datapoint if (field.type === 'many2one') { @@ -1792,7 +1801,7 @@ var BasicModel = AbstractModel.extend({ * @returns {Object} */ _getEvalContext: function (element) { - var evalContext = this.get(element.id, {raw: true}).data; + var evalContext = this.get(element.id, {raw: true, noUnsetNumeric: true}).data; evalContext.active_model = element.model; if (evalContext.id) { evalContext.active_id = evalContext.id; -- cgit v1.2.3