Skip to content

Commit

Permalink
[FIX] web: edit a required field in a list view in multi_edit
Browse files Browse the repository at this point in the history
Before this commit, in a list view in multi_edit mode and editable="0",
it was possible to edit a required field with an invalid value.

Why:
In the PR 101924, we decided to no longer pass readonly/required of fields
in non-editable views (if no editable="1").

Solution:
To know if a view is editable, you should not only look if it is
editable="1" but also if it is multi_edit="1".
So we want to pass the readonly/required fields if the view is
editable="1" or multi_edit="1".

How to reproduce:
- Go to a multi_edit="1" and editable="0" list view with at least one
  required field on the server side
- Select the checkbox of the record you want to edit
- Edit that field with an invalid value (e.g. clearing a text field)
- Click outside the line being edited

Before this commit:
The record is saved with the invalid value

After this commit:
An alert dialog is displayed to warn us that the value is invalid.
The record returns to readonly mode with the old value.

closes #103743

Related: odoo/enterprise#33045
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
  • Loading branch information
FrancoisGe authored and beledouxdenis committed Oct 21, 2022
1 parent f974eeb commit 554397c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Expand Up @@ -84,5 +84,6 @@ AlertDialog.props = {
contentClass: { type: String, optional: true },
};
AlertDialog.defaultProps = {
...ConfirmationDialog.defaultProps,
title: _lt("Alert"),
};
37 changes: 37 additions & 0 deletions addons/web/static/tests/views/list_view_tests.js
Expand Up @@ -1034,6 +1034,43 @@ QUnit.module("Views", (hooks) => {
assert.verifySteps(["onchange", "create", "read"]);
});

QUnit.test("multi_edit: edit a required field with an invalid value", async function (assert) {
serverData.models.foo.fields.foo.required = true;

await makeView({
type: "list",
resModel: "foo",
serverData,
arch: `
<tree multi_edit="1">
<field name="foo"/>
<field name="int_field"/>
</tree>`,
mockRPC(route, args) {
assert.step(args.method);
},
});
assert.containsN(target, ".o_data_row", 4);
assert.verifySteps(["get_views", "web_search_read"]);

const rows = target.querySelectorAll(".o_data_row");
await click(rows[0], ".o_list_record_selector input");
await click(rows[0].querySelector(".o_data_cell"));
await editInput(target, "[name='foo'] input", "");
await click(target, ".o_list_view");
assert.containsOnce(target, ".modal");
assert.strictEqual(target.querySelector(".modal .btn").textContent, "Ok");

await click(target.querySelector(".modal .btn"));
assert.strictEqual(
target.querySelector(".o_data_row .o_data_cell[name='foo']").textContent,
"yop"
);
assert.hasClass(target.querySelector(".o_data_row"), "o_data_row_selected");

assert.verifySteps([]);
});

QUnit.test("save a record with an required field computed by another", async function (assert) {
serverData.models.foo.onchanges = {
foo(record) {
Expand Down

0 comments on commit 554397c

Please sign in to comment.