[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) <aab@odoo.com>
This commit is contained in:
@@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<t t-if="field.searchable and props.filter(field)">
|
||||
<li class="o_field_selector_item" t-on-click="() => this.onFieldSelected({ ...field, name: fieldKey })">
|
||||
<t t-esc="field.string" />
|
||||
<t t-if="field.relation">
|
||||
<t t-if="field.relation and props.followRelations">
|
||||
<i
|
||||
class="fa fa-chevron-right o_field_selector_relation_icon"
|
||||
role="img"
|
||||
|
||||
@@ -477,4 +477,45 @@ QUnit.module("Components", (hooks) => {
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user