diff options
| author | Martin Geubelle <mge@odoo.com> | 2017-11-02 13:53:43 +0100 |
|---|---|---|
| committer | Martin Geubelle <mge@odoo.com> | 2017-11-02 16:02:11 +0100 |
| commit | 3e63f01cf1c3acab24221f1033d5d6ae6b33303f (patch) | |
| tree | 60b19bf0c48e039c55942dcde359eeb864561541 /addons/web | |
| parent | b2466c80ae37f92e9e88f941e72b24288f9e4572 (diff) | |
[FIX] web: FieldSelector: add model in field attributes
The key `model` was missing in the FieldSelector selected fields.
The model can be useful for example to create a one2many related field.
Diffstat (limited to 'addons/web')
| -rw-r--r-- | addons/web/static/src/js/widgets/model_field_selector.js | 17 | ||||
| -rw-r--r-- | addons/web/static/tests/widgets/model_field_selector_tests.js | 10 |
2 files changed, 21 insertions, 6 deletions
diff --git a/addons/web/static/src/js/widgets/model_field_selector.js b/addons/web/static/src/js/widgets/model_field_selector.js index b82c2ed1963..81abfbe0d6c 100644 --- a/addons/web/static/src/js/widgets/model_field_selector.js +++ b/addons/web/static/src/js/widgets/model_field_selector.js @@ -204,7 +204,7 @@ var ModelFieldSelector = Widget.extend({ context: this.getSession().user_context, }) .then((function (fields) { - modelFieldsCache.cache[model] = sortFields(fields); + modelFieldsCache.cache[model] = sortFields(fields, model); }).bind(this)); } return def.then((function () { @@ -299,7 +299,7 @@ var ModelFieldSelector = Widget.extend({ _pushPageData: function (model) { var def; if (this.model === model && this.options.fields) { - def = $.when(sortFields(this.options.fields)); + def = $.when(sortFields(this.options.fields, model)); } else { def = this._getModelFieldsFromCache(model, this.options.filters); } @@ -539,14 +539,21 @@ return ModelFieldSelector; * the final array contain an additional key "name" with the field name. * * @param {Object} fields - the mapping field name -> field info + * @param {string} model * @returns {Object[]} the field infos sorted by field "string" (field infos - * contain an additional key "name" with the field name) + * contain additional keys "model" and "name" with the field + * name) */ -function sortFields(fields) { +function sortFields(fields, model) { return _.chain(fields) .pairs() .sortBy(function (p) { return p[1].string; }) - .map(function (p) { return _.extend({name: p[0]}, p[1]); }) + .map(function (p) { + return _.extend({ + name: p[0], + model: model, + }, p[1]); + }) .value(); } }); diff --git a/addons/web/static/tests/widgets/model_field_selector_tests.js b/addons/web/static/tests/widgets/model_field_selector_tests.js index d331f898d42..1ce4fc8c2dc 100644 --- a/addons/web/static/tests/widgets/model_field_selector_tests.js +++ b/addons/web/static/tests/widgets/model_field_selector_tests.js @@ -50,7 +50,7 @@ QUnit.module('ModelFieldSelector', { }, function () { QUnit.test("creating a field chain from scratch", function (assert) { - assert.expect(13); + assert.expect(14); var $target = $("#qunit-fixture"); @@ -90,6 +90,14 @@ QUnit.module('ModelFieldSelector', { assert.strictEqual(getValueFromDOM($value), "Bar", "field selector value should be displayed with a 'Bar' tag"); + assert.deepEqual(fieldSelector.getSelectedField(), { + model: "partner", + name: "bar", + searchable: true, + string: "Bar", + type: "boolean", + }, "the selected field should be correctly set"); + // Focusing the input again should open the same popover fieldSelector.$el.trigger('focusin'); assert.ok($fieldSelectorPopover.is(":visible"), |
