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. --- .../web/static/src/js/views/basic/basic_model.js | 11 ++++++- .../static/src/js/views/basic/basic_renderer.js | 38 ---------------------- 2 files changed, 10 insertions(+), 39 deletions(-) (limited to 'addons/web/static/src/js/views/basic') 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; diff --git a/addons/web/static/src/js/views/basic/basic_renderer.js b/addons/web/static/src/js/views/basic/basic_renderer.js index 2aa4479648b..1db0718545e 100644 --- a/addons/web/static/src/js/views/basic/basic_renderer.js +++ b/addons/web/static/src/js/views/basic/basic_renderer.js @@ -51,44 +51,6 @@ return AbstractRenderer.extend({ } }); }, - /** - * Helper method, used to get an object with the 'raw' field values. It is - * important when we want to evaluate if a record matches a given domain. - * - * A basic model record is a tree structure, but we sometimes need 'pure' - * data, so for example, [1,4] for the value of a one2many, not - * [{Object}, {Object}]. - * - * @param {Object} record - * @returns {Object} - */ - _getFieldValues: function (record) { - var result = {}; - _.each(record.getFieldNames(), function (name) { - var field = record.fields[name]; - var value = record.data[name]; - result[name] = value; - if (!value) { - return; - } - else if (field.type === 'many2one') { - result[name] = value.data ? value.data.id || false : false; - } - else if (field.type === 'one2many' || field.type === 'many2many') { - if (value) { - result[name] = _.pluck(value.data, 'res_id'); - } else { - result[name] = []; - } - } - else if (field.type === 'boolean') { - // we want an explicit false value, not null if it is unset - result[name] = value || false; - } - }); - result.id = record.data.id; - return result; - }, /** * Render the view * -- cgit v1.2.3