[IMP] web: x2many list: deactivate modal when in editable

Before this commit, in a form view, it was possible to open a record in
a x2many list field when the list is editable (`editable="top|bottom"`)
and the form view or the field is in readonly.

We want to disable the opening of the record in this case to stay
consistant for a better UX:
- when in a editable x2many list, the record form view never opens (even
  if the form view or the field is in readonly)
- when not in editable, the form view always opens

This commit does not modify the behaviour of the x2many field kanban
view.

task-2964320

closes odoo/odoo#110838

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
fdardenne
2023-02-07 15:35:49 +01:00
parent 14d97ec28a
commit 1bfc3aa1cf
5 changed files with 39 additions and 3 deletions
@@ -86,6 +86,7 @@ class QuestionPageOneToManyField extends X2ManyField {
}
openRecord(params);
};
this.canOpenRecord = true;
}
/**
@@ -91,6 +91,9 @@ export class X2ManyField extends Component {
},
});
};
this.canOpenRecord =
this.viewMode === "list" ? !(archInfo.editable || this.props.editable) : true;
const selectCreate = useSelectCreate({
resModel: this.props.value.resModel,
activeActions: this.activeActions,
@@ -237,7 +240,9 @@ export class X2ManyField extends Component {
}
async openRecord(record) {
return this._openRecord({ record, mode: this.props.readonly ? "readonly" : "edit" });
if (this.canOpenRecord) {
return this._openRecord({ record, mode: this.props.readonly ? "readonly" : "edit" });
}
}
}
X2ManyField.components = { Pager, KanbanRenderer, ListRenderer, ViewButton };
@@ -2861,6 +2861,31 @@ QUnit.module("Fields", (hooks) => {
assert.containsNone(target, ".o_field_x2many_list_row_add");
});
QUnit.test(
"one2many list: cannot open record in editable list and form in readonly mode",
async function (assert) {
serverData.models.partner.records[0].p = [2];
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form edit="0">
<field name="p">
<tree editable="bottom">
<field name="display_name"/>
</tree>
</field>
</form>`,
resId: 1,
});
assert.containsOnce(target, ".o_data_cell[name='display_name']");
await click(target, ".o_data_cell[name='display_name']");
assert.containsNone(target, ".modal-dialog");
}
);
QUnit.test("one2many list: conditional create/delete actions", async function (assert) {
serverData.models.partner.records[0].p = [2, 4];
await makeView({
@@ -670,7 +670,7 @@ QUnit.module("Views", (hooks) => {
arch: `
<form edit="0">
<field name="partner_ids">
<tree editable="top">
<tree>
<field name="display_name"/>
<field name="timmy" widget="many2many_tags" options="{'color_field': 'color'}"/>
</tree>
@@ -4,7 +4,12 @@ import { registry } from "@web/core/registry";
import { SlideCategoryListRenderer } from "./slide_category_list_renderer";
import { X2ManyField } from "@web/views/fields/x2many/x2many_field";
class SlideCategoryOneToManyField extends X2ManyField {}
class SlideCategoryOneToManyField extends X2ManyField {
setup() {
super.setup();
this.canOpenRecord = true;
}
}
SlideCategoryOneToManyField.components = {
...X2ManyField.components,
ListRenderer: SlideCategoryListRenderer,