[FIX] web: discarding an existing record in form view action target new.

Do an action in target new that will spawn a record in its form view.
The typical example is "Edit View: XXX" in the debug systray.

On the dialog, click on "Discard".

Before this commit, that button did not close the dialog.

After this commit, that "Discard" button closes the dialog.

closes odoo/odoo#103275

X-original-commit: 08751e0eef0cefe74e626ffa8ba26a5e8f18113f
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Lucas Perais (lpe) <lpe@odoo.com>
This commit is contained in:
Lucas Perais
2022-10-18 13:17:06 +02:00
parent 4c224159b9
commit 62526a3546
2 changed files with 32 additions and 1 deletions
@@ -441,7 +441,7 @@ export class FormController extends Component {
if (this.props.onDiscard) {
this.props.onDiscard(this.model.root);
}
if (this.model.root.isVirtual) {
if (this.model.root.isVirtual || this.env.inDialog) {
this.env.config.historyBack();
}
}
@@ -2762,6 +2762,37 @@ QUnit.module("Views", (hooks) => {
assert.containsNone(target, ".o_dialog .o_form_view", "the dialog has been closed");
});
QUnit.test(
"form views in dialogs closes on discard on existing record",
async function (assert) {
serverData.models.partner.records[0].foo = undefined;
delete serverData.models.partner.fields.foo.default;
serverData.views = {
"partner,false,form": `
<form>
<field name="foo" required="1"/>
</form>`,
};
serverData.actions = {
1: {
id: 1,
name: "Partner",
res_model: "partner",
type: "ir.actions.act_window",
views: [[false, "form"]],
target: "new",
res_id: 1,
},
};
const webClient = await createWebClient({ serverData });
await doAction(webClient, 1);
assert.containsOnce(target, ".o_dialog .o_form_view", "the dialog has been opened");
await click(target.querySelector(".o_dialog .o_form_button_cancel"));
assert.containsNone(target, ".o_dialog .o_form_view", "the dialog has been closed");
}
);
QUnit.test("form views in dialogs do not have class o_xxl_form_view", async function (assert) {
const bus = new EventBus();
registry.category("services").add("ui", {