[FIX] web: open record from list with a x2m field on virtual record

To reproduce
============
- On a project, on a task
- create a subtask give it a name and from the list view click on the
  "view" button
- you get redirected to form view to create a new task that is not related
to the parent task or the project

Problem
=======
When you click on the "view" button, the task is not saved yet, so the
subtask doesn't exist yet to be viewed in Form view

Solution
========
We prevent the redirection to the form view if the record is not saved yet
same logic as : https://github.com/odoo/odoo/commit/9b136383c2599301413e6770cc0ff204273b589d

opw-3681471

closes odoo/odoo#149753

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Abdelouahab (abla)
2024-01-31 13:47:07 +00:00
parent 54a1f89bda
commit af66512ea8
2 changed files with 29 additions and 1 deletions
@@ -272,7 +272,7 @@
<t t-if="props.onOpenFormView">
<td class="o_list_record_open_form_view text-center"
t-on-keydown="(ev) => this.onCellKeydown(ev, group, record)"
t-on-click.stop="() => props.onOpenFormView(record)"
t-on-click.stop="() => isX2Many and record.isNew ? this.displaySaveNotification() : props.onOpenFormView(record)"
tabindex="-1"
>
<button class="btn btn-link text-end"
@@ -13636,6 +13636,34 @@ QUnit.module("Views", (hooks) => {
}
);
QUnit.test(
"open form view action in x2many should display a notification if the record is virtual",
async (assert) => {
const notificationService = makeFakeNotificationService((msg, options) => {
assert.step(`${options.type}:${msg}`);
});
registry.category("services").add("notification", notificationService, { force: true });
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<field name="p">
<tree editable="bottom" open_form_view="1">
<field name="foo"/>
</tree>
</field>
</form>`,
});
await click(target.querySelector(".o_field_one2many .o_field_x2many_list_row_add a"));
await click(target.querySelector(".o_list_record_open_form_view"));
assert.verifySteps(['danger:Please click on the "save" button first']);
}
);
QUnit.test("prevent recreating a deleted record", async (assert) => {
serverData.models.partner.records.length = 1;