From 9996668bade7d7d0e887b1f7c026200f5dd8446b Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 5 Dec 2014 17:40:42 +0100 Subject: [PATCH] [FIX] web: get conditional user defaults This is possible to set field conditional defaults, if the field has the attribute "change_default". The defaults are set by the web client, by calling the method "get_defaults" of ir.values model, when the onchange is triggered on the field on which the condition is. In 7.0, all onchanges were triggered clientside, one by one. On creation, the defaults of default_get method were pushed in the form, and then, as the values of the fields were changed (from null to the default value), all onchanges on which there was default value were triggered. In 8.0, onchanges are performed server side, all at once. On creation, the onchange method is triggered by default (wether or not there is a default value for them), for all fields (widget param of method do_onchange of view_forms js is undefined, meaning the onchange is not triggered on a specific field, but on all fields). In such a case, we must call the get_defaults method of ir.values model for all fields (having change_default attribute), in order the conditional defaults to be set in the form view. --- addons/web/static/src/js/view_form.js | 71 +++++++++++++++------------ 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index ccb6475e01d..5295942aa95 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -511,38 +511,47 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM } this.onchanges_mutex.exec(function(){ return def.then(function(response) { - if (widget && widget.field['change_default']) { - var fieldname = widget.name; - var value_; - if (response.value && (fieldname in response.value)) { - // Use value from onchange if onchange executed - value_ = response.value[fieldname]; - } else { - // otherwise get form value for field - value_ = self.fields[fieldname].get_value(); - } - var condition = fieldname + '=' + value_; - - if (value_) { - return self.alive(new instance.web.Model('ir.values').call( - 'get_defaults', [self.model, condition] - )).then(function (results) { - if (!results.length) { - return response; - } - if (!response.value) { - response.value = {}; - } - for(var i=0; i