From 2d97866f5aa600a194104eb644f4b81d1d3ae428 Mon Sep 17 00:00:00 2001 From: "Michael (mcm)" Date: Tue, 4 Oct 2022 08:57:07 +0000 Subject: [PATCH] [IMP] web: hide relation in field selector There was an option in the legacy ModelFieldSelector that could be used to prevent following the relations. This option was lost since the widget has been converted. This commit simply reintroduces the option. closes odoo/odoo#102308 X-original-commit: 673faab4dec7a0df434cf0575303df97a36db0f1 Signed-off-by: Aaron Bohy (aab) --- .../model_field_selector.js | 3 ++ .../model_field_selector_popover.js | 10 +++-- .../model_field_selector_popover.xml | 2 +- .../tests/core/model_field_selector_tests.js | 41 +++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/core/model_field_selector/model_field_selector.js b/addons/web/static/src/core/model_field_selector/model_field_selector.js index df7279cb023..43714898f40 100644 --- a/addons/web/static/src/core/model_field_selector/model_field_selector.js +++ b/addons/web/static/src/core/model_field_selector/model_field_selector.js @@ -88,6 +88,7 @@ export class ModelFieldSelector extends Component { isDebugMode: this.props.isDebugMode, loadChain: this.loadChain.bind(this), filter: this.props.filter, + followRelations: this.props.followRelations, }, { closeOnClickAway: true, @@ -110,6 +111,7 @@ Object.assign(ModelFieldSelector, { isDebugMode: { type: Boolean, optional: true }, update: { type: Function, optional: true }, filter: { type: Function, optional: true }, + followRelations: { type: Boolean, optional: true }, }, defaultProps: { readonly: true, @@ -117,5 +119,6 @@ Object.assign(ModelFieldSelector, { showSearchInput: true, update: () => {}, filter: () => true, + followRelations: true, }, }); diff --git a/addons/web/static/src/core/model_field_selector/model_field_selector_popover.js b/addons/web/static/src/core/model_field_selector/model_field_selector_popover.js index ee6c1647f77..0e834559f17 100644 --- a/addons/web/static/src/core/model_field_selector/model_field_selector_popover.js +++ b/addons/web/static/src/core/model_field_selector/model_field_selector_popover.js @@ -73,13 +73,13 @@ export class ModelFieldSelectorPopover extends Component { onFieldSelected(field) { this.searchValue = ""; this.currentNode.field = field; - if (!field.relation) { - this.props.close(); - } else { + if (field.relation && this.props.followRelations) { this.chain.push({ resModel: field.relation, field: null, }); + } else { + this.props.close(); } this.update(); } @@ -107,5 +107,9 @@ Object.assign(ModelFieldSelectorPopover, { loadChain: Function, filter: Function, close: Function, + followRelations: { type: Boolean, optional: true }, + }, + defaultProps: { + followRelations: true, }, }); diff --git a/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml b/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml index bf5679ea173..8426068b7d3 100644 --- a/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml +++ b/addons/web/static/src/core/model_field_selector/model_field_selector_popover.xml @@ -35,7 +35,7 @@
  • - + { assert.containsNone(target, ".o_field_selector_popover"); }); + + QUnit.test("can follow relations", async (assert) => { + await mountComponent(ModelFieldSelector, { + props: { + readonly: false, + fieldName: "", + resModel: "partner", + followRelations: true, // default + update(value) { + assert.strictEqual(value, "product_id"); + }, + }, + }); + + await click(target, ".o_field_selector"); + assert.containsOnce( + target, + ".o_field_selector_item:last-child .o_field_selector_relation_icon" + ); + await click(target, ".o_field_selector_item:last-child .o_field_selector_relation_icon"); + assert.containsOnce(target, ".o_popover"); + }); + + QUnit.test("cannot follow relations", async (assert) => { + await mountComponent(ModelFieldSelector, { + props: { + readonly: false, + fieldName: "", + resModel: "partner", + followRelations: false, + update(value) { + assert.strictEqual(value, "product_id"); + }, + }, + }); + + await click(target, ".o_field_selector"); + assert.containsNone(target, ".o_field_selector_relation_icon"); + await click(target, ".o_field_selector_item:last-child"); + assert.containsNone(target, ".o_popover"); + }); });