[IMP] web: enable list button for draft record

Before this commit, the buttons of the draft record in a
list view were disabled. Now, they are enabled and will
save (create) the record before executing the button's action.

closes odoo/odoo#110383

Task: 3132960
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Michael (mcm)
2023-02-02 15:02:07 +01:00
parent 5c3589ebe7
commit 42a57110eb
3 changed files with 26 additions and 4 deletions
@@ -494,7 +494,11 @@ export class ListController extends Component {
});
}
async beforeExecuteActionButton(clickParams) {}
async beforeExecuteActionButton(clickParams) {
if (clickParams.special !== "cancel" && this.model.root.editedRecord) {
return this.model.root.editedRecord.save();
}
}
async afterExecuteActionButton(clickParams) {}
}
@@ -245,7 +245,7 @@
className="button.className"
clickParams="button.clickParams"
defaultRank="button.defaultRank"
disabled="record.isVirtual || button.disabled"
disabled="button.disabled"
icon="button.icon"
record="record"
string="button.string"
@@ -7365,8 +7365,8 @@ QUnit.module("Views", (hooks) => {
);
assert.strictEqual(
target.querySelector(".o_list_button button").disabled,
true,
"buttons should be disabled while the record is not yet created"
false,
"buttons should not be disabled while the record is not yet created"
);
await clickSave(target);
@@ -7394,6 +7394,14 @@ QUnit.module("Views", (hooks) => {
<field name="foo"/>
<button string="abc" icon="fa-phone" type="object" name="schedule_another_phonecall"/>
</tree>`,
mockRPC(route, { method }) {
if (method === "create") {
assert.step("create");
} else if (route === "/web/dataset/call_button") {
assert.step("call_button");
return true;
}
},
});
await click(target.querySelector(".o_list_button_add"));
@@ -7403,6 +7411,16 @@ QUnit.module("Views", (hooks) => {
"table button i.o_button_icon.fa-phone",
"should have rendered a button"
);
assert.notOk(
target.querySelector("table button").disabled,
"button should not be disabled when creating the record"
);
await click(target, "table button");
assert.verifySteps(
["create", "call_button"],
"clicking the button should save the record and then execute the action"
);
});
QUnit.test("list view with a button without icon", async function (assert) {