[FIX] web: KanbanView multi edit

Before this commit, in a kanban view, if you try to create a new record
while another one is being saved, then a crash is displayed.

To avoid this problem, when we create a new record in quickCreate mode,
we will first wait until the first one has finished saving before
creating the new one.

closes odoo/odoo#96826

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
FrancoisGe
2022-07-28 13:21:18 +02:00
parent a234b8b9b6
commit 19c2bbfa3a
3 changed files with 99 additions and 0 deletions
@@ -59,6 +59,9 @@ export class KanbanRecordQuickCreate extends Component {
/** @param {boolean} force */
cancel(force) {
if (this.state.disabled) {
return;
}
this.props.onCancel(force);
}
@@ -1831,6 +1831,7 @@ export class DynamicRecordList extends DynamicList {
}
async quickCreate(activeFields, context) {
await this.model.mutex.getUnlockedDef();
const record = this.quickCreateRecord;
if (record) {
this.removeRecord(record);
@@ -2037,6 +2037,101 @@ QUnit.module("Views", (hooks) => {
assert.verifySteps(["create"]);
});
QUnit.test(
"save a quick create record and create a new record at the same time",
async (assert) => {
const prom = makeDeferred();
await makeView({
type: "kanban",
resModel: "partner",
serverData,
arch: `
<kanban on_create="quick_create">
<field name="bar"/>
<templates>
<t t-name="kanban-box">
<div>
<field name="display_name"/>
</div>
</t>
</templates>
</kanban>`,
groupBy: ["bar"],
async mockRPC(route, { method }) {
if (method === "name_create") {
assert.step("name_create");
await prom;
}
},
});
assert.containsN(
target,
".o_kanban_record",
4,
"should have 4 records at the beginning"
);
// Create and save a record
await quickCreateRecord();
await editQuickCreateInput("display_name", "new partner");
await validateRecord();
assert.containsN(
target,
".o_kanban_record",
4,
"should not have created the record yet"
);
assert.strictEqual(
target.querySelector(".o_kanban_quick_create [name=display_name] input").value,
"new partner",
"quick create should not be empty yet"
);
assert.hasClass(
target.querySelector(".o_kanban_quick_create"),
"o_disabled",
"quick create should be disabled"
);
// Create a new record during the save of the first one
await createRecord();
assert.containsN(
target,
".o_kanban_record",
4,
"should not have created the record yet"
);
assert.strictEqual(
target.querySelector(".o_kanban_quick_create [name=display_name] input").value,
"new partner",
"quick create should not be empty yet"
);
assert.hasClass(
target.querySelector(".o_kanban_quick_create"),
"o_disabled",
"quick create should be disabled"
);
prom.resolve();
await nextTick();
assert.containsN(target, ".o_kanban_record", 5, "should have created a new record");
assert.strictEqual(
target.querySelector(
".o_kanban_quick_create .o_field_widget[name=display_name] input"
).value,
"",
"quick create should now be empty"
);
assert.doesNotHaveClass(
target.querySelector(".o_kanban_quick_create"),
"o_disabled",
"quick create should be enabled"
);
assert.verifySteps(["name_create"]);
}
);
QUnit.test(
"quick create record: prevent multiple adds with ENTER, with onchange",
async (assert) => {