From 8473bde80e6609d552af8b00396c72a20bd3c47f Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 29 Jun 2017 11:46:46 +0200 Subject: [PATCH] [FIX] web: handle 'domain' key returned by onchanges Onchange RPCs return an object that may contain a 'domain' key. When it does, its value is an object whose keys are field names and values are the new domain for the corresponding field. Before this rev., the 'domain' key was totally ignored by the BasicModel. This feature is used for example in the account.payment form view (go to an open invoice, click on 'Register payment'): the domain of field payment_method_id is updated by the onchanges (e.g. when changing the journal_id). As the domain was ignored, it always displayed all possible payment methods. --- .../static/src/js/fields/relational_fields.js | 104 ++++++++---- .../static/src/js/views/basic/basic_model.js | 10 +- addons/web/static/src/xml/base.xml | 14 +- .../tests/fields/relational_fields_tests.js | 150 ++++++++++++++++++ 4 files changed, 238 insertions(+), 40 deletions(-) diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 44f884f130c..df7f018369d 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -1785,15 +1785,7 @@ var FieldSelection = AbstractField.extend({ */ init: function () { this._super.apply(this, arguments); - if (this.field.type === 'many2one') { - this.values = this.record.specialData[this.name]; - this.formatType = 'many2one'; - } else { - this.values = _.reject(this.field.selection, function (v) { - return v[0] === false && v[1] === ''; - }); - } - this.values = [[false, this.attrs.placeholder || '']].concat(this.values); + this._setValues(); }, //-------------------------------------------------------------------------- @@ -1823,13 +1815,12 @@ var FieldSelection = AbstractField.extend({ * @private */ _renderEdit: function () { - if (!this.$el.children().length) { - for (var i = 0 ; i < this.values.length ; i++) { - this.$el.append($('