[FIX] web: invalid kanban record quick_create stays open

- Before this commit
Validating an invalid kanban record on quick creation
would leave the quick creation mode.

- After this commit
Validating an invalid kanban record on quick creation
will stay in quick creation mode, indicating which fields are invalid.

closes odoo/odoo#98874

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Bruno Boi
2022-08-25 12:05:47 +02:00
parent 67b41d47e6
commit ec70294e64
3 changed files with 49 additions and 16 deletions
@@ -295,6 +295,20 @@ class KanbanGroup extends Group {
await this.checkActiveValue();
}
async validateQuickCreate() {
const record = this.list.quickCreateRecord;
if (!record) {
return false;
}
const saved = await record.save();
if (saved) {
this.addRecord(this.removeRecord(record), 0);
this.count++;
this.list.count++;
return record;
}
}
// ------------------------------------------------------------------------
// Protected
// ------------------------------------------------------------------------
@@ -2542,22 +2542,6 @@ export class Group extends DataPoint {
this.model.notify();
}
async validateQuickCreate() {
const record = this.list.quickCreateRecord;
if (!record) {
return false;
}
const saved = await record.save();
if (saved) {
this.addRecord(this.removeRecord(record), 0);
this.count++;
this.list.count++;
return record;
} else {
this.removeRecord(record);
}
}
valueEquals(value) {
return this.value instanceof DateTime ? this.value.equals(value) : this.value === value;
}
@@ -1562,6 +1562,41 @@ QUnit.module("Views", (hooks) => {
]);
});
QUnit.test("quick create record validation: stays open when invalid", async (assert) => {
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="foo"/></div>
</t></templates>
</kanban>
`,
groupBy: ["bar"],
async mockRPC(route, { method }) {
assert.step(method || route);
},
});
assert.verifySteps(["get_views", "web_read_group", "web_search_read", "web_search_read"]);
await createRecord();
assert.verifySteps(["onchange"]);
// do not fill anything and validate
await validateRecord();
assert.verifySteps([]);
assert.containsOnce(target, ".o_kanban_group:first-child .o_kanban_quick_create");
assert.hasClass(target.querySelector("[name=display_name]"), "o_field_invalid");
assert.containsOnce(target, ".o_notification_manager .o_notification");
assert.equal(
target.querySelector(".o_notification").textContent,
"Invalid fields: Display Name"
);
});
QUnit.test("quick create record with default values and onchanges", async (assert) => {
serverData.models.partner.fields.int_field.default = 4;
serverData.models.partner.onchanges = {