[FIX] web: keep the possibility of creating a record with form view

Issue:
------
When a list view is editable and we add a `Group By`,
the create button in the header is no longer available.
This is annoying when we are working with default filters
and do not have any records.

Solution:
---------
Add the "New" button in the header of the list view
and redirect to the form view when we use it.

opw-3304692

closes odoo/odoo#126710

X-original-commit: 8332cca8926a8d032f921b39520227070303fcc5
Signed-off-by: Francois Georis (fge) <fge@odoo.com>
Signed-off-by: Thomas Lefebvre (thle) <thle@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-06-29 08:01:02 +02:00
parent 809029602e
commit cbcb712471
3 changed files with 47 additions and 6 deletions
@@ -202,7 +202,7 @@ export class ListController extends Component {
async createRecord({ group } = {}) {
const list = (group && group.list) || this.model.root;
if (this.editable) {
if (this.editable && !list.isGrouped) {
if (!(list instanceof DynamicRecordList)) {
throw new Error("List should be a DynamicRecordList");
}
@@ -5,7 +5,7 @@
<div t-att-class="className" t-ref="root">
<Layout className="model.useSampleModel ? 'o_view_sample_data' : ''" display="display">
<t t-set-slot="control-panel-create-button">
<t t-if="!model.root.editedRecord and activeActions.create and (!model.root.isGrouped or !editable) and !env.inDialog">
<t t-if="!model.root.editedRecord and activeActions.create and !env.inDialog">
<button type="button" class="btn btn-primary o_list_button_add" data-hotkey="c" t-on-click="onClickCreate" data-bounce-button="">
New
</button>
@@ -2861,10 +2861,10 @@ QUnit.module("Views", (hooks) => {
await toggleSearchBarMenu(target);
await toggleMenuItem(target, "candle");
assert.containsNone(
assert.containsOnce(
target,
".o_list_button_add",
"Create not available as list is grouped"
".o_list_button_add:visible",
"Create available as list is grouped"
);
assert.containsNone(
target,
@@ -2874,6 +2874,47 @@ QUnit.module("Views", (hooks) => {
}
);
QUnit.test(
"editable list view: check that add button is present when groupby applied",
async function (assert) {
assert.expect(4);
serverData.models.foo.fields.foo = { string: "Foo", type: "char", required: true };
serverData.actions = {
11: {
id: 11,
name: "Partners Action 11",
res_model: "foo",
type: "ir.actions.act_window",
views: [[3, "list"], [4, "form"]],
search_view_id: [9, "search"],
}
};
serverData.views = {
"foo,3,list":
'<tree editable="top"><field name="display_name"/><field name="foo"/></tree>',
"foo,4,form":
'<form><field name="display_name"/><field name="foo"/></form>',
"foo,9,search": `
<search>
<filter string="candle" name="itsName" context="{'group_by': 'foo'}"/>
</search>`,
};
const webClient = await createWebClient({ serverData });
await doAction(webClient, 11);
assert.containsOnce(target, ".o_list_button_add:visible");
await click(target.querySelector(".o_searchview_dropdown_toggler"));
await click($(target).find('.o_menu_item:contains("candle")')[0]);
assert.containsOnce(target, ".o_list_button_add:visible");
assert.containsOnce(target, ".o_list_view");
await click($(".o_list_button_add:visible").get(0));
assert.containsOnce(target, ".o_form_view");
}
);
QUnit.test("list view not groupable", async function (assert) {
serverData.views = {
"foo,false,search": `
@@ -13461,7 +13502,7 @@ QUnit.module("Views", (hooks) => {
await toggleSearchBarMenu(target);
await toggleMenuItem(target, "bar");
assert.containsNone(target, ".o_list_button_add");
assert.containsOnce(target, ".o_list_button_add:visible");
// reload without groupby
await toggleMenuItem(target, "bar");