Debian Codegraph @

addons/web/static/tests/views/fields/one2many_field.test.js

raw
1 import { expect, getFixture, test } from "@odoo/hoot";
2 import {
3 click,
4 getNextFocusableElement,
5 press,
6 queryAll,
7 queryAllTexts,
8 queryFirst,
9 queryOne,
10 } from "@odoo/hoot-dom";
11 import { Deferred, animationFrame, mockTimeZone, runAllTimers } from "@odoo/hoot-mock";
12
13 import { onWillDestroy, onWillStart, reactive, useState } from "@odoo/owl";
14 import { getPickerCell } from "@web/../tests/core/datetime/datetime_test_helpers";
15 import {
16 clickFieldDropdown,
17 clickFieldDropdownItem,
18 clickSave,
19 contains,
20 defineModels,
21 fields,
22 getService,
23 makeServerError,
24 MockServer,
25 mockService,
26 models,
27 mountView,
28 mountViewInDialog,
29 mountWithCleanup,
30 onRpc,
31 patchWithCleanup,
32 selectFieldDropdownItem,
33 serverState,
34 } from "@web/../tests/web_test_helpers";
35 import { browser } from "@web/core/browser/browser";
36 import { registry } from "@web/core/registry";
37 import { pick } from "@web/core/utils/objects";
38 import { Record } from "@web/model/relational_model/record";
39 import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field";
40 import { WebClient } from "@web/webclient/webclient";
41
42 class Partner extends models.Model {
43 name = fields.Char();
44 foo = fields.Char({ default: "My little Foo Value" });
45 bar = fields.Boolean({ default: true });
46 int_field = fields.Integer();
47 qux = fields.Float({ string: "Qux", digits: [16, 1] });
48 p = fields.One2many({
49 string: "one2many field",
50 relation: "partner",
51 relation_field: "trululu",
52 });
53 turtles = fields.One2many({
54 string: "one2many turtle field",
55 relation: "turtle",
56 relation_field: "turtle_trululu",
57 });
58 trululu = fields.Many2one({ relation: "partner" });
59 timmy = fields.Many2many({ relation: "partner.type", string: "pokemon" });
60 product_id = fields.Many2one({ relation: "product" });
61 color = fields.Selection({
62 selection: [
63 ["red", "Red"],
64 ["black", "Black"],
65 ],
66 default: "red",
67 });
68 date = fields.Date();
69 datetime = fields.Datetime();
70 user_id = fields.Many2one({ relation: "res.users" });
71 reference = fields.Reference({
72 selection: [
73 ["product.product", "Product"],
74 ["partner.type", "Partner Type"],
75 ["partner", "Partner"],
76 ],
77 });
78
79 _records = [
80 {
81 id: 1,
82 name: "first record",
83 bar: true,
84 foo: "yop",
85 int_field: 10,
86 qux: 0.44,
87 p: [],
88 turtles: [2],
89 timmy: [],
90 trululu: 4,
91 user_id: 17,
92 },
93 {
94 id: 2,
95 name: "second record",
96 bar: true,
97 foo: "blip",
98 int_field: 9,
99 qux: 13,
100 p: [],
101 timmy: [],
102 trululu: 1,
103 product_id: 37,
104 date: "2017-01-25",
105 datetime: "2016-12-12 10:55:05",
106 user_id: 17,
107 },
108 {
109 id: 4,
110 name: "aaa",
111 bar: false,
112 },
113 ];
114 }
115
116 class Product extends models.Model {
117 _name = "product";
118
119 name = fields.Char();
120
121 _records = [
122 {
123 id: 37,
124 name: "xphone",
125 },
126 {
127 id: 41,
128 name: "xpad",
129 },
130 ];
131 }
132
133 class PartnerType extends models.Model {
134 color = fields.Integer({ string: "Color index" });
135 name = fields.Char();
136
137 _records = [
138 {
139 id: 12,
140 name: "gold",
141 color: 2,
142 },
143 {
144 id: 14,
145 name: "silver",
146 color: 5,
147 },
148 ];
149 }
150
151 class Turtle extends models.Model {
152 name = fields.Char();
153 turtle_foo = fields.Char();
154 turtle_bar = fields.Boolean({ default: true });
155 turtle_int = fields.Integer();
156 turtle_qux = fields.Float({
157 string: "Qux",
158 digits: [16, 1],
159 required: true,
160 default: 1.5,
161 });
162 turtle_description = fields.Text({ string: "Description" });
163 turtle_trululu = fields.Many2one({ relation: "partner" });
164 turtle_ref = fields.Reference({
165 selection: [
166 ["product", "Product"],
167 ["partner", "Partner"],
168 ],
169 });
170 product_id = fields.Many2one({ relation: "product", required: true });
171 partner_ids = fields.Many2many({ relation: "partner" });
172
173 _records = [
174 {
175 id: 1,
176 name: "leonardo",
177 turtle_bar: true,
178 turtle_foo: "yop",
179 partner_ids: [],
180 },
181 {
182 id: 2,
183 name: "donatello",
184 turtle_bar: true,
185 turtle_foo: "blip",
186 turtle_int: 9,
187 partner_ids: [2, 4],
188 },
189 {
190 id: 3,
191 name: "raphael",
192 product_id: 37,
193 turtle_bar: false,
194 turtle_foo: "kawa",
195 turtle_int: 21,
196 turtle_qux: 9.8,
197 partner_ids: [],
198 turtle_ref: "product,37",
199 },
200 ];
201 }
202
203 class Users extends models.Model {
204 _name = "res.users";
205
206 name = fields.Char();
207 partner_ids = fields.One2many({ relation: "partner", relation_field: "user_id" });
208
209 has_group() {
210 return true;
211 }
212
213 _records = [
214 {
215 id: 17,
216 name: "Aline",
217 partner_ids: [1, 2],
218 },
219 {
220 id: 19,
221 name: "Christine",
222 },
223 ];
224 }
225
226 defineModels([Partner, PartnerType, Product, Turtle, Users]);
227
228 test("New record with a o2m also with 2 new records, ordered, and resequenced", async () => {
229 // Needed to have two new records in a single stroke
230 Partner._onChanges = {
231 foo: function (obj) {
232 obj.p = [
233 [0, 0, { trululu: false }],
234 [0, 0, { trululu: false }],
235 ];
236 },
237 };
238
239 let startAssert = false;
240 onRpc((args) => {
241 if (startAssert) {
242 expect.step(args.method + " " + args.model);
243 }
244 });
245
246 await mountView({
247 type: "form",
248 resModel: "partner",
249 arch: `
250 <form>
251 <field name="foo"/>
252 <field name="p">
253 <list editable="bottom" default_order="int_field">
254 <field name="int_field" widget="handle"/>
255 <field name="trululu"/>
256 </list>
257 </field>
258 </form>`,
259 resId: 1,
260 });
261
262 startAssert = true;
263
264 await contains(".o_control_panel_main_buttons .o_form_button_create").click();
265
266 // change the int_field through drag and drop
267 // that way, we'll trigger the sorting and the name read
268 // of the lines of "p"
269 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop("tbody tr");
270
271 expect.verifySteps(["onchange partner"]);
272 });
273
274 test.tags("desktop");
275 test("resequence with NULL value", async () => {
276 mockService("action", {
277 doActionButton(params) {
278 params.onClose();
279 },
280 });
281 Partner._records.push(
282 { id: 10, int_field: 1 },
283 { id: 11, int_field: 2 },
284 { id: 12, int_field: 3 },
285 { id: 13 }
286 );
287 Partner._records[0].p = [10, 11, 12, 13];
288
289 const serverValues = {
290 10: 1,
291 11: 2,
292 12: 3,
293 13: false,
294 };
295
296 onRpc("web_read", function ({ parent }) {
297 const res = parent();
298 const getServerValue = (record) =>
299 serverValues[record.id] === false ? Number.MAX_SAFE_INTEGER : serverValues[record.id];
300
301 // when sorted, NULL values are last
302 res[0].p.sort((a, b) => getServerValue(a) - getServerValue(b));
303 return res;
304 });
305
306 onRpc("web_save", ({ args }) => {
307 args[1].p.forEach(([cmd, id, values]) => {
308 serverValues[id] = values.int_field;
309 });
310 });
311
312 await mountView({
313 type: "form",
314 resModel: "partner",
315 resId: 1,
316 arch: `
317 <form>
318 <sheet><div name="button_box">
319 <button name="reload" class="reload" type="object" string="Confirm"/>
320 </div></sheet>
321 <field name="foo"/>
322 <field name="p">
323 <list editable="bottom" default_order="int_field">
324 <field name="int_field" widget="handle"/>
325 <field name="id"/>
326 </list>
327 </field>
328 </form>`,
329 });
330
331 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["10", "11", "12", "13"]);
332
333 await contains("tbody tr:nth-child(4) .o_handle_cell").dragAndDrop("tbody tr:nth-child(3)");
334 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["10", "11", "13", "12"]);
335
336 await contains("button.reload").click();
337 expect(queryAllTexts(".o_field_cell[name=id]")).toEqual(["10", "11", "13", "12"]);
338 });
339
340 test.tags("desktop");
341 test("one2many in a list x2many editable use the right context", async () => {
342 onRpc("name_create", (args) => {
343 expect.step(`name_create ${args.kwargs.context.my_context}`);
344 });
345 await mountView({
346 type: "form",
347 resModel: "partner",
348 arch: `
349 <form>
350 <field name="p">
351 <list editable="bottom">
352 <field name="int_field" widget="handle"/>
353 <field name="trululu" context="{'my_context': 'list'}" />
354 </list>
355 <form>
356 <field name="trululu" context="{'my_context': 'form'}"/>
357 </form>
358 </field>
359 </form>`,
360 resId: 1,
361 });
362
363 await contains(".o_field_x2many_list .o_field_x2many_list_row_add a").click();
364 await contains("[name='trululu'] input").edit("new partner");
365 await selectFieldDropdownItem("trululu", 'Create "new partner"');
366
367 expect.verifySteps(["name_create list"]);
368 });
369
370 test.tags("desktop");
371 test("one2many in a list x2many non-editable use the right context", async () => {
372 onRpc("name_create", (args) => {
373 expect.step(`name_create ${args.kwargs.context.my_context}`);
374 });
375 await mountView({
376 type: "form",
377 resModel: "partner",
378 arch: `
379 <form>
380 <field name="p">
381 <list>
382 <field name="int_field" widget="handle"/>
383 <field name="trululu" context="{'my_context': 'list'}" />
384 </list>
385 <form>
386 <field name="trululu" context="{'my_context': 'form'}"/>
387 </form>
388 </field>
389 </form>`,
390 resId: 1,
391 });
392
393 await contains(".o_field_x2many_list .o_field_x2many_list_row_add a").click();
394 await contains("[name='trululu'] input").edit("new partner");
395 await selectFieldDropdownItem("trululu", 'Create "new partner"');
396
397 expect.verifySteps(["name_create form"]);
398 });
399
400 test("O2M field without relation_field", async () => {
401 delete Partner._fields.p.relation_field;
402
403 Partner._records[0].p = [2, 4];
404 await mountView({
405 type: "form",
406 resModel: "partner",
407 arch: `
408 <form>
409 <field name="p">
410 <list>
411 <field name="foo" invisible="1"/>
412 <field name="name" />
413 </list>
414 </field>
415 </form>`,
416 resId: 1,
417 });
418
419 await contains(".o_field_x2many_list .o_field_x2many_list_row_add a").click();
420 expect(".o_dialog").toHaveCount(1);
421 });
422
423 test("do not send context in unity spec if field is invisible", async () => {
424 expect.assertions(1);
425 onRpc("web_read", ({ kwargs }) => {
426 expect(kwargs.specification).toEqual({
427 display_name: {},
428 p: {},
429 });
430 });
431 await mountView({
432 type: "form",
433 resModel: "partner",
434 arch: `
435 <form>
436 <field name="p" invisible="1" context="{'x': 2}"/>
437 </form>`,
438 resId: 1,
439 });
440 });
441
442 test("O2M List with pager, decoration and default_order: add and cancel adding", async () => {
443 // The decoration on the list implies that its condition will be evaluated
444 // against the data of the field (actual records *displayed*)
445 // If one data is wrongly formed, it will crash
446 // This test adds then cancels a record in a paged, ordered, and decorated list
447 // That implies prefetching of records for sorting
448 // and evaluation of the decoration against *visible records*
449
450 Partner._records[0].p = [2, 4];
451 await mountView({
452 type: "form",
453 resModel: "partner",
454 arch: `
455 <form>
456 <field name="p">
457 <list editable="bottom" limit="1" decoration-muted="foo != False" default_order="name">
458 <field name="foo" invisible="1"/>
459 <field name="name" />
460 </list>
461 </field>
462 </form>`,
463 resId: 1,
464 });
465
466 await contains(".o_field_x2many_list .o_field_x2many_list_row_add a").click();
467
468 expect(".o_field_x2many_list .o_data_row").toHaveCount(2);
469
470 expect(queryOne(".o_selected_row")).toBe(queryOne(".o_field_x2many_list .o_data_row:eq(1)"), {
471 message: "The selected row should be the new one",
472 });
473
474 // Cancel Creation
475 await press("escape");
476 await animationFrame();
477 expect(".o_field_x2many_list .o_data_row").toHaveCount(1);
478 });
479
480 test.tags("desktop");
481 test("O2M with parented m2o and domain on parent.m2o", async () => {
482 // Records in an o2m can have a m2o pointing to themselves.
483 // In that case, a domain evaluation on that field followed by name_search
484 // shouldn't send virtual_ids to the server.
485
486 Turtle._fields.parent_id = fields.Many2one({
487 string: "Parent",
488 relation: "turtle",
489 });
490 Turtle._views = {
491 form: `
492 <form>
493 <field name="parent_id"/>
494 </form>`,
495 };
496 onRpc("web_name_search", ({ kwargs }) => {
497 expect(kwargs.domain).toEqual([["id", "in", []]]);
498 expect.step("web_name_search");
499 });
500 await mountView({
501 type: "form",
502 resModel: "partner",
503 arch: `
504 <form>
505 <field name="turtles">
506 <list>
507 <field name="parent_id"/>
508 </list>
509 <form>
510 <field name="parent_id" domain="[('id', 'in', parent.turtles)]"/>
511 </form>
512 </field>
513 </form>`,
514 });
515 await contains(".o_field_x2many_list_row_add a").click();
516 await clickFieldDropdown("parent_id");
517 // Only one web_name_search since empty search returns no result
518 expect.verifySteps(["web_name_search"]);
519 await contains(".o_field_widget[name=parent_id] input").edit("ABC", { confirm: false });
520 await runAllTimers();
521 await clickFieldDropdownItem("parent_id", "Create and edit...");
522
523 await contains(".o_dialog:not(.o_inactive_modal) .modal-footer .o_form_button_save").click();
524 await contains(".o_dialog:not(.o_inactive_modal) .o_form_button_save_new").click();
525
526 expect(".o_data_row").toHaveCount(1);
527
528 await contains(".o_field_many2one input").click();
529 });
530
531 test.tags("desktop");
532 test('O2M with buttons with attr "special" in dialog close the dialog', async () => {
533 await mountView({
534 type: "form",
535 resModel: "partner",
536 arch: `
537 <form>
538 <field name="p">
539 <list>
540 <field name="bar"/>
541 </list>
542 <form>
543 <field name="bar"/>
544 <footer>
545 <button special="cancel" data-hotkey="x" string="Cancel" class="btn-secondary"/>
546 </footer>
547 </form>
548 </field>
549 </form>`,
550 });
551
552 await contains(".o_field_x2many_list_row_add a").click();
553 expect(".o_dialog").toHaveCount(1);
554
555 expect(".modal .btn").toHaveText("Cancel");
556
557 await contains(".modal .btn").click();
558 expect(".o_dialog").toHaveCount(0);
559 });
560
561 test.tags("desktop");
562 test("O2M modal buttons are disabled on click", async () => {
563 // Records in an o2m can have a m2o pointing to themselves.
564 // In that case, a domain evaluation on that field followed by name_search
565 // shouldn't send virtual_ids to the server
566
567 Turtle._fields.parent_id = fields.Many2one({
568 string: "Parent",
569 relation: "turtle",
570 });
571 Turtle._views = {
572 form: `
573 <form>
574 <field name="parent_id"/>
575 </form>`,
576 };
577 const def = new Deferred();
578 onRpc("web_save", () => def);
579 await mountView({
580 type: "form",
581 resModel: "partner",
582 arch: `
583 <form>
584 <field name="turtles">
585 <list>
586 <field name="parent_id"/>
587 </list>
588 <form>
589 <field name="parent_id"/>
590 </form>
591 </field>
592 </form>`,
593 });
594
595 await contains(".o_field_x2many_list_row_add a").click();
596
597 await clickFieldDropdown("parent_id");
598 await contains(".o_field_widget[name=parent_id] input").edit("ABC", { confirm: false });
599 await runAllTimers();
600 await clickFieldDropdownItem("parent_id", "Create and edit...");
601 await contains(".o_dialog:not(.o_inactive_modal) .modal-footer .o_form_button_save").click();
602 expect(".o_dialog:not(.o_inactive_modal) .modal-footer .o_form_button_save").not.toBeEnabled();
603 def.resolve();
604 await animationFrame();
605 // close all dialogs
606 await contains(".o_dialog:not(.o_inactive_modal) .modal-footer .o_form_button_save").click();
607 await animationFrame();
608 expect(".o_dialog .o_form_view").toHaveCount(0);
609 });
610
611 test.tags("desktop");
612 test("clicking twice on a record in a one2many will open it once", async () => {
613 Turtle._views = {
614 form: `
615 <form>
616 <field name="turtle_foo"/>
617 </form>`,
618 };
619
620 const def = new Deferred();
621 let firstRead = true;
622 onRpc("turtle", "web_read", async ({ model }) => {
623 expect.step("web_read turtle");
624 if (!firstRead) {
625 await def;
626 }
627 firstRead = false;
628 });
629 await mountView({
630 type: "form",
631 resModel: "partner",
632 resId: 1,
633 arch: `
634 <form>
635 <field name="turtles">
636 <list>
637 <field name="name"/>
638 </list>
639 </field>
640 </form>`,
641 });
642 await contains(".o_data_cell").click();
643 await contains(".o_data_cell").click();
644 def.resolve();
645 await animationFrame();
646 expect(".modal").toHaveCount(1);
647
648 await contains(".modal .btn-close").click();
649 expect(".modal").toHaveCount(0);
650
651 await contains(".o_data_cell").click();
652 expect(".modal").toHaveCount(1);
653
654 expect.verifySteps(["web_read turtle"]);
655 });
656
657 test("resequence a x2m in a form view dialog from another x2m", async () => {
658 onRpc((args) => {
659 expect.step(args.method);
660 });
661 onRpc("write", (args) => {
662 expect(Object.keys(args.args[1])).toEqual(["turtles"]);
663 expect(args.args[1].turtles).toHaveLength(1);
664 expect(args.args[1].turtles[0]).toEqual([
665 1,
666 2,
667 {
668 partner_ids: [
669 [1, 2, { int_field: 0 }],
670 [1, 4, { int_field: 1 }],
671 ],
672 },
673 ]);
674 });
675 await mountView({
676 type: "form",
677 resModel: "partner",
678 resId: 1,
679 arch: `
680 <form>
681 <field name="turtles">
682 <list>
683 <field name="name"/>
684 </list>
685 <form>
686 <field name="partner_ids">
687 <list editable="top">
688 <field name="int_field" widget="handle"/>
689 <field name="name"/>
690 </list>
691 </field>
692 </form>
693 </field>
694 </form>`,
695 });
696 expect.verifySteps(["get_views", "web_read"]);
697
698 await contains(".o_data_cell").click();
699 expect(".modal").toHaveCount(1);
700 expect(queryAllTexts(".modal [name='name']")).toEqual(["aaa", "second record"]);
701 expect.verifySteps(["web_read"]);
702 await contains(".modal tr:eq(2) .o_handle_cell").dragAndDrop(".modal [name='name']:eq(0)");
703 expect(queryAllTexts(".modal [name='name']")).toEqual(["second record", "aaa"]);
704 expect.verifySteps([]);
705
706 await contains(".modal .o_form_button_save").click();
707 await clickSave();
708 expect.verifySteps(["web_save"]);
709 });
710
711 test("one2many list editable with cell readonly modifier", async () => {
712 expect.assertions(3);
713
714 Partner._records[0].p = [2];
715 Partner._records[1].turtles = [1, 2];
716 onRpc("web_save", (args) => {
717 expect(args.args[1].p[0][2]).toEqual(
718 { foo: "ff", qux: 99, turtles: [] },
719 { message: "The right values should be written" }
720 );
721 });
722 await mountView({
723 type: "form",
724 resModel: "partner",
725 arch: `
726 <form>
727 <field name="p">
728 <list editable="bottom">
729 <field name="turtles" invisible="1"/>
730 <field name="foo" readonly="turtles"/>
731 <field name="qux" readonly="turtles"/>
732 </list>
733 </field>
734 </form>`,
735 resId: 1,
736 });
737 await contains(".o_field_x2many_list_row_add a").click();
738
739 expect(".o_selected_row [name=foo] input").toBeFocused({
740 message: "The first input of the line should have the focus",
741 });
742
743 // Simulating hitting the 'f' key twice
744 await contains(".o_selected_row [name=foo] input").edit("f", { confirm: false });
745 await contains(".o_selected_row [name=foo] input").edit("ff", { confirm: false });
746
747 expect(".o_selected_row [name=foo] input").toBeFocused({
748 message: "The first input of the line should still have the focus",
749 });
750
751 // Simulating a TAB key
752 await press("Tab");
753 await animationFrame();
754 await contains(".o_selected_row [name=qux] input").edit(9, { confirm: false });
755 await contains(".o_selected_row [name=qux] input").edit(99);
756 await clickSave();
757 });
758
759 test("one2many wait for the onchange of the resequenced finish before save", async () => {
760 expect.assertions(2);
761
762 Partner._records[0].p = [1, 2];
763 Partner._onChanges = {
764 p: function (obj) {
765 obj.p = [[1, 2, { qux: 99 }]];
766 },
767 };
768 const def = new Deferred();
769 onRpc("onchange", async () => {
770 await def;
771 expect.step("onchange");
772 });
773 onRpc("web_save", (args) => {
774 expect.step("web_save");
775 expect(args.args[1].p).toEqual([
776 [1, 1, { int_field: 9 }],
777 [1, 2, { int_field: 10, qux: 99 }],
778 ]);
779 });
780 await mountView({
781 type: "form",
782 resModel: "partner",
783 arch: `
784 <form>
785 <field name="p">
786 <list>
787 <field name="int_field" widget="handle"/>
788 <field name="foo"/>
789 <field name="qux"/>
790 </list>
791 </field>
792 </form>`,
793 resId: 1,
794 });
795 // Drag and drop the second line in first position
796 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop("tbody tr");
797 await clickSave();
798
799 // resolve the onchange promise
800 def.resolve();
801 await animationFrame();
802 expect.verifySteps(["onchange", "web_save"]);
803 });
804
805 test("one2many basic properties", async () => {
806 Partner._records[0].p = [2];
807 onRpc((args) => {
808 expect.step(args.method);
809 });
810 await mountView({
811 type: "form",
812 resModel: "partner",
813 arch: `
814 <form>
815 <sheet>
816 <notebook>
817 <page string="Partner page">
818 <field name="p">
819 <list>
820 <field name="foo"/>
821 </list>
822 </field>
823 </page>
824 </notebook>
825 </sheet>
826 </form>`,
827 resId: 1,
828 });
829
830 expect.verifySteps(["get_views", "web_read"]);
831 expect(".o_field_x2many_list_row_add").toHaveCount(1);
832 expect(".o_field_x2many_list_row_add").toHaveAttribute("colspan", "2");
833 expect("td.o_list_record_remove").toHaveCount(1);
834 });
835
836 test("transferring class attributes in one2many sub fields", async () => {
837 await mountView({
838 type: "form",
839 resModel: "partner",
840 arch: `
841 <form>
842 <field name="turtles">
843 <list editable="bottom">
844 <field name="turtle_foo" class="hey"/>
845 </list>
846 </field>
847 </form>`,
848 resId: 1,
849 });
850 expect("td.hey").toHaveCount(1);
851
852 await contains("td.o_data_cell").click();
853 expect('td.hey div[name="turtle_foo"] input').toHaveCount(1); // WOWL to check! hey on input?
854 });
855
856 test("one2many with date and datetime", async () => {
857 mockTimeZone(+2);
858 Partner._records[0].p = [2];
859
860 await mountView({
861 type: "form",
862 resModel: "partner",
863 arch: `
864 <form>
865 <sheet>
866 <notebook>
867 <page string="Partner page">
868 <field name="p">
869 <list>
870 <field name="date"/>
871 <field name="datetime"/>
872 </list>
873 </field>
874 </page>
875 </notebook>
876 </sheet>
877 </form>`,
878 resId: 1,
879 });
880 expect("td:eq(0)").toHaveText("Jan 25, 2017");
881 expect("td:eq(1)").toHaveText("Dec 12, 2016, 12:55 PM");
882 });
883
884 test("rendering with embedded one2many", async () => {
885 Partner._records[0].p = [2];
886 await mountView({
887 type: "form",
888 resModel: "partner",
889 arch: `
890 <form>
891 <sheet>
892 <notebook>
893 <page string="P page">
894 <field name="p">
895 <list>
896 <field name="foo"/>
897 <field name="bar"/>
898 </list>
899 </field>
900 </page>
901 </notebook>
902 </sheet>
903 </form>`,
904 resId: 1,
905 });
906 expect("thead th:eq(0)").toHaveText("Foo");
907 expect("tbody td:eq(0)").toHaveText("blip");
908 });
909
910 test("use the limit attribute in arch (in field o2m inline list view)", async () => {
911 Partner._records[0].turtles = [1, 2, 3];
912 onRpc("turtle", (args) => {
913 expect(args.args[0]).toEqual([1, 2]);
914 });
915 await mountView({
916 type: "form",
917 resModel: "partner",
918 arch: `
919 <form>
920 <field name="turtles">
921 <list limit="2">
922 <field name="turtle_foo"/>
923 </list>
924 </field>
925 </form>`,
926 resId: 1,
927 });
928 expect(".o_data_row").toHaveCount(2);
929 });
930
931 test.tags("desktop");
932 test("delete all records in last page (in field o2m inline list view)", async () => {
933 Partner._records[0].turtles = [1, 2, 3];
934 await mountView({
935 type: "form",
936 resModel: "partner",
937 arch: `
938 <form>
939 <field name="turtles">
940 <list limit="2">
941 <field name="turtle_foo"/>
942 </list>
943 </field>
944 </form>`,
945 resId: 1,
946 });
947 expect(".o_data_row").toHaveCount(2);
948 expect(".o_x2m_control_panel .o_pager").toHaveText("1-2 / 3");
949 await contains(".o_x2m_control_panel .o_pager_next").click();
950 expect(".o_data_row").toHaveCount(1);
951 await contains(".o_list_record_remove").click();
952 expect(".o_x2m_control_panel .o_pager").toHaveCount(0);
953 expect(".o_data_row").toHaveCount(2);
954 await contains(".o_form_button_cancel").click();
955 expect(".o_x2m_control_panel .o_pager").toHaveText("1-2 / 3");
956 });
957
958 test("delete all records then repopulate", async () => {
959 Partner._records[0].turtles = [1];
960 await mountView({
961 type: "form",
962 resModel: "partner",
963 arch: `
964 <form>
965 <field name="turtles">
966 <list editable="bottom" default_order="turtle_int">
967 <field name="turtle_int" widget="handle"/>
968 <field name="turtle_foo"/>
969 </list>
970 </field>
971 </form>`,
972 resId: 1,
973 });
974 expect(".o_data_row").toHaveCount(1);
975 await contains(".o_list_record_remove").click();
976 expect(".o_data_row").toHaveCount(0);
977 await contains(".o_field_x2many_list_row_add a").click();
978 await contains(".o_field_one2many .o_list_renderer tbody input").edit("value 1", {
979 confirm: "blur",
980 });
981 expect(".o_data_row").toHaveCount(1);
982 await contains(".o_field_x2many_list_row_add a").click();
983 await contains(".o_field_one2many .o_list_renderer tbody input").edit("value 2", {
984 confirm: "blur",
985 });
986 expect(".o_data_row").toHaveCount(2);
987 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop("tbody tr");
988 expect(".o_data_row").toHaveCount(2);
989 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["value 2", "value 1"]);
990 });
991
992 test.tags("desktop");
993 test("nested x2manys with inline form, but not list", async () => {
994 Turtle._views = { list: `<list><field name="turtle_foo"/></list>` };
995 Partner._views = {
996 list: `<list><field name="foo"/></list>`,
997 };
998 await mountView({
999 type: "form",
1000 resModel: "partner",
1001 arch: `
1002 <form>
1003 <field name="turtles">
1004 <form>
1005 <field name="turtle_foo"/>
1006 <field name="partner_ids">
1007 <form>
1008 <field name="foo"/>
1009 </form>
1010 </field>
1011 </form>
1012 </field>
1013 </form>`,
1014 resId: 1,
1015 });
1016
1017 expect(".o_form_view").toHaveCount(1);
1018 expect(".o_data_row").toHaveCount(1);
1019
1020 await contains(".o_data_row .o_data_cell").click();
1021 expect(".o_dialog").toHaveCount(1);
1022 expect(".o_dialog .o_data_row").toHaveCount(2);
1023 });
1024
1025 test.tags("desktop");
1026 test("use the limit attribute in arch (in field o2m non inline list view)", async () => {
1027 Partner._records[0].turtles = [1, 2, 3];
1028 Turtle._views = { list: `<list limit="2"><field name="turtle_foo"/></list>` };
1029 onRpc((args) => {
1030 expect.step(args.method);
1031 });
1032 onRpc("web_read", (args) => {
1033 expect(args.kwargs.specification).toEqual({
1034 display_name: {},
1035 turtles: {
1036 fields: {
1037 turtle_foo: {},
1038 },
1039 limit: 2,
1040 },
1041 });
1042 });
1043 await mountView({
1044 type: "form",
1045 resModel: "partner",
1046 arch: `<form><field name="turtles" widget="one2many"/></form>`,
1047 resId: 1,
1048 });
1049 expect(".o_data_row").toHaveCount(2);
1050 expect.verifySteps(["get_views", "get_views", "web_read"]);
1051 });
1052
1053 test.tags("desktop");
1054 test("one2many with default_order on view not inline", async () => {
1055 Partner._records[0].turtles = [1, 2, 3];
1056 Turtle._views = {
1057 list: `
1058 <list default_order="turtle_foo">
1059 <field name="turtle_int"/>
1060 <field name="turtle_foo"/>
1061 </list>`,
1062 };
1063 await mountView({
1064 type: "form",
1065 resModel: "partner",
1066 arch: `
1067 <form>
1068 <sheet>
1069 <notebook>
1070 <page string="Turtles">
1071 <field name="turtles" widget="one2many"/>
1072 </page>
1073 </notebook>
1074 </sheet>
1075 </form>`,
1076 resId: 1,
1077 });
1078 expect(queryAllTexts(".o_field_one2many .o_data_cell")).toEqual([
1079 "9",
1080 "blip",
1081 "21",
1082 "kawa",
1083 "0",
1084 "yop",
1085 ]);
1086 });
1087
1088 test.tags("desktop");
1089 test("embedded one2many with widget", async () => {
1090 Partner._records[0].p = [2];
1091 await mountView({
1092 type: "form",
1093 resModel: "partner",
1094 arch: `
1095 <form>
1096 <sheet>
1097 <notebook>
1098 <page string="P page">
1099 <field name="p">
1100 <list>
1101 <field name="int_field" widget="handle"/>
1102 <field name="foo"/>
1103 </list>
1104 </field>
1105 </page>
1106 </notebook>
1107 </sheet>
1108 </form>`,
1109 resId: 1,
1110 });
1111
1112 expect("span.o_row_handle").toHaveCount(1);
1113 });
1114
1115 test.tags("desktop");
1116 test("embedded one2many with handle widget", async () => {
1117 Partner._records[0].turtles = [1, 2, 3];
1118 Partner._onChanges = {
1119 turtles: function () {},
1120 };
1121 onRpc("onchange", () => {
1122 expect.step("onchange");
1123 });
1124 await mountView({
1125 type: "form",
1126 resModel: "partner",
1127 arch: `
1128 <form>
1129 <field name="turtles">
1130 <list default_order="turtle_int">
1131 <field name="turtle_int" widget="handle"/>
1132 <field name="turtle_foo"/>
1133 </list>
1134 </field>
1135 </form>`,
1136 resId: 1,
1137 });
1138
1139 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["yop", "blip", "kawa"]);
1140
1141 // Drag and drop the second line in first position
1142 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop("tbody tr");
1143
1144 expect.verifySteps(["onchange"]);
1145
1146 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blip", "yop", "kawa"]);
1147
1148 await clickSave();
1149
1150 expect(MockServer.env["turtle"].map((r) => pick(r, "id", "turtle_foo", "turtle_int"))).toEqual([
1151 { id: 1, turtle_foo: "yop", turtle_int: 1 },
1152 { id: 2, turtle_foo: "blip", turtle_int: 0 },
1153 { id: 3, turtle_foo: "kawa", turtle_int: 21 },
1154 ]);
1155
1156 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blip", "yop", "kawa"]);
1157 });
1158
1159 test.tags("desktop");
1160 test("onchange for embedded one2many in a one2many", async () => {
1161 expect.assertions(3);
1162
1163 Turtle._fields.partner_ids = fields.One2many({ relation: "partner" });
1164 Turtle._records[0].partner_ids = [1];
1165 Partner._records[0].turtles = [1];
1166
1167 Partner._onChanges = {
1168 turtles: function (obj) {
1169 obj.turtles = [
1170 [
1171 1,
1172 1,
1173 {
1174 partner_ids: [[4, 2]],
1175 },
1176 ],
1177 ];
1178 },
1179 };
1180 onRpc("web_save", (args) => {
1181 expect(args.args[1].turtles).toEqual([
1182 [1, 1, { turtle_foo: "hop", partner_ids: [[4, 2]] }],
1183 ]);
1184 });
1185
1186 await mountView({
1187 type: "form",
1188 resModel: "partner",
1189 arch: `
1190 <form>
1191 <field name="turtles">
1192 <list editable="bottom">
1193 <field name="turtle_foo"/>
1194 <field name="partner_ids" widget="many2many_tags"/>
1195 </list>
1196 </field>
1197 </form>`,
1198 resId: 1,
1199 });
1200
1201 expect(".o_field_many2many_tags").toHaveText("first record");
1202
1203 await contains(".o_data_cell:eq(1)").click();
1204 await contains(".o_selected_row .o_field_widget[name=turtle_foo] input").edit("hop", {
1205 confirm: "blur",
1206 });
1207
1208 expect(".o_field_many2many_tags").toHaveText("first record\nsecond record");
1209
1210 await clickSave();
1211 });
1212
1213 test("onchange for embedded one2many in a one2many with a second page", async () => {
1214 Turtle._fields.partner_ids = fields.One2many({ relation: "partner" });
1215 Turtle._records[0].partner_ids = [1];
1216 // we need a second page, so we set two records and only display one per page
1217 Partner._records[0].turtles = [1, 2];
1218
1219 Partner._onChanges = {
1220 turtles: function (obj) {
1221 obj.turtles = [
1222 [
1223 1,
1224 1,
1225 {
1226 partner_ids: [[4, 2]],
1227 },
1228 ],
1229 [
1230 1,
1231 2,
1232 {
1233 turtle_foo: "blip",
1234 partner_ids: [[4, 1]],
1235 },
1236 ],
1237 ];
1238 },
1239 };
1240 onRpc("web_save", (args) => {
1241 expect(args.args[1].turtles).toEqual([
1242 [1, 1, { turtle_foo: "hop", partner_ids: [[4, 2]] }],
1243 [
1244 1,
1245 2,
1246 {
1247 partner_ids: [[4, 1]],
1248 turtle_foo: "blip",
1249 },
1250 ],
1251 ]);
1252 });
1253
1254 await mountView({
1255 type: "form",
1256 resModel: "partner",
1257 arch: `
1258 <form>
1259 <field name="turtles">
1260 <list editable="bottom" limit="1">
1261 <field name="turtle_foo"/>
1262 <field name="partner_ids" widget="many2many_tags"/>
1263 </list>
1264 </field>
1265 </form>`,
1266 resId: 1,
1267 });
1268
1269 await contains(".o_data_cell:eq(1)").click();
1270 await contains(".o_selected_row .o_field_widget[name=turtle_foo] input").edit("hop", {
1271 confirm: "blur",
1272 });
1273 await clickSave();
1274 });
1275
1276 test("onchange for embedded one2many in a one2many updated by server", async () => {
1277 // here we test that after an onchange, the embedded one2many field has
1278 // been updated by a new list of ids by the server response, to this new
1279 // list should be correctly sent back at save time
1280 expect.assertions(3);
1281
1282 Turtle._fields.partner_ids = fields.One2many({ relation: "partner" });
1283 Partner._records[0].turtles = [2];
1284 Turtle._records[1].partner_ids = [2];
1285
1286 Partner._onChanges = {
1287 turtles: function (obj) {
1288 obj.turtles = [
1289 [
1290 1,
1291 2,
1292 {
1293 partner_ids: [[4, 4]],
1294 },
1295 ],
1296 ];
1297 },
1298 };
1299 onRpc("web_save", (args) => {
1300 expect(args.args[1].turtles).toEqual(
1301 [
1302 [
1303 1,
1304 2,
1305 {
1306 partner_ids: [[4, 4]],
1307 turtle_foo: "hop",
1308 },
1309 ],
1310 ],
1311 {
1312 message: "The right values should be written",
1313 }
1314 );
1315 });
1316
1317 await mountView({
1318 type: "form",
1319 resModel: "partner",
1320 arch: `
1321 <form>
1322 <field name="turtles">
1323 <list editable="bottom">
1324 <field name="turtle_foo"/>
1325 <field name="partner_ids" widget="many2many_tags"/>
1326 </list>
1327 </field>
1328 </form>`,
1329 resId: 1,
1330 });
1331 expect(queryAllTexts(".o_data_cell.o_many2many_tags_cell .o_tag_badge_text")).toEqual([
1332 "second record",
1333 ]);
1334
1335 await contains(".o_data_cell:eq(1)").click();
1336 await contains(".o_selected_row [name=turtle_foo] input").edit("hop", {
1337 confirm: "blur",
1338 });
1339 await clickSave();
1340 expect(queryAllTexts(".o_data_cell.o_many2many_tags_cell .o_tag_badge_text")).toEqual([
1341 "second record",
1342 "aaa",
1343 ]);
1344 });
1345
1346 test("onchange for embedded one2many with handle widget", async () => {
1347 Partner._records[0].turtles = [1, 2, 3];
1348 let partnerOnchange = 0;
1349 Partner._onChanges = {
1350 turtles: function () {
1351 partnerOnchange++;
1352 },
1353 };
1354 let turtleOnchange = 0;
1355 Turtle._onChanges = {
1356 turtle_int: function () {
1357 turtleOnchange++;
1358 },
1359 };
1360
1361 await mountView({
1362 type: "form",
1363 resModel: "partner",
1364 arch: `
1365 <form>
1366 <field name="turtles">
1367 <list default_order="turtle_int">
1368 <field name="turtle_int" widget="handle"/>
1369 <field name="turtle_foo"/>
1370 </list>
1371 </field>
1372 </form>`,
1373 resId: 1,
1374 });
1375
1376 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["yop", "blip", "kawa"]);
1377 // Drag and drop the second line in first position
1378 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop("tbody tr");
1379
1380 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blip", "yop", "kawa"]);
1381 expect(turtleOnchange).toBe(2, { message: "should trigger one onchange per line updated" });
1382 expect(partnerOnchange).toBe(1, { message: "should trigger only one onchange on the parent" });
1383 });
1384
1385 test("onchange for embedded one2many with handle widget using same sequence", async () => {
1386 Turtle._records[0].turtle_int = 1;
1387 Turtle._records[1].turtle_int = 1;
1388 Turtle._records[2].turtle_int = 1;
1389 Partner._records[0].turtles = [1, 2, 3];
1390 let turtleOnchange = 0;
1391 Turtle._onChanges = {
1392 turtle_int: function () {
1393 turtleOnchange++;
1394 },
1395 };
1396
1397 onRpc("write", (args) => {
1398 expect(args.args[1].turtles).toEqual(
1399 [
1400 [1, 2, { turtle_int: 1 }],
1401 [1, 1, { turtle_int: 2 }],
1402 [1, 3, { turtle_int: 3 }],
1403 ],
1404 {
1405 message:
1406 "should change all lines that have changed (the first one doesn't change because it has the same sequence)",
1407 }
1408 );
1409 });
1410
1411 await mountView({
1412 type: "form",
1413 resModel: "partner",
1414 arch: `
1415 <form>
1416 <field name="turtles">
1417 <list default_order="turtle_int">
1418 <field name="turtle_int" widget="handle"/>
1419 <field name="turtle_foo"/>
1420 </list>
1421 </field>
1422 </form>`,
1423 resId: 1,
1424 });
1425
1426 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["yop", "blip", "kawa"]);
1427
1428 // Drag and drop the second line in first position
1429 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop("tbody tr");
1430
1431 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blip", "yop", "kawa"]);
1432 expect(turtleOnchange).toBe(3, { message: "should update all lines" });
1433
1434 await clickSave();
1435 });
1436
1437 test("onchange for embedded one2many with handle widget (more records)", async () => {
1438 const ids = [];
1439 for (let i = 10; i < 50; i++) {
1440 const id = 10 + i;
1441 ids.push(id);
1442 Turtle._records.push({
1443 id: id,
1444 turtle_int: 0,
1445 turtle_foo: "#" + id,
1446 });
1447 }
1448 ids.push(1, 2, 3);
1449 Partner._records[0].turtles = ids;
1450 Partner._onChanges = {
1451 turtles: function (obj) {},
1452 };
1453
1454 await mountView({
1455 type: "form",
1456 resModel: "partner",
1457 arch: `
1458 <form>
1459 <field name="turtles">
1460 <list editable="bottom" default_order="turtle_int">
1461 <field name="turtle_int" widget="handle"/>
1462 <field name="turtle_foo"/>
1463 </list>
1464 </field>
1465 </form>`,
1466 resId: 1,
1467 });
1468
1469 await contains("div[name=turtles] .o_pager_next").click();
1470
1471 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["yop", "blip", "kawa"]);
1472
1473 await contains(".o_data_cell.o_list_char").click();
1474 await contains('.o_list_renderer div[name="turtle_foo"] input').edit("blurp");
1475
1476 // Drag and drop the third line in second position
1477 // TODO JUM: PRHOOT the events
1478 const { drop, moveTo } = await contains("tbody tr:eq(2) .o_handle_cell").drag();
1479 await moveTo(`tbody tr:eq(1)`);
1480 await drop(document.body);
1481
1482 // need to unselect row...
1483 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blurp", "kawa", "blip"]);
1484
1485 await clickSave();
1486 await contains('div[name="turtles"] .o_pager_next').click();
1487
1488 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blurp", "kawa", "blip"]);
1489 });
1490
1491 test("onchange with modifiers for embedded one2many on the second page", async () => {
1492 const ids = [];
1493 for (let i = 10; i < 60; i++) {
1494 const id = 10 + i;
1495 ids.push(id);
1496 Turtle._records.push({
1497 id: id,
1498 turtle_int: 0,
1499 turtle_foo: "#" + id,
1500 });
1501 }
1502 ids.push(1, 2, 3);
1503 Partner._records[0].turtles = ids;
1504 Partner._onChanges = {
1505 turtles: function (obj) {},
1506 };
1507
1508 await mountView({
1509 type: "form",
1510 resModel: "partner",
1511 arch: `
1512 <form>
1513 <field name="turtles">
1514 <list editable="bottom" default_order="turtle_int" limit="10">
1515 <field name="turtle_int" widget="handle"/>
1516 <field name="turtle_foo"/>
1517 <field name="turtle_qux" readonly="not turtle_foo"/>
1518 </list>
1519 </field>
1520 </form>`,
1521 resId: 1,
1522 });
1523
1524 const getTurtleFooValues = () => queryAllTexts(".o_data_cell.o_list_char").join("");
1525
1526 expect(getTurtleFooValues()).toBe("#20#21#22#23#24#25#26#27#28#29");
1527
1528 await contains(".o_data_cell.o_list_char").click();
1529 await contains("div[name=turtle_foo] input").edit("blurp");
1530 // click outside of the one2many to unselect the row
1531 await contains(".o_form_view").click();
1532 expect(getTurtleFooValues()).toBe("blurp#21#22#23#24#25#26#27#28#29");
1533
1534 // the domain fail if the widget does not use the already loaded data.
1535 await contains(".o_form_button_cancel").click();
1536 expect(".modal").toHaveCount(0);
1537 expect(getTurtleFooValues()).toBe("#20#21#22#23#24#25#26#27#28#29");
1538
1539 // Drag and drop the third line in second position
1540 await contains("tbody tr:eq(2) .o_handle_cell").dragAndDrop("tbody tr:eq(1)");
1541 expect(getTurtleFooValues()).toBe("#20#30#31#32#33#34#35#36#37#38");
1542
1543 // Drag and drop the third line in second position
1544 await contains("tbody tr:eq(2) .o_handle_cell").dragAndDrop("tbody tr:eq(1)");
1545 expect(getTurtleFooValues()).toBe("#20#39#40#41#42#43#44#45#46#47");
1546
1547 await contains(".o_form_view").click();
1548 expect(getTurtleFooValues()).toBe("#20#39#40#41#42#43#44#45#46#47");
1549
1550 await contains(".o_form_button_cancel").click();
1551 expect(".modal").toHaveCount(0);
1552 expect(getTurtleFooValues()).toBe("#20#21#22#23#24#25#26#27#28#29");
1553 });
1554
1555 test("onchange followed by edition on the second page", async () => {
1556 const ids = [];
1557 for (let i = 1; i < 85; i++) {
1558 const id = 10 + i;
1559 ids.push(id);
1560 Turtle._records.push({
1561 id: id,
1562 turtle_int: (id / 3) | 0,
1563 turtle_foo: "#" + i,
1564 });
1565 }
1566 ids.splice(41, 0, 1, 2, 3);
1567 Partner._records[0].turtles = ids;
1568 Partner._onChanges = {
1569 turtles: function (obj) {},
1570 };
1571
1572 await mountView({
1573 type: "form",
1574 resModel: "partner",
1575 arch: `
1576 <form>
1577 <sheet>
1578 <group>
1579 <field name="turtles">
1580 <list editable="top" default_order="turtle_int">
1581 <field name="turtle_int" widget="handle"/>
1582 <field name="turtle_foo"/>
1583 </list>
1584 </field>
1585 </group>
1586 </sheet>
1587 </form>`,
1588 resId: 1,
1589 });
1590
1591 await contains(".o_field_widget[name=turtles] .o_pager_next").click();
1592
1593 await contains(".o_field_one2many .o_list_renderer tbody tr td.o_handle_cell:eq(1)").click();
1594 await contains('.o_field_one2many .o_list_renderer tbody div[name="turtle_foo"] input').edit(
1595 "value 1"
1596 );
1597 await contains(".o_field_one2many .o_list_renderer tbody tr td.o_handle_cell:eq(2)").click();
1598 await contains('.o_field_one2many .o_list_renderer tbody div[name="turtle_foo"] input').edit(
1599 "value 2"
1600 );
1601
1602 expect(".o_data_row").toHaveCount(40);
1603 expect(".o_field_one2many .o_list_renderer .o_data_cell.o_list_char:eq(0)").toHaveText("#39", {
1604 message: "should display '#39' at the first line",
1605 });
1606
1607 await contains(".o_field_x2many_list_row_add a").click();
1608
1609 expect(".o_data_row").toHaveCount(40, {
1610 message: "should display 39 records and the create line",
1611 });
1612
1613 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row", {
1614 message: "should display the create line in first position",
1615 });
1616 expect('.o_field_one2many .o_list_renderer tbody div[name="turtle_foo"]').toHaveText("", {
1617 message: "should be an empty input",
1618 });
1619 expect(".o_field_one2many .o_list_renderer .o_data_cell.o_list_char:eq(1)").toHaveText("#39");
1620
1621 await contains(".o_data_row input").edit("value 3", { confirm: "blur" });
1622
1623 expect(".o_data_row:eq(0)").toHaveClass(["o_data_row", "o_row_draggable"]);
1624 expect(".o_field_one2many .o_list_renderer .o_data_cell.o_list_char:eq(1)").toHaveText("#39");
1625
1626 await contains(".o_field_x2many_list_row_add a").click();
1627
1628 expect(".o_data_row").toHaveCount(40, {
1629 message: "should display 39 records and the create line",
1630 });
1631 expect(".o_field_one2many .o_list_renderer .o_data_cell.o_list_char:eq(1)").toHaveText(
1632 "value 3"
1633 );
1634 expect(".o_field_one2many .o_list_renderer .o_data_cell.o_list_char:eq(2)").toHaveText("#39");
1635 });
1636
1637 test("onchange followed by edition on the second page (part 2)", async () => {
1638 const ids = [];
1639 for (let i = 1; i < 85; i++) {
1640 const id = 10 + i;
1641 ids.push(id);
1642 Turtle._records.push({
1643 id: id,
1644 turtle_int: (id / 3) | 0,
1645 turtle_foo: "#" + i,
1646 });
1647 }
1648 ids.splice(41, 0, 1, 2, 3);
1649 Partner._records[0].turtles = ids;
1650 Partner._onChanges = {
1651 turtles: function (obj) {},
1652 };
1653
1654 // bottom order
1655
1656 await mountView({
1657 type: "form",
1658 resModel: "partner",
1659 arch: `
1660 <form>
1661 <sheet>
1662 <group>
1663 <field name="turtles">
1664 <list editable="bottom" default_order="turtle_int">
1665 <field name="turtle_int" widget="handle"/>
1666 <field name="turtle_foo"/>
1667 </list>
1668 </field>
1669 </group>
1670 </sheet>
1671 </form>`,
1672 resId: 1,
1673 });
1674
1675 await contains(".o_field_widget[name=turtles] .o_pager_next").click();
1676
1677 await contains(".o_field_one2many .o_list_renderer tbody tr td.o_handle_cell:eq(1)").click();
1678 await contains('.o_field_one2many .o_list_renderer tbody div[name="turtle_foo"] input').edit(
1679 "value 1",
1680 { confirm: "blur" }
1681 );
1682 await contains(".o_field_one2many .o_list_renderer tbody tr td.o_handle_cell:eq(2)").click();
1683 await contains('.o_field_one2many .o_list_renderer tbody div[name="turtle_foo"] input').edit(
1684 "value 2",
1685 { confirm: "blur" }
1686 );
1687
1688 expect(".o_data_row").toHaveCount(40, { message: "should display 40 records" });
1689 expect(".o_field_one2many .o_list_renderer tbody .o_data_cell.o_list_char:eq(0)").toHaveText(
1690 "#39",
1691 {
1692 message: "should display '#39' at the first line",
1693 }
1694 );
1695 expect(".o_field_one2many .o_list_renderer tbody .o_data_cell.o_list_char:eq(39)").toHaveText(
1696 "#77",
1697 { message: "should display '#77' at the last line" }
1698 );
1699
1700 await contains(".o_field_x2many_list_row_add a").click();
1701
1702 expect(".o_data_row").toHaveCount(41, {
1703 message: "should display 41 records and the create line",
1704 });
1705 expect(".o_field_one2many .o_list_renderer tbody .o_data_cell.o_list_char:eq(39)").toHaveText(
1706 "#77",
1707 { message: "should display '#77' at the penultimate line" }
1708 );
1709 expect(".o_data_row:eq(40)").toHaveClass("o_selected_row", {
1710 message: "should display the create line in first position",
1711 });
1712
1713 await contains('.o_field_one2many .o_list_renderer tbody div[name="turtle_foo"] input').edit(
1714 "value 3",
1715 { confirm: "blur" }
1716 );
1717 await contains(".o_field_x2many_list_row_add a").click();
1718
1719 expect(".o_data_row").toHaveCount(42, {
1720 message: "should display 42 records and the create line",
1721 });
1722 expect(".o_field_one2many .o_list_renderer tbody .o_data_cell.o_list_char:eq(40)").toHaveText(
1723 "value 3"
1724 );
1725 expect(".o_field_one2many .o_list_renderer tbody .o_data_cell.o_list_char:eq(41)").toHaveText(
1726 ""
1727 );
1728 expect(".o_data_row:eq(41)").toHaveClass("o_selected_row", {
1729 message: "should display the create line in first position",
1730 });
1731 });
1732
1733 test("onchange returning a commands 4 for an x2many", async () => {
1734 Partner._onChanges = {
1735 foo(obj) {
1736 obj.turtles = [
1737 [4, 1],
1738 [4, 3],
1739 ];
1740 },
1741 };
1742
1743 await mountView({
1744 type: "form",
1745 resModel: "partner",
1746 arch: `
1747 <form>
1748 <field name="foo"/>
1749 <field name="turtles">
1750 <list>
1751 <field name="turtle_foo"/>
1752 </list>
1753 </field>
1754 </form>`,
1755 resId: 1,
1756 });
1757
1758 expect(".o_data_row").toHaveCount(1);
1759
1760 // change the value of foo to trigger the onchange
1761 await contains(".o_field_widget[name=foo] input").edit("some value");
1762 expect(".o_data_row").toHaveCount(3);
1763 });
1764
1765 test("x2many fields inside x2manys are fetched after an onchange", async () => {
1766 expect.assertions(5);
1767
1768 Turtle._records[0].partner_ids = [1];
1769 Partner._onChanges = {
1770 foo: function (obj) {
1771 obj.turtles = [
1772 [3, 2],
1773 [4, 1],
1774 [4, 2],
1775 [4, 3],
1776 ];
1777 },
1778 };
1779
1780 onRpc("onchange", (args) => {
1781 expect(args.args[3]).toEqual({
1782 // spec
1783 display_name: {},
1784 foo: {},
1785 turtles: {
1786 fields: {
1787 partner_ids: {
1788 fields: {
1789 display_name: {},
1790 },
1791 },
1792 turtle_foo: {},
1793 },
1794 limit: 40,
1795 },
1796 });
1797 });
1798
1799 await mountView({
1800 type: "form",
1801 resModel: "partner",
1802 arch: `
1803 <form>
1804 <sheet>
1805 <group>
1806 <field name="foo"/>
1807 <field name="turtles">
1808 <list>
1809 <field name="turtle_foo"/>
1810 <field name="partner_ids" widget="many2many_tags"/>
1811 </list>
1812 </field>
1813 </group>
1814 </sheet>
1815 </form>`,
1816 resId: 1,
1817 });
1818
1819 expect(".o_data_row").toHaveCount(1);
1820 expect(".o_data_row .o_field_widget[name=partner_ids]").toHaveText("second record\naaa");
1821
1822 // change the value of foo to trigger the onchange
1823 await contains(".o_field_widget[name=foo] input").edit("some value");
1824
1825 expect(".o_data_row").toHaveCount(3, {
1826 message: "there should be three records in the relation",
1827 });
1828 expect(".o_data_row .o_field_widget[name=partner_ids]:eq(0)").toHaveText("first record");
1829 });
1830
1831 test("reference fields inside x2manys are fetched after an onchange", async () => {
1832 expect.assertions(4);
1833
1834 Turtle._records[1].turtle_ref = "product,41";
1835 Partner._onChanges = {
1836 foo: function (obj) {
1837 obj.turtles = [
1838 [4, 1],
1839 [4, 3],
1840 ];
1841 },
1842 };
1843
1844 await mountView({
1845 type: "form",
1846 resModel: "partner",
1847 arch: `
1848 <form>
1849 <sheet>
1850 <group>
1851 <field name="foo"/>
1852 <field name="turtles">
1853 <list>
1854 <field name="turtle_foo"/>
1855 <field name="turtle_ref" class="ref_field"/>
1856 </list>
1857 </field>
1858 </group>
1859 </sheet>
1860 </form>`,
1861 resId: 1,
1862 });
1863
1864 expect(".o_data_row").toHaveCount(1);
1865 expect(queryAllTexts(".ref_field")).toEqual(["xpad"]);
1866
1867 // change the value of foo to trigger the onchange
1868 await contains(".o_field_widget[name=foo] input").edit("some value");
1869
1870 expect(".o_data_row").toHaveCount(3);
1871 expect(queryAllTexts(".ref_field")).toEqual(["xpad", "", "xphone"]);
1872 });
1873
1874 test.tags("desktop");
1875 test("onchange on one2many containing x2many in form view", async () => {
1876 Partner._onChanges = {
1877 foo: function (obj) {
1878 obj.turtles = [[0, false, { turtle_foo: "new record" }]];
1879 },
1880 };
1881 Partner._views = {
1882 list: '<list><field name="foo"/></list>',
1883 };
1884
1885 await mountView({
1886 type: "form",
1887 resModel: "partner",
1888 arch: `
1889 <form>
1890 <field name="foo"/>
1891 <field name="turtles">
1892 <list>
1893 <field name="turtle_foo"/>
1894 </list>
1895 <form>
1896 <field name="partner_ids">
1897 <list editable="top">
1898 <field name="foo"/>
1899 </list>
1900 </field>
1901 </form>
1902 </field>
1903 </form>`,
1904 });
1905
1906 expect(".o_data_row").toHaveCount(1, {
1907 message: "the onchange should have created one record in the relation",
1908 });
1909
1910 // open the created o2m record in a form view, and add a m2m subrecord
1911 // in its relation
1912 await contains(".o_data_row .o_data_cell").click();
1913
1914 expect(".modal").toHaveCount(1);
1915 expect(".modal .o_data_row").toHaveCount(0);
1916
1917 // add a many2many subrecord
1918 await contains(".modal .o_field_x2many_list_row_add a").click();
1919
1920 expect(".modal").toHaveCount(2, { message: "should have opened a second dialog" });
1921
1922 // select a many2many subrecord
1923 await contains(".modal:eq(1) .o_list_view .o_data_cell").click();
1924
1925 expect(".modal").toHaveCount(1);
1926 expect(".modal .o_data_row").toHaveCount(1);
1927 expect(".modal .o_x2m_control_panel .o_pager").toHaveCount(0, {
1928 message: "m2m pager should be hidden",
1929 });
1930
1931 // click on 'Save & Close'
1932 await contains(".modal-footer .btn-primary").click();
1933
1934 expect(".modal").toHaveCount(0, { message: "dialog should be closed" });
1935
1936 // reopen o2m record, and another m2m subrecord in its relation, but
1937 // discard the changes
1938 await contains(".o_data_row .o_data_cell").click();
1939
1940 expect(".modal").toHaveCount(1);
1941 expect(".modal .o_data_row").toHaveCount(1);
1942
1943 // add another m2m subrecord
1944 await contains(".modal .o_field_x2many_list_row_add a").click();
1945
1946 expect(".modal").toHaveCount(2, { message: "should have opened a second dialog" });
1947
1948 await contains(".modal:eq(1) .o_list_view .o_data_cell").click();
1949
1950 expect(".modal").toHaveCount(1, { message: "second dialog should be closed" });
1951 expect(".modal .o_data_row").toHaveCount(2, {
1952 message: "there should be two records in the one2many in the dialog",
1953 });
1954
1955 // click on 'Discard'
1956 await contains(".modal-footer .btn-secondary").click();
1957
1958 expect(".modal").toHaveCount(0, { message: "dialog should be closed" });
1959
1960 // reopen o2m record to check that second changes have properly been discarded
1961 await contains(".o_data_row .o_data_cell").click();
1962
1963 expect(".modal").toHaveCount(1);
1964 expect(".modal .o_data_row").toHaveCount(1);
1965 });
1966
1967 test.tags("desktop");
1968 test("onchange on one2many with x2many in list (no widget) and form view (list)", async () => {
1969 expect.assertions(7);
1970 Turtle._fields.turtle_foo = fields.Char({ default: "a default value" });
1971 Partner._onChanges = {
1972 foo: function (obj) {
1973 obj.p = [[0, false, { turtles: [[0, false, { turtle_foo: "hello" }]] }]];
1974 },
1975 };
1976 onRpc("partner", "onchange", ({ args }) => {
1977 expect(args[3]).toEqual({
1978 display_name: {},
1979 foo: {},
1980 p: {
1981 fields: {
1982 turtles: {
1983 fields: {
1984 turtle_foo: {},
1985 },
1986 },
1987 },
1988 limit: 40,
1989 },
1990 });
1991 });
1992
1993 await mountView({
1994 type: "form",
1995 resModel: "partner",
1996 arch: `
1997 <form>
1998 <field name="foo"/>
1999 <field name="p">
2000 <list>
2001 <field name="turtles"/>
2002 </list>
2003 <form>
2004 <field name="turtles">
2005 <list editable="top">
2006 <field name="turtle_foo"/>
2007 </list>
2008 </field>
2009 </form>
2010 </field>
2011 </form>`,
2012 });
2013
2014 expect(".o_data_row").toHaveCount(1, {
2015 message: "the onchange should have created one record in the relation",
2016 });
2017
2018 // open the created o2m record in a form view
2019 await contains(".o_data_row .o_data_cell").click();
2020
2021 expect(".modal").toHaveCount(1);
2022 expect(".modal .o_data_row").toHaveCount(1);
2023 expect(".modal .o_data_row").toHaveText("hello");
2024
2025 // add a one2many subrecord and check if the default value is correctly applied
2026 await contains(".modal .o_field_x2many_list_row_add a").click();
2027
2028 expect(".modal .o_data_row").toHaveCount(2);
2029 expect(".modal .o_data_row .o_field_widget[name=turtle_foo] input").toHaveValue(
2030 "a default value"
2031 );
2032 });
2033
2034 test("save an o2m dialog form view and discard main form view", async () => {
2035 await mountView({
2036 type: "form",
2037 resModel: "partner",
2038 resId: 1,
2039 arch: `
2040 <form>
2041 <field name="turtles">
2042 <list>
2043 <field name="name"/>
2044 </list>
2045 <form>
2046 <field name="name"/>
2047 </form>
2048 </field>
2049 </form>`,
2050 });
2051
2052 expect(".o_data_row").toHaveCount(1);
2053 expect(".o_data_row [name='name']").toHaveText("donatello");
2054
2055 await contains(".o_data_row .o_data_cell").click();
2056 expect(".modal [name='name'] input").toHaveValue("donatello");
2057
2058 await contains(".modal [name='name'] input").edit("leonardo");
2059 await contains(".modal .o_form_button_save").click();
2060 expect(".modal").toHaveCount(0);
2061 expect(".o_data_row [name='name']").toHaveText("leonardo");
2062
2063 await contains(".o_data_row .o_data_cell").click();
2064 await contains(".modal .o_form_button_cancel").click();
2065 expect(".o_data_row [name='name']").toHaveText("leonardo");
2066
2067 await contains(".o_form_button_cancel").click();
2068 expect(".o_data_row [name='name']").toHaveText("donatello");
2069
2070 await contains(".o_data_row .o_data_cell").click();
2071 expect(".modal [name='name'] input").toHaveValue("donatello");
2072 });
2073
2074 test("discard with nested o2m form view dialog", async () => {
2075 Partner._records[0].p = [2];
2076 Partner._records[1].p = [4];
2077
2078 await mountView({
2079 type: "form",
2080 resModel: "partner",
2081 resId: 1,
2082 arch: `
2083 <form>
2084 <field name="name"/>
2085 <field name="p">
2086 <list>
2087 <field name="name"/>
2088 </list>
2089 <form>
2090 <field name="name"/>
2091 <field name="p">
2092 <list>
2093 <field name="name"/>
2094 </list>
2095 <form>
2096 <field name="name"/>
2097 </form>
2098 </field>
2099 </form>
2100 </field>
2101 </form>`,
2102 });
2103
2104 expect(".o_data_row").toHaveCount(1);
2105 expect(".o_data_row [name='name']").toHaveText("second record");
2106
2107 await contains(".o_data_row .o_data_cell").click();
2108 expect("#dialog_0 [name='name'] input").toHaveValue("second record");
2109
2110 await contains("#dialog_0 .o_data_row .o_data_cell").click();
2111 expect("#dialog_1 [name='name'] input").toHaveValue("aaa");
2112
2113 await contains("#dialog_1 [name='name'] input").edit("leonardo");
2114 await contains("#dialog_1 .o_form_button_save").click();
2115 expect("#dialog_1").toHaveCount(0);
2116 expect("#dialog_0 .o_data_row [name='name']").toHaveText("leonardo");
2117
2118 await contains("#dialog_0 .o_data_row .o_data_cell").click();
2119 expect("#dialog_2 [name='name'] input").toHaveValue("leonardo");
2120 await contains("#dialog_2 .o_form_button_cancel").click();
2121 await contains("#dialog_0 .o_form_button_cancel").click();
2122 await contains(".o_data_row .o_data_cell").click();
2123 expect(".modal .o_data_row [name='name']").toHaveText("aaa");
2124 });
2125
2126 test("discard a form dialog view and then reopen it with a domain based on a text field", async () => {
2127 Turtle._records[1].turtle_foo = "yop";
2128 Turtle._views = {
2129 form: `
2130 <form>
2131 <field name="name" invisible="turtle_foo == 'yop'"/>
2132 <field name="turtle_foo"/>
2133 </form>`,
2134 };
2135
2136 await mountView({
2137 type: "form",
2138 resModel: "partner",
2139 resId: 1,
2140 arch: `
2141 <form>
2142 <field name="name"/>
2143 <field name="turtles">
2144 <list>
2145 <field name="name"/>
2146 </list>
2147 </field>
2148 </form>`,
2149 });
2150
2151 expect(".o_data_row").toHaveCount(1);
2152 expect(".o_data_row [name='name']").toHaveText("donatello");
2153
2154 await contains(".o_data_row .o_data_cell").click();
2155 expect(".modal [name='name']").toHaveCount(0);
2156 expect(".modal [name='turtle_foo'] input").toHaveValue("yop");
2157
2158 await contains(".modal [name='turtle_foo'] input").edit("display");
2159 expect(".modal [name='name'] input").toHaveValue("donatello");
2160 expect(".modal [name='turtle_foo'] input").toHaveValue("display");
2161
2162 await contains(".modal .o_form_button_save").click();
2163 await contains(".o_form_button_cancel").click();
2164 await contains(".o_data_row .o_data_cell").click();
2165 expect(".modal [name='name']").toHaveCount(0);
2166 expect(".modal [name='turtle_foo'] input").toHaveValue("yop");
2167 });
2168
2169 test("onchange on one2many with x2many in list (many2many_tags) and form view (list)", async () => {
2170 expect.assertions(7);
2171 Turtle._fields.turtle_foo = fields.Char({ default: "a default value" });
2172 Partner._onChanges = {
2173 foo: function (obj) {
2174 obj.p = [[0, false, { turtles: [[0, false, { turtle_foo: "hello" }]] }]];
2175 },
2176 };
2177 onRpc("partner", "onchange", ({ args }) => {
2178 expect(args[3]).toEqual({
2179 display_name: {},
2180 foo: {},
2181 p: {
2182 fields: {
2183 turtles: {
2184 fields: {
2185 display_name: {},
2186 turtle_foo: {},
2187 },
2188 },
2189 },
2190 limit: 40,
2191 },
2192 });
2193 });
2194 await mountView({
2195 type: "form",
2196 resModel: "partner",
2197 arch: `
2198 <form>
2199 <field name="foo"/>
2200 <field name="p">
2201 <list>
2202 <field name="turtles" widget="many2many_tags"/>
2203 </list>
2204 <form>
2205 <field name="turtles">
2206 <list editable="top">
2207 <field name="turtle_foo"/>
2208 </list>
2209 </field>
2210 </form>
2211 </field>
2212 </form>`,
2213 });
2214
2215 expect(".o_data_row").toHaveCount(1, {
2216 message: "the onchange should have created one record in the relation",
2217 });
2218
2219 // open the created o2m record in a form view
2220 await contains(".o_data_row .o_data_cell").click();
2221
2222 expect(".modal").toHaveCount(1);
2223 expect(".modal .o_data_row").toHaveCount(1);
2224 expect(".modal .o_data_row").toHaveText("hello");
2225
2226 // add a one2many subrecord and check if the default value is correctly applied
2227 await contains(".modal .o_field_x2many_list_row_add a").click();
2228
2229 expect(".modal .o_data_row").toHaveCount(2);
2230 expect(".modal .o_data_row .o_field_widget[name=turtle_foo] input").toHaveValue(
2231 "a default value"
2232 );
2233 });
2234
2235 test("embedded one2many with handle widget with minimum setValue calls", async () => {
2236 Turtle._records[0].turtle_int = 6;
2237 Turtle._records.push(
2238 {
2239 id: 4,
2240 turtle_int: 20,
2241 turtle_foo: "a1",
2242 },
2243 {
2244 id: 5,
2245 turtle_int: 9,
2246 turtle_foo: "a2",
2247 },
2248 {
2249 id: 6,
2250 turtle_int: 2,
2251 turtle_foo: "a3",
2252 },
2253 {
2254 id: 7,
2255 turtle_int: 11,
2256 turtle_foo: "a4",
2257 }
2258 );
2259 Partner._records[0].turtles = [1, 2, 3, 4, 5, 6, 7];
2260
2261 patchWithCleanup(Record.prototype, {
2262 _update() {
2263 if (this.resModel === "turtle") {
2264 expect.step(`${this.resId}`);
2265 }
2266 return super._update(...arguments);
2267 },
2268 });
2269
2270 await mountView({
2271 type: "form",
2272 resModel: "partner",
2273 arch: `
2274 <form>
2275 <field name="turtles">
2276 <list default_order="turtle_int">
2277 <field name="turtle_int" widget="handle"/>
2278 <field name="turtle_foo"/>
2279 </list>
2280 </field>
2281 </form>`,
2282 resId: 1,
2283 });
2284
2285 expect(queryAllTexts(".o_data_row [name='turtle_foo']")).toEqual([
2286 "a3",
2287 "yop",
2288 "blip",
2289 "a2",
2290 "a4",
2291 "a1",
2292 "kawa",
2293 ]);
2294
2295 const positions = [
2296 [6, 0, ["3", "6", "1", "2", "5", "7", "4"]], // move the last to the first line
2297 [5, 1, ["7", "6", "1", "2", "5"]], // move the penultimate to the second line
2298 [2, 5, ["1", "2", "5", "6"]], // move the third to the penultimate line
2299 ];
2300 for (const [sourceIndex, targetIndex, steps] of positions) {
2301 await contains(`tbody tr:eq(${sourceIndex}) .o_handle_cell`).dragAndDrop(
2302 `tbody tr:eq(${targetIndex})`
2303 );
2304 expect.verifySteps(steps);
2305 }
2306
2307 expect(queryAllTexts(".o_data_row [name='turtle_foo']")).toEqual([
2308 "kawa",
2309 "a4",
2310 "yop",
2311 "blip",
2312 "a2",
2313 "a3",
2314 "a1",
2315 ]);
2316 });
2317
2318 test("embedded one2many (editable list) with handle widget", async () => {
2319 Partner._records[0].p = [1, 2, 4];
2320 onRpc("web_save", (args) => {
2321 expect.step(args.method);
2322 expect(args.args[1].p).toEqual([
2323 [1, 2, { int_field: 0 }],
2324 [1, 4, { int_field: 1 }],
2325 ]);
2326 });
2327 await mountView({
2328 type: "form",
2329 resModel: "partner",
2330 arch: `
2331 <form>
2332 <field name="p">
2333 <list editable="top">
2334 <field name="int_field" widget="handle"/>
2335 <field name="foo"/>
2336 </list>
2337 </field>
2338 </form>`,
2339 resId: 1,
2340 });
2341
2342 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual([
2343 "My little Foo Value",
2344 "blip",
2345 "yop",
2346 ]);
2347
2348 expect.verifySteps([]);
2349
2350 // Drag and drop the second line in first position
2351 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop(".o_field_one2many tbody tr:eq(0)");
2352
2353 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual([
2354 "blip",
2355 "My little Foo Value",
2356 "yop",
2357 ]);
2358
2359 await contains(".o_data_cell.o_list_char").click();
2360
2361 expect(".o_field_widget[name=foo] input").toHaveValue("blip");
2362
2363 expect.verifySteps([]);
2364
2365 await clickSave();
2366
2367 expect.verifySteps(["web_save"]);
2368 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual([
2369 "blip",
2370 "My little Foo Value",
2371 "yop",
2372 ]);
2373 });
2374
2375 test("one2many list order with handle widget", async () => {
2376 onRpc("web_read", (args) => {
2377 expect.step(`web_read`);
2378 expect(args.kwargs.specification.p.order).toBe("int_field ASC, id ASC");
2379 });
2380 await mountView({
2381 type: "form",
2382 resModel: "partner",
2383 arch: `
2384 <form>
2385 <field name="p">
2386 <list editable="top">
2387 <field name="int_field" widget="handle"/>
2388 <field name="foo"/>
2389 </list>
2390 </field>
2391 </form>`,
2392 resId: 1,
2393 });
2394 expect.verifySteps(["web_read"]);
2395 });
2396
2397 test("one2many kanban order with handle widget", async () => {
2398 onRpc("web_read", (args) => {
2399 expect.step(`web_read`);
2400 expect(args.kwargs.specification.p.order).toBe("int_field ASC, id ASC");
2401 });
2402 await mountView({
2403 type: "form",
2404 resModel: "partner",
2405 arch: `
2406 <form>
2407 <field name="p">
2408 <kanban>
2409 <field name="int_field" widget="handle"/>
2410 <templates>
2411 <t t-name="card">
2412 <field name="foo"/>
2413 </t>
2414 </templates>
2415 </kanban>
2416 </field>
2417 </form>`,
2418 resId: 1,
2419 });
2420 expect.verifySteps(["web_read"]);
2421 });
2422
2423 test("one2many field when using the pager", async () => {
2424 const ids = [];
2425 for (let i = 0; i < 45; i++) {
2426 const id = 10 + i;
2427 ids.push(id);
2428 Partner._records.push({
2429 id,
2430 name: `relational record ${id}`,
2431 });
2432 }
2433 Partner._records[0].p = ids.slice(0, 42);
2434 Partner._records[1].p = ids.slice(42);
2435
2436 onRpc("web_read", (args) => {
2437 expect.step(`unity read ${args.args[0]}`);
2438 });
2439
2440 await mountView({
2441 type: "form",
2442 resModel: "partner",
2443 arch: `
2444 <form>
2445 <field name="p">
2446 <kanban>
2447 <templates>
2448 <t t-name="card">
2449 <field name="name"/>
2450 </t>
2451 </templates>
2452 </kanban>
2453 </field>
2454 </form>`,
2455 resId: 1,
2456 resIds: [1, 2],
2457 });
2458
2459 expect.verifySteps(["unity read 1"]);
2460 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40);
2461
2462 // move to record 2, which has 3 related records (and shouldn't contain the
2463 // related records of record 1 anymore)
2464 await contains(".o_form_view .o_control_panel .o_pager_next").click();
2465 expect.verifySteps(["unity read 2"]);
2466 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(3);
2467
2468 // move back to record 1, which should contain again its first 40 related
2469 // records
2470 await contains(".o_form_view .o_control_panel .o_pager_previous").click();
2471 expect.verifySteps(["unity read 1"]);
2472 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40);
2473
2474 // move to the second page of the o2m: 1 RPC should have been done to fetch
2475 // the 2 subrecords of page 2, and those records should now be displayed
2476 await contains(".o_x2m_control_panel .o_pager_next").click();
2477 expect.verifySteps(["unity read 50,51"]);
2478 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(2);
2479
2480 // move to record 2 again and check that everything is correctly updated
2481 await contains(".o_form_view .o_control_panel .o_pager_next").click();
2482 expect.verifySteps(["unity read 2"]);
2483 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(3);
2484
2485 // move back to record 1 and move to page 2 again: all data should have
2486 // been correctly reloaded
2487 await contains(".o_form_view .o_control_panel .o_pager_previous").click();
2488 expect.verifySteps(["unity read 1"]);
2489 await contains(".o_x2m_control_panel .o_pager_next").click();
2490 expect.verifySteps(["unity read 50,51"]);
2491 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(2);
2492 });
2493
2494 test("edition of one2many field with pager", async () => {
2495 const ids = [];
2496 for (let i = 0; i < 45; i++) {
2497 const id = 10 + i;
2498 ids.push(id);
2499 Partner._records.push({
2500 id: id,
2501 name: "relational record " + id,
2502 });
2503 }
2504 Partner._records[0].p = ids;
2505 Partner._views = { form: '<form><field name="name"/></form>' };
2506
2507 let saveCount = 0;
2508 let checkRead = false;
2509 let readIDs;
2510 onRpc("web_read", (args) => {
2511 if (checkRead) {
2512 readIDs = args.args[0];
2513 checkRead = false;
2514 }
2515 });
2516 onRpc("web_save", (args) => {
2517 expect.step("web_save");
2518 saveCount++;
2519 const commands = args.args[1].p;
2520 switch (saveCount) {
2521 case 1:
2522 expect(commands).toEqual([[0, commands[0][1], { name: "new record" }]]);
2523 break;
2524 case 2:
2525 expect(commands).toEqual([[2, 10]]);
2526 break;
2527 case 3:
2528 expect(commands).toEqual([
2529 [0, commands[0][1], { name: "new record page 1" }],
2530 [2, 11],
2531 [2, 52],
2532 [0, commands[3][1], { name: "new record page 2" }],
2533 ]);
2534 break;
2535 }
2536 });
2537 await mountView({
2538 type: "form",
2539 resModel: "partner",
2540 arch: `
2541 <form>
2542 <field name="p">
2543 <kanban>
2544 <templates>
2545 <t t-name="card">
2546 <div>
2547 <a type="delete" class="fa fa-times float-end delete_icon"/>
2548 <field name="name"/>
2549 </div>
2550 </t>
2551 </templates>
2552 </kanban>
2553 </field>
2554 </form>`,
2555 resId: 1,
2556 });
2557
2558 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40);
2559
2560 // add a record on page one
2561 checkRead = true;
2562 await contains(".o-kanban-button-new").click();
2563 await contains(".modal input").edit("new record");
2564
2565 await contains(".modal .modal-footer .btn-primary").click();
2566
2567 // checks
2568 expect(readIDs).toBe(undefined, { message: "should not have read any record" });
2569 expect(
2570 ".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new):contains('new record')"
2571 ).toHaveCount(0);
2572
2573 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40);
2574
2575 // save
2576 await clickSave();
2577
2578 // delete a record on page one
2579 checkRead = true;
2580 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new):eq(0)").toHaveText(
2581 "relational record 10"
2582 );
2583
2584 await contains(".delete_icon").click(); // should remove record!!!
2585
2586 // checks
2587 expect(readIDs).toEqual([50], {
2588 message: "should have read a record (to display 40 records on page 1)",
2589 });
2590 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40);
2591 // save
2592 await clickSave();
2593
2594 // add and delete records in both pages
2595 checkRead = true;
2596 readIDs = undefined;
2597 // add and delete a record in page 1
2598 await contains(".o-kanban-button-new").click();
2599 await contains(".modal input").edit("new record page 1");
2600 await contains(".modal .modal-footer .btn-primary").click();
2601 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new):eq(0)").toHaveText(
2602 "relational record 11",
2603 {
2604 message: "first record should be the one with id 11 (next checks rely on that)",
2605 }
2606 );
2607
2608 await contains(".delete_icon").click(); // should remove record!!!
2609 expect(readIDs).toEqual([51], {
2610 message: "should have read a record (to display 40 records on page 1)",
2611 });
2612 // add and delete a record in page 2
2613 await contains(".o_x2m_control_panel .o_pager_next").click();
2614
2615 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new):eq(0)").toHaveText(
2616 "relational record 52",
2617 {
2618 message: "first record should be the one with id 52 (next checks rely on that)",
2619 }
2620 );
2621
2622 checkRead = true;
2623 readIDs = undefined;
2624 await contains(".delete_icon").click(); // should remove record!!!
2625 await contains(".o-kanban-button-new").click();
2626
2627 await contains(".modal input").edit("new record page 2");
2628 await contains(".modal .modal-footer .btn-primary").click();
2629
2630 expect(readIDs).toBe(undefined, { message: "should not have read any record" });
2631 // checks
2632 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(5);
2633 expect(
2634 ".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new):contains('new record page 1')"
2635 ).toHaveCount(1);
2636 expect(
2637 ".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new):contains('new record page 2')"
2638 ).toHaveCount(1);
2639 // save
2640 await clickSave();
2641
2642 expect.verifySteps(["web_save", "web_save", "web_save"]);
2643 });
2644
2645 test.tags("desktop");
2646 test("edition of one2many field with pager on desktop", async () => {
2647 const ids = [];
2648 for (let i = 0; i < 45; i++) {
2649 const id = 10 + i;
2650 ids.push(id);
2651 Partner._records.push({
2652 id: id,
2653 name: "relational record " + id,
2654 });
2655 }
2656 Partner._records[0].p = ids;
2657 Partner._views = { form: '<form><field name="name"/></form>' };
2658
2659 let saveCount = 0;
2660 let checkRead = false;
2661 onRpc("web_read", (args) => {
2662 if (checkRead) {
2663 checkRead = false;
2664 }
2665 });
2666 onRpc("web_save", (args) => {
2667 expect.step("web_save");
2668 saveCount++;
2669 const commands = args.args[1].p;
2670 switch (saveCount) {
2671 case 1:
2672 expect(commands).toEqual([[0, commands[0][1], { name: "new record" }]]);
2673 break;
2674 case 2:
2675 expect(commands).toEqual([[2, 10]]);
2676 break;
2677 case 3:
2678 expect(commands).toEqual([
2679 [0, commands[0][1], { name: "new record page 1" }],
2680 [2, 11],
2681 [2, 52],
2682 [0, commands[3][1], { name: "new record page 2" }],
2683 ]);
2684 break;
2685 }
2686 });
2687 await mountView({
2688 type: "form",
2689 resModel: "partner",
2690 arch: `
2691 <form>
2692 <field name="p">
2693 <kanban>
2694 <templates>
2695 <t t-name="card">
2696 <div>
2697 <a type="delete" class="fa fa-times float-end delete_icon"/>
2698 <field name="name"/>
2699 </div>
2700 </t>
2701 </templates>
2702 </kanban>
2703 </field>
2704 </form>`,
2705 resId: 1,
2706 });
2707
2708 expect(".o_x2m_control_panel .o_pager_counter").toHaveText("1-40 / 45");
2709
2710 // add a record on page one
2711 checkRead = true;
2712 await contains(".o-kanban-button-new").click();
2713 await contains(".modal input").edit("new record");
2714
2715 await contains(".modal .modal-footer .btn-primary").click();
2716
2717 // checks
2718 expect(".o_x2m_control_panel .o_pager_counter").toHaveText("1-40 / 46");
2719
2720 // save
2721 await clickSave();
2722
2723 // delete a record on page one
2724 checkRead = true;
2725
2726 await contains(".delete_icon").click(); // should remove record!!!
2727
2728 // checks
2729 expect(".o_x2m_control_panel .o_pager_counter").toHaveText("1-40 / 45");
2730 // save
2731 await clickSave();
2732
2733 // add and delete records in both pages
2734 checkRead = true;
2735 // add and delete a record in page 1
2736 await contains(".o-kanban-button-new").click();
2737 await contains(".modal input").edit("new record page 1");
2738 await contains(".modal .modal-footer .btn-primary").click();
2739
2740 await contains(".delete_icon").click(); // should remove record!!!
2741 // add and delete a record in page 2
2742 await contains(".o_x2m_control_panel .o_pager_next").click();
2743
2744 checkRead = true;
2745 await contains(".delete_icon").click(); // should remove record!!!
2746 await contains(".o-kanban-button-new").click();
2747
2748 await contains(".modal input").edit("new record page 2");
2749 await contains(".modal .modal-footer .btn-primary").click();
2750
2751 // checks
2752 expect(".o_x2m_control_panel .o_pager_counter").toHaveText("41-45 / 45");
2753 // save
2754 await clickSave();
2755
2756 expect.verifySteps(["web_save", "web_save", "web_save"]);
2757 });
2758
2759 test("When viewing one2many records in an embedded kanban, the delete button should say 'Delete' and not 'Remove'", async () => {
2760 expect.assertions(1);
2761 Turtle._views = {
2762 form: `
2763 <form>
2764 <h3>Data</h3>
2765 </form>`,
2766 };
2767 await mountView({
2768 type: "form",
2769 resModel: "partner",
2770 arch: `
2771 <form>
2772 <field name="turtles">
2773 <kanban>
2774 <templates>
2775 <t t-name="card">
2776 <h3>Record 1</h3>
2777 </t>
2778 </templates>
2779 </kanban>
2780 </field>
2781 </form>`,
2782 resId: 1,
2783 });
2784
2785 // Opening the record to see the footer buttons
2786 await contains(".o_kanban_record").click();
2787
2788 expect(".o_btn_remove").toHaveText("Delete");
2789 });
2790
2791 test("open a record in a one2many kanban (mode 'readonly')", async () => {
2792 Turtle._views = {
2793 form: `
2794 <form>
2795 <field name="name"/>
2796 </form>`,
2797 };
2798 await mountView({
2799 type: "form",
2800 resModel: "partner",
2801 arch: `
2802 <form edit="0">
2803 <field name="turtles">
2804 <kanban>
2805 <templates>
2806 <t t-name="card">
2807 <field name="name"/>
2808 </t>
2809 </templates>
2810 </kanban>
2811 </field>
2812 </form>`,
2813 resId: 1,
2814 });
2815
2816 expect(".o_kanban_record:eq(0)").toHaveText("donatello");
2817
2818 await contains(".o_kanban_record").click();
2819
2820 expect(".modal").toHaveCount(1);
2821 expect(".modal div[name=name] span").toHaveText("donatello");
2822 });
2823
2824 test("open a record in a one2many kanban (mode 'edit')", async () => {
2825 Turtle._views = {
2826 form: `
2827 <form>
2828 <field name="name"/>
2829 </form>`,
2830 };
2831 await mountView({
2832 type: "form",
2833 resModel: "partner",
2834 arch: `
2835 <form>
2836 <field name="turtles">
2837 <kanban>
2838 <templates>
2839 <t t-name="card">
2840 <field name="name"/>
2841 </t>
2842 </templates>
2843 </kanban>
2844 </field>
2845 </form>`,
2846 resId: 1,
2847 });
2848
2849 expect(".o_kanban_record:eq(0)").toHaveText("donatello");
2850
2851 await contains(".o_kanban_record").click();
2852
2853 expect(".modal").toHaveCount(1);
2854 expect(".modal div[name=name] input").toHaveValue("donatello");
2855 });
2856
2857 test("open a record in an one2many readonly", async () => {
2858 Turtle._views = {
2859 form: `
2860 <form>
2861 <field name="name"/>
2862 </form>`,
2863 };
2864 await mountView({
2865 type: "form",
2866 resModel: "partner",
2867 arch: `
2868 <form>
2869 <field name="turtles" readonly='1'>
2870 <list>
2871 <field name="name" />
2872 </list>
2873 <form>
2874 <field name="name" />
2875 </form>
2876 </field>
2877 </form>`,
2878 resId: 1,
2879 });
2880
2881 await contains(".o_data_row .o_data_cell").click();
2882 expect(".modal").toHaveCount(1);
2883 expect(".modal div[name=name] span").toHaveText("donatello");
2884
2885 await contains(".modal .o_form_button_cancel").click();
2886 await contains(".o_data_row .o_data_cell").click();
2887 expect(".modal").toHaveCount(1);
2888 expect(".modal div[name=name] span").toHaveText("donatello");
2889 });
2890
2891 test("open a record in a one2many kanban with an x2m in the form", async () => {
2892 Partner._records[0].p = [2];
2893 Partner._records[1].p = [4];
2894
2895 Partner._views = {
2896 form: `
2897 <form>
2898 <field name="name"/>
2899 <field name="p">
2900 <list>
2901 <field name="name"/>
2902 </list>
2903 </field>
2904 </form>`,
2905 };
2906
2907 const def = new Deferred();
2908 onRpc("web_read", async (args) => {
2909 if (args.args[0][0] === 2) {
2910 expect.step("web_read: 2");
2911 await def;
2912 }
2913 });
2914 await mountView({
2915 type: "form",
2916 resModel: "partner",
2917 arch: `
2918 <form>
2919 <field name="p">
2920 <kanban>
2921 <templates>
2922 <t t-name="card">
2923 <field name="name"/>
2924 </t>
2925 </templates>
2926 </kanban>
2927 </field>
2928 </form>`,
2929 resId: 1,
2930 });
2931
2932 await contains(".o_kanban_record").click();
2933 def.resolve();
2934 await animationFrame();
2935 expect(".modal").toHaveCount(1);
2936 expect(".modal [name=name] input").toHaveValue("second record");
2937 expect(queryAllTexts(".modal .o_data_row")).toEqual(["aaa"]);
2938
2939 expect.verifySteps(["web_read: 2"]);
2940 });
2941
2942 test("one2many in kanban: add a line custom control create editable", async () => {
2943 Turtle._views = {
2944 form: `
2945 <form>
2946 <field name="name"/>
2947 </form>`,
2948 };
2949 await mountView({
2950 type: "form",
2951 resModel: "partner",
2952 arch: `
2953 <form>
2954 <field name="turtles">
2955 <kanban>
2956 <control>
2957 <create string="Add food" context="" />
2958 <create string="Add pizza" context="{'default_name': 'pizza'}"/>
2959 </control>
2960 <control>
2961 <create string="Add pasta" context="{'default_name': 'pasta'}"/>
2962 </control>
2963 <templates>
2964 <t t-name="card">
2965 <field name="name"/>
2966 </t>
2967 </templates>
2968 </kanban>
2969 </field>
2970 </form>`,
2971 resId: 1,
2972 });
2973
2974 const createButtons = queryAll(".o_x2m_control_panel .o_cp_buttons button");
2975 expect(queryAllTexts(createButtons)).toEqual(["Add food", "Add pizza", "Add pasta"]);
2976
2977 await contains(createButtons[0]).click();
2978 expect(".modal").toHaveCount(1);
2979 expect(".modal div[name=name] input").toHaveValue("");
2980
2981 await contains(".modal .o_form_button_cancel").click();
2982 await contains(createButtons[1]).click();
2983 expect(".modal").toHaveCount(1);
2984 expect(".modal div[name=name] input").toHaveValue("pizza");
2985
2986 await contains(".modal .o_form_button_cancel").click();
2987 await contains(createButtons[2]).click();
2988 expect(".modal").toHaveCount(1);
2989 expect(".modal div[name=name] input").toHaveValue("pasta");
2990 });
2991
2992 test("one2many in kanban: add a line custom control create editable (2)", async () => {
2993 Turtle._views = {
2994 form: `
2995 <form>
2996 <field name="name"/>
2997 </form>`,
2998 };
2999 onRpc("do_something", (args) => {
3000 expect.step("do_something");
3001 expect(args.kwargs.context.parent_id).toBe(2);
3002 return true;
3003 });
3004 await mountView({
3005 type: "form",
3006 resModel: "partner",
3007 arch: `
3008 <form>
3009 <field name="turtles">
3010 <kanban>
3011 <control>
3012 <create string="Create" context="{}" />
3013 <button string="Action Button" name="do_something" type="object" context="{'parent_id': parent.id}"/>
3014 </control>
3015 <templates>
3016 <t t-name="card">
3017 <field name="name"/>
3018 </t>
3019 </templates>
3020 </kanban>
3021 </field>
3022 </form>`,
3023 resId: 2,
3024 });
3025
3026 expect(queryAllTexts(".o_x2m_control_panel .o_cp_buttons button")).toEqual([
3027 "Create",
3028 "Action Button",
3029 ]);
3030
3031 await contains(".o_x2m_control_panel .o_cp_buttons button:eq(1)").click();
3032 expect.verifySteps(["do_something"]);
3033 });
3034
3035 test("add record in a one2many non editable list with context", async () => {
3036 expect.assertions(1);
3037
3038 onRpc("turtle", "onchange", ({ kwargs }) => {
3039 // done by the X2ManyFieldDialog
3040 expect(kwargs.context).toEqual({
3041 abc: 2,
3042 allowed_company_ids: [1],
3043 lang: "en",
3044 tz: "taht",
3045 uid: 7,
3046 });
3047 });
3048 await mountView({
3049 type: "form",
3050 resModel: "partner",
3051 arch: `
3052 <form>
3053 <field name="int_field"/>
3054 <field name="turtles" context="{'abc': int_field}">
3055 <list><field name="name"/></list>
3056 <form><field name="name"/></form>
3057 </field>
3058 </form>`,
3059 });
3060
3061 await contains(".o_field_widget[name=int_field] input").edit("2");
3062 await contains(".o_field_x2many_list_row_add a").click();
3063 });
3064
3065 test.tags("desktop");
3066 test("edition of one2many field, with onchange and not inline sub view", async () => {
3067 Turtle._onChanges.turtle_int = function (obj) {
3068 obj.turtle_foo = String(obj.turtle_int);
3069 };
3070 Partner._onChanges.turtles = function () {};
3071 Turtle._views = {
3072 list: `
3073 <list>
3074 <field name="turtle_foo"/>
3075 </list>`,
3076 form: `
3077 <form>
3078 <group>
3079 <field name="turtle_foo"/>
3080 <field name="turtle_int"/>
3081 </group>
3082 </form>`,
3083 };
3084
3085 await mountView({
3086 type: "form",
3087 resModel: "partner",
3088 arch: `
3089 <form>
3090 <field name="turtles" widget="one2many"/>
3091 </form>`,
3092 resId: 1,
3093 });
3094 await contains(".o_field_x2many_list_row_add a").click();
3095 await contains('div[name="turtle_int"] input').edit("5");
3096 await contains(".modal-footer button.btn-primary").click();
3097 let firstCellOfSecondRow = ".o_data_cell.o_list_char:eq(1)";
3098 expect(firstCellOfSecondRow).toHaveText("5");
3099 await contains(firstCellOfSecondRow).click();
3100
3101 await contains('div[name="turtle_int"] input').edit("3");
3102 await contains(".modal-footer button.btn-primary").click();
3103 firstCellOfSecondRow = ".o_data_cell.o_list_char:eq(1)";
3104 expect(firstCellOfSecondRow).toHaveText("3");
3105 });
3106
3107 test.tags("desktop");
3108 test("onchange specification complete after open sub form view not inline", async () => {
3109 Partner._onChanges.name = () => {};
3110 Turtle._views = {
3111 form: `
3112 <form>
3113 <field name="name"/>
3114 <field name="partner_ids">
3115 <list>
3116 <field name="name"/>
3117 </list>
3118 </field>
3119 </form>`,
3120 };
3121 onRpc("partner", "onchange", ({ args }) => {
3122 if (args[1].name === "test") {
3123 expect(args[3]).toEqual({
3124 name: {},
3125 display_name: {},
3126 turtles: {
3127 fields: {
3128 turtle_foo: {},
3129 },
3130 limit: 40,
3131 },
3132 });
3133 } else if (args[1].name === "test2") {
3134 expect(args[3]).toEqual({
3135 name: {},
3136 display_name: {},
3137 turtles: {
3138 fields: {
3139 name: {},
3140 partner_ids: {
3141 fields: {
3142 name: {},
3143 },
3144 limit: 40,
3145 },
3146 turtle_foo: {},
3147 },
3148 limit: 40,
3149 },
3150 });
3151 return {
3152 value: {
3153 turtles: [
3154 [
3155 1,
3156 2,
3157 {
3158 name: "yop",
3159 partner_ids: [[1, 2, { name: "plop" }]],
3160 },
3161 ],
3162 ],
3163 },
3164 };
3165 }
3166 });
3167 await mountView({
3168 type: "form",
3169 resModel: "partner",
3170 arch: `
3171 <form>
3172 <field name="name"/>
3173 <field name="turtles">
3174 <list>
3175 <field name="turtle_foo"/>
3176 </list>
3177 </field>
3178 </form>`,
3179 resId: 1,
3180 });
3181 await contains("div[name='name'] input").edit("test");
3182 await contains(".o_data_row .o_data_cell").click();
3183 expect(".modal [name='name'] input").toHaveValue("donatello");
3184 expect(queryAllTexts(".modal .o_data_row")).toEqual(["second record", "aaa"]);
3185
3186 await contains(".modal .o_form_button_save").click();
3187 await contains("div[name='name'] input").edit("test2");
3188 await contains(".o_data_row .o_data_cell").click();
3189 expect(".modal [name='name'] input").toHaveValue("yop");
3190 expect(queryAllTexts(".modal .o_data_row")).toEqual(["plop", "aaa"]);
3191 });
3192
3193 test("sorting one2many fields", async () => {
3194 Partner._fields.foo.sortable = true;
3195 Partner._records.push({ id: 23, foo: "abc", int_field: 1 });
3196 Partner._records.push({ id: 24, foo: "xyz", int_field: 1 });
3197 Partner._records.push({ id: 25, foo: "def", int_field: 2 });
3198 Partner._records[0].p = [23, 24, 25];
3199
3200 let rpcCount = 0;
3201 onRpc(() => {
3202 rpcCount++;
3203 });
3204 await mountView({
3205 type: "form",
3206 resModel: "partner",
3207 arch: `
3208 <form>
3209 <field name="p">
3210 <list>
3211 <field name="foo"/>
3212 <field name="int_field"/>
3213 </list>
3214 </field>
3215 </form>`,
3216 resId: 1,
3217 });
3218
3219 rpcCount = 0;
3220 expect(queryAllTexts(".o_data_cell[name='foo']")).toEqual(["abc", "xyz", "def"]);
3221
3222 await contains("table thead [data-name='foo'].o_column_sortable").click();
3223 expect(rpcCount).toBe(0, { message: "in memory sort, no RPC should have been done" });
3224 expect(queryAllTexts(".o_data_cell[name='foo']")).toEqual(["abc", "def", "xyz"]);
3225
3226 await contains("table thead [data-name='foo'].o_column_sortable").click();
3227 expect(queryAllTexts(".o_data_cell[name='foo']")).toEqual(["xyz", "def", "abc"]);
3228
3229 await contains("table thead [data-name='int_field'].o_column_sortable").click();
3230 expect(queryAllTexts(".o_data_cell[name='foo']")).toEqual(["xyz", "abc", "def"]);
3231
3232 await contains("table thead [data-name='int_field'].o_column_sortable").click();
3233 expect(queryAllTexts(".o_data_cell[name='foo']")).toEqual(["def", "xyz", "abc"]);
3234 });
3235
3236 test("sorting one2many fields with multi page", async () => {
3237 Partner._records.push({ id: 23, foo: "abc", int_field: 1 });
3238 Partner._records.push({ id: 24, foo: "xyz", int_field: 1 });
3239 Partner._records.push({ id: 25, foo: "def", int_field: 2 });
3240 Partner._records.push({ id: 26, foo: "otc", int_field: 2 });
3241 Partner._records[0].p = [23, 24, 25, 26];
3242
3243 await mountView({
3244 type: "form",
3245 resModel: "partner",
3246 arch: `
3247 <form>
3248 <field name="p">
3249 <list limit="2">
3250 <field name="foo"/>
3251 <field name="int_field"/>
3252 </list>
3253 </field>
3254 </form>`,
3255 resId: 1,
3256 });
3257
3258 expect(queryAllTexts(".o_data_row")).toEqual(["abc 1", "xyz 1"]);
3259
3260 await contains("table thead [data-name='int_field'].o_column_sortable").click();
3261 expect(queryAllTexts(".o_data_row")).toEqual(["abc 1", "xyz 1"]);
3262
3263 await contains("table thead [data-name='foo'].o_column_sortable").click();
3264 expect(queryAllTexts(".o_data_row")).toEqual(["abc 1", "def 2"]);
3265
3266 await contains(".o_field_widget[name='p'] .o_pager_next").click();
3267 expect(queryAllTexts(".o_data_row")).toEqual(["otc 2", "xyz 1"]);
3268 });
3269
3270 test("one2many list field edition", async () => {
3271 Partner._records.push({
3272 id: 3,
3273 name: "relational record 1",
3274 });
3275 Partner._records[1].p = [3];
3276
3277 await mountView({
3278 type: "form",
3279 resModel: "partner",
3280 arch: `
3281 <form>
3282 <field name="p">
3283 <list editable="top">
3284 <field name="name"/>
3285 </list>
3286 </field>
3287 </form>`,
3288 resId: 2,
3289 });
3290
3291 expect(".o_field_one2many tbody td:eq(0)").toHaveText("relational record 1");
3292
3293 await contains(".o_field_one2many tbody td").click();
3294 expect(".o_field_one2many tbody .o_data_row:eq(0)").toHaveClass("o_selected_row");
3295 await contains(".o_field_one2many tbody td input").edit("new value", { confirm: false });
3296 expect(".o_field_one2many tbody .o_data_row:eq(0)").toHaveClass("o_selected_row");
3297 expect(".o_field_one2many tbody td input").toHaveValue("new value");
3298
3299 // leave o2m edition
3300 await contains(".o_form_view").click();
3301 expect(".o_field_one2many tbody .o_data_row:eq(0)").not.toHaveClass("o_selected_row");
3302
3303 // discard changes
3304 await contains(".o_form_button_cancel").click();
3305 expect(".modal").toHaveCount(0);
3306 expect(".o_field_one2many tbody td:eq(0)").toHaveText("relational record 1");
3307
3308 // edit again and save
3309 await contains(".o_field_one2many tbody td").click();
3310 await contains(".o_field_one2many tbody td input").edit("new value");
3311 await contains(".o_form_view").click();
3312 await clickSave();
3313
3314 expect(".o_field_one2many tbody td:eq(0)").toHaveText("new value");
3315 });
3316
3317 test("one2many list: create action disabled", async () => {
3318 await mountView({
3319 type: "form",
3320 resModel: "partner",
3321 arch: `
3322 <form>
3323 <field name="p">
3324 <list create="0">
3325 <field name="name"/>
3326 </list>
3327 </field>
3328 </form>`,
3329 resId: 1,
3330 });
3331 expect(".o_field_x2many_list_row_add").toHaveCount(0);
3332 });
3333
3334 test("one2many list: cannot open record in editable list and form in readonly mode", async () => {
3335 Partner._records[0].p = [2];
3336 await mountView({
3337 type: "form",
3338 resModel: "partner",
3339 arch: `
3340 <form edit="0">
3341 <field name="p">
3342 <list editable="bottom">
3343 <field name="name"/>
3344 </list>
3345 </field>
3346 </form>`,
3347 resId: 1,
3348 });
3349
3350 expect(".o_data_cell[name='name']").toHaveCount(1);
3351 await contains(".o_data_cell[name='name']").click();
3352 expect(".modal-dialog").toHaveCount(0);
3353 });
3354
3355 test("one2many list: cannot open record in editable=bottom and edit=false list", async () => {
3356 Partner._records[0].p = [2];
3357 await mountView({
3358 type: "form",
3359 resModel: "partner",
3360 arch: `
3361 <form>
3362 <field name="p">
3363 <list editable="bottom" edit="false">
3364 <field name="name"/>
3365 </list>
3366 </field>
3367 </form>`,
3368 resId: 1,
3369 });
3370
3371 expect(".o_data_cell[name='name']").toHaveCount(1);
3372 await contains(".o_data_cell[name='name']").click();
3373 expect(".modal-dialog").toHaveCount(0);
3374 });
3375
3376 test("one2many list: conditional create/delete actions", async () => {
3377 Partner._records[0].p = [2, 4];
3378 await mountView({
3379 type: "form",
3380 resModel: "partner",
3381 arch: `
3382 <form>
3383 <field name="bar"/>
3384 <field name="p" options="{'create': [('bar', '=', True)], 'delete': [('bar', '=', True)]}">
3385 <list>
3386 <field name="name"/>
3387 </list>
3388 </field>
3389 </form>`,
3390 resId: 1,
3391 });
3392
3393 // bar is true -> create and delete action are available
3394 expect(".o_field_x2many_list_row_add").toHaveCount(1);
3395 expect("td.o_list_record_remove button").toHaveCount(2);
3396
3397 // set bar to false -> create and delete action are no longer available
3398 await contains('.o_field_widget[name="bar"] input').click();
3399
3400 expect(".o_field_x2many_list_row_add").toHaveCount(0);
3401 expect("td.o_list_record_remove button").toHaveCount(0);
3402 });
3403
3404 test("boolean field in a one2many must be directly editable", async () => {
3405 Partner._records[0].p = [2, 4];
3406 await mountView({
3407 type: "form",
3408 resModel: "partner",
3409 arch: `
3410 <form>
3411 <field name="p">
3412 <list editable="top">
3413 <field name="bar"/>
3414 <field name="name"/>
3415 </list>
3416 </field>
3417 </form>`,
3418 resId: 1,
3419 });
3420 expect(".o_data_cell[name='bar'] input:eq(0)").toBeChecked();
3421 expect(".o_data_cell[name='bar'] input:eq(1)").not.toBeChecked();
3422
3423 await contains('[name="bar"] .o-checkbox').click();
3424 expect(".o_data_cell[name='bar'] input:eq(0)").not.toBeChecked();
3425 expect(".o_data_cell[name='bar'] input:eq(1)").not.toBeChecked();
3426 });
3427
3428 test("many2many list: unlink two records", async () => {
3429 expect.assertions(4);
3430 Partner._records[0].p = [1, 2, 4];
3431 Partner._views = {
3432 form: `
3433 <form>
3434 <field name="name"/>
3435 </form>`,
3436 };
3437 onRpc("web_save", (args) => {
3438 expect(args.args[1].p).toEqual([[3, 1]], { message: "should send a command 3 (unlink)" });
3439 });
3440 await mountView({
3441 type: "form",
3442 resModel: "partner",
3443 arch: `
3444 <form>
3445 <field name="p" widget="many2many">
3446 <list>
3447 <field name="name"/>
3448 </list>
3449 </field>
3450 </form>`,
3451 resId: 1,
3452 });
3453 expect("td.o_list_record_remove button").toHaveCount(3);
3454
3455 await contains("td.o_list_record_remove button").click();
3456 expect("td.o_list_record_remove button").toHaveCount(2);
3457
3458 await contains("tr.o_data_row td").click();
3459 expect(".modal .modal-footer .o_btn_remove").toHaveCount(0);
3460
3461 await contains(".modal .btn-secondary").click();
3462 await clickSave();
3463 });
3464
3465 test("one2many list: deleting one records", async () => {
3466 expect.assertions(3);
3467 Partner._records[0].p = [1, 2, 4];
3468 Partner._views = {
3469 form: `
3470 <form>
3471 <field name="name"/>
3472 </form>`,
3473 };
3474 onRpc("web_save", (args) => {
3475 expect(args.args[1].p).toEqual([[2, 1]]);
3476 });
3477 await mountView({
3478 type: "form",
3479 resModel: "partner",
3480 arch: `
3481 <form>
3482 <field name="p">
3483 <list>
3484 <field name="name"/>
3485 </list>
3486 </field>
3487 </form>`,
3488 resId: 1,
3489 });
3490 expect("td.o_list_record_remove button").toHaveCount(3);
3491
3492 await contains("td.o_list_record_remove button").click();
3493 expect("td.o_list_record_remove button").toHaveCount(2);
3494
3495 // save and check that the correct command has been generated
3496 await clickSave();
3497
3498 // FIXME: it would be nice to test that the view is re-rendered correctly,
3499 // but as the relational data isn't re-fetched, the rendering is ok even
3500 // if the changes haven't been saved
3501 });
3502
3503 test("one2many kanban: edition", async () => {
3504 expect.assertions(17);
3505
3506 Partner._records[0].p = [2];
3507 onRpc("web_save", (args) => {
3508 const commands = args.args[1].p;
3509 expect(commands).toEqual([
3510 [
3511 0,
3512 commands[0][1],
3513 {
3514 color: "red",
3515 name: "new subrecord 3",
3516 foo: "My little Foo Value",
3517 },
3518 ],
3519 [2, 2],
3520 ]);
3521 });
3522 await mountView({
3523 type: "form",
3524 resModel: "partner",
3525 // color will be in the kanban but not in the form
3526 // foo will be in the form but not in the kanban
3527 arch: `
3528 <form>
3529 <field name="p">
3530 <kanban>
3531 <templates>
3532 <t t-name="card">
3533 <div>
3534 <a type="delete" class="fa fa-times float-end delete_icon"/>
3535 <field name="name"/>
3536 <field name="color"/>
3537 </div>
3538 </t>
3539 </templates>
3540 </kanban>
3541 <form>
3542 <field name="name"/>
3543 <field name="foo"/>
3544 </form>
3545 </field>
3546 </form>`,
3547 resId: 1,
3548 });
3549
3550 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
3551 expect(".o_kanban_record span:eq(0)").toHaveText("second record");
3552 expect(".o_kanban_record span:eq(1)").toHaveText("Red");
3553 expect(".delete_icon").toHaveCount(1);
3554 expect(".o_field_one2many .o-kanban-button-new").toHaveCount(1);
3555 expect(".o_field_one2many .o-kanban-button-new").toHaveClass(
3556 "o_kanban_record o-kanban-button-new btn btn-link py-4"
3557 );
3558 expect(".o_field_one2many .o-kanban-button-new").toHaveText("Add one2many field");
3559
3560 // edit existing subrecord
3561 await contains(".o_kanban_record:eq(0)").click();
3562
3563 await contains(".modal .o_form_view .o_field_widget:eq(0) input").edit("new name");
3564 await contains(".modal .modal-footer .btn-primary:eq(0)").click();
3565 expect(".o_kanban_record span:first").toHaveText("new name");
3566
3567 // create a new subrecord
3568 await contains(".o-kanban-button-new:eq(0)").click();
3569 await contains(".modal .o_form_view .o_field_widget:eq(0) input").edit("new subrecord 1");
3570 await contains(".modal .modal-footer .btn-primary:eq(0)").click();
3571 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(2);
3572 expect(".o_kanban_record:eq(1) span:eq(0)").toHaveText("new subrecord 1", {
3573 message: 'value of newly created subrecord should be "new subrecord 1"',
3574 });
3575 // create two new subrecords
3576 await contains(".o-kanban-button-new:eq(0)").click();
3577 await contains(".modal .o_form_view .o_field_widget:eq(0) input").edit("new subrecord 2");
3578 await contains(".modal .modal-footer .btn-primary:eq(1)").click();
3579 await contains(".modal .o_form_view .o_field_widget:eq(0) input").edit("new subrecord 3");
3580 await contains(".modal .modal-footer .btn-primary:eq(0)").click();
3581 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(4);
3582
3583 // delete subrecords
3584 await contains(".o_kanban_record:eq(0)").click();
3585 expect(".modal .modal-footer .o_btn_remove").toHaveCount(1);
3586 await contains(".modal .modal-footer .o_btn_remove:eq(0)").click();
3587 expect(".o_modal").toHaveCount(0, { message: "modal should have been closed" });
3588 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(3);
3589 await contains(".o_kanban_renderer .delete_icon:first():eq(0)").click();
3590 await contains(".o_kanban_renderer .delete_icon:first():eq(0)").click();
3591 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
3592 expect(".o_kanban_record span:first").toHaveText("new subrecord 3", {
3593 message: 'the remaining subrecord should be "new subrecord 3"',
3594 });
3595
3596 // save and check that the correct command has been generated
3597 await clickSave();
3598 });
3599
3600 test("one2many kanban (editable): properly handle add-label node attribute", async () => {
3601 await mountView({
3602 type: "form",
3603 resModel: "partner",
3604 arch: `
3605 <form>
3606 <field name="turtles" add-label="Add turtle" mode="kanban">
3607 <kanban>
3608 <templates>
3609 <t t-name="card">
3610 <field name="name"/>
3611 </t>
3612 </templates>
3613 </kanban>
3614 </field>
3615 </form>`,
3616 resId: 1,
3617 });
3618
3619 expect(queryAllTexts('.o_field_one2many[name="turtles"] .o-kanban-button-new')).toEqual(
3620 ["Add turtle"],
3621 { message: "In O2M Kanban, Add button should have 'Add turtle' label" }
3622 );
3623 });
3624
3625 test("one2many kanban: create action disabled", async () => {
3626 Partner._records[0].p = [4];
3627
3628 await mountView({
3629 type: "form",
3630 resModel: "partner",
3631 arch: `
3632 <form>
3633 <field name="p">
3634 <kanban create="0">
3635 <templates>
3636 <t t-name="card">
3637 <div>
3638 <a type="delete" class="fa fa-times float-end delete_icon"/>
3639 <field name="name"/>
3640 </div>
3641 </t>
3642 </templates>
3643 </kanban>
3644 </field>
3645 </form>`,
3646 resId: 1,
3647 });
3648
3649 expect(".o-kanban-button-new").toHaveCount(0);
3650 expect(".o_field_x2many_kanban .delete_icon").toHaveCount(1);
3651 });
3652
3653 test("one2many kanban: conditional create/delete actions", async () => {
3654 Partner._records[0].p = [2, 4];
3655
3656 await mountView({
3657 type: "form",
3658 resModel: "partner",
3659 arch: `
3660 <form>
3661 <field name="bar"/>
3662 <field name="p" options="{'create': [('bar', '=', True)], 'delete': [('bar', '=', True)]}">
3663 <kanban>
3664 <templates>
3665 <t t-name="card">
3666 <field name="name"/>
3667 </t>
3668 </templates>
3669 </kanban>
3670 <form>
3671 <field name="name"/>
3672 <field name="foo"/>
3673 </form>
3674 </field>
3675 </form>`,
3676 resId: 1,
3677 });
3678 // bar is initially true -> create and delete actions are available
3679 expect(".o-kanban-button-new").toHaveCount(1, { message: '"Add" button should be available' });
3680
3681 await contains(".o_kanban_record:first").click();
3682 expect(".modal .modal-footer .o_btn_remove").toHaveCount(1, {
3683 message: "There should be a Remove Button inside modal",
3684 });
3685
3686 await contains(".modal .o_form_button_cancel").click();
3687 // set bar false -> create and delete actions are no longer available
3688 await contains('.o_field_widget[name="bar"] input').click();
3689 expect(".o-kanban-button-new").toHaveCount(0, {
3690 message: '"Add" button should not be available as bar is False',
3691 });
3692
3693 await contains(".o_kanban_record:first").click();
3694 expect(".modal .modal-footer .o_btn_remove").toHaveCount(0, {
3695 message: "There should not be a Remove Button as bar field is False",
3696 });
3697 });
3698
3699 test("one2many kanban: conditional write action", async () => {
3700 Partner._records[0].p = [2, 4];
3701
3702 await mountView({
3703 type: "form",
3704 resModel: "partner",
3705 arch: `
3706 <form>
3707 <field name="bar"/>
3708 <field name="p" options="{'write': [('bar', '=', True)]}">
3709 <kanban>
3710 <templates>
3711 <t t-name="card">
3712 <field name="name"/>
3713 <field name="bar" widget="boolean_toggle"/>
3714 </t>
3715 </templates>
3716 </kanban>
3717 <form>
3718 <field name="name"/>
3719 <field name="foo"/>
3720 </form>
3721 </field>
3722 </form>`,
3723 resId: 1,
3724 });
3725
3726 expect(".o_kanban_record:first span").toHaveText("second record");
3727 expect(".o_field_widget[name=bar]:first input").toBeChecked();
3728
3729 // bar is initially true -> edit action is available
3730 expect(".o_kanban_record:first .o_field_widget[name=bar] input").toBeEnabled();
3731 expect(".o-kanban-button-new").toHaveCount(1); // can create
3732 await contains(".o_kanban_record:first").click();
3733 expect(".o_dialog .o_form_renderer").toHaveClass("o_form_editable");
3734 await contains(".o_dialog .o_field_widget[name=name] input").edit("second record edited");
3735 await contains(".modal .o_form_button_save").click();
3736 expect(".o_kanban_record:first span").toHaveText("second record edited");
3737
3738 // set bar false -> edit action is no longer available
3739 await contains('.o_field_widget[name="bar"] input').click();
3740 expect(".o_kanban_record:first .o_field_widget[name=bar] input").not.toBeEnabled();
3741 expect(".o-kanban-button-new").toHaveCount(1); // can still create
3742 await contains(".o_kanban_record:first").click();
3743 expect(".o_dialog .o_form_renderer").toHaveClass("o_form_readonly");
3744 expect(".o_dialog .o_form_button_save").toHaveCount(0);
3745 await contains(".modal .o_form_button_cancel").click();
3746 expect(".o_dialog").toHaveCount(0);
3747 });
3748
3749 test.tags("desktop");
3750 test("editable one2many list, pager is updated on desktop", async () => {
3751 Turtle._records.push({ id: 4, turtle_foo: "stephen hawking" });
3752 Partner._records[0].turtles = [1, 2, 3, 4];
3753
3754 await mountView({
3755 type: "form",
3756 resModel: "partner",
3757 arch: `
3758 <form>
3759 <field name="turtles">
3760 <list editable="bottom" limit="3">
3761 <field name="turtle_foo"/>
3762 </list>
3763 </field>
3764 </form>`,
3765 resId: 1,
3766 });
3767
3768 // add a record, add value to turtle_foo then click in form view to confirm it
3769 await contains(".o_field_x2many_list_row_add a").click();
3770
3771 await contains('div[name="turtle_foo"] input').edit("nora");
3772
3773 await contains(getFixture()).click();
3774
3775 expect(".o_field_widget[name=turtles] .o_pager").toHaveText("1-4 / 5");
3776 });
3777
3778 test("one2many list (non editable): edition", async () => {
3779 expect.assertions(11);
3780
3781 let nbWrite = 0;
3782 Partner._records[0].p = [2, 4];
3783 onRpc("web_save", (args) => {
3784 nbWrite++;
3785 expect(args.args[1]).toEqual({
3786 p: [
3787 [1, 2, { name: "new name" }],
3788 [2, 4],
3789 ],
3790 });
3791 });
3792 await mountView({
3793 type: "form",
3794 resModel: "partner",
3795 arch: `
3796 <form>
3797 <field name="p">
3798 <list>
3799 <field name="name"/>
3800 <field name="qux"/>
3801 </list>
3802 <form>
3803 <field name="name"/>
3804 </form>
3805 </field>
3806 </form>`,
3807 resId: 1,
3808 });
3809
3810 expect("td.o_list_number").toHaveCount(2);
3811 expect(".o_list_renderer tbody td:eq(0)").toHaveText("second record");
3812 expect(".o_list_record_remove").toHaveCount(2);
3813 expect(".o_field_x2many_list_row_add").toHaveCount(1);
3814
3815 // edit first record
3816 await contains(".o_list_renderer .o_data_cell").click();
3817 expect(".o_list_renderer .o_data_cell:eq(0)").toHaveClass("o_readonly_modifier");
3818
3819 await contains(".modal .o_form_editable input").edit("new name");
3820
3821 contains(".modal .modal-footer .btn-primary").click();
3822 await animationFrame();
3823 expect(".o_list_renderer tbody td:eq(0)").toHaveText("new name");
3824 expect(nbWrite).toBe(0, { message: "should not have write anything in DB" });
3825
3826 // remove second record
3827 contains(".o_list_record_remove:eq(1)").click();
3828 await animationFrame();
3829 expect("td.o_list_number").toHaveCount(1);
3830 expect(".o_list_renderer tbody td:eq(0)").toHaveText("new name");
3831
3832 await clickSave(); // save the record
3833 expect(nbWrite).toBe(1, { message: "should have write the changes in DB" });
3834 });
3835
3836 test("one2many list (editable): edition, part 2", async () => {
3837 expect.assertions(11);
3838 onRpc("web_save", (args) => {
3839 // Would be nice to assert this way, but we don't control the virtual ids index
3840 // expect(args.args[1].p).toEqual([
3841 // [0, "virtual_2", { foo: "gemuse" }],
3842 // [0, "virtual_1", { foo: "kartoffel" }],
3843 // ]);
3844 expect(args.args[1].p[0][0]).toBe(0);
3845 expect(args.args[1].p[1][0]).toBe(0);
3846 expect(args.args[1].p[0][2]).toEqual({ foo: "gemuse" });
3847 expect(args.args[1].p[1][2]).toEqual({ foo: "kartoffel" });
3848 });
3849 await mountView({
3850 type: "form",
3851 resModel: "partner",
3852 arch: `
3853 <form>
3854 <field name="p">
3855 <list editable="top">
3856 <field name="foo"/>
3857 </list>
3858 </field>
3859 </form>`,
3860 resId: 1,
3861 });
3862 // edit mode, then click on Add an item and enter a value
3863 await contains(".o_field_x2many_list_row_add a").click();
3864 await contains(".o_selected_row > td input").edit("kartoffel", { confirm: "false" });
3865 expect("td .o_field_char input").toHaveValue("kartoffel");
3866
3867 // click again on Add an item
3868 await contains(".o_field_x2many_list_row_add a").click();
3869 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row");
3870 expect(".o_data_cell:eq(1)").toHaveText("kartoffel");
3871 expect(".o_selected_row > td input").toHaveCount(1);
3872 expect("tr.o_data_row").toHaveCount(2);
3873
3874 // enter another value and save
3875 await contains(".o_selected_row > td input").edit("gemuse", { confirm: "false" });
3876 await clickSave();
3877 expect("tr.o_data_row").toHaveCount(2);
3878 expect(queryAllTexts(".o_data_cell")).toEqual(["gemuse", "kartoffel"]);
3879 });
3880
3881 test("one2many list (editable): edition, part 3", async () => {
3882 await mountView({
3883 type: "form",
3884 resModel: "partner",
3885 arch: `
3886 <form>
3887 <group>
3888 <field name="turtles">
3889 <list editable="top">
3890 <field name="turtle_foo"/>
3891 </list>
3892 </field>
3893 </group>
3894 </form>`,
3895 resId: 1,
3896 });
3897
3898 // edit mode, then click on Add an item, enter value in turtle_foo and Add an item again
3899 expect("tr.o_data_row").toHaveCount(1);
3900 await contains(".o_field_x2many_list_row_add a").click();
3901 await contains('div[name="turtle_foo"] input').edit("nora", { confirm: "false" });
3902 await contains(".o_field_x2many_list_row_add a").click();
3903 expect("tr.o_data_row").toHaveCount(3);
3904
3905 // cancel the edition
3906 await contains(".o_form_button_cancel").click();
3907
3908 expect(".modal").toHaveCount(0);
3909 expect("tr.o_data_row").toHaveCount(1);
3910 });
3911
3912 test.tags("desktop");
3913 test("one2many list (editable): edition, part 4", async () => {
3914 let i = 0;
3915 Turtle._onChanges = {
3916 turtle_trululu: function (obj) {
3917 if (i) {
3918 obj.turtle_description = "Some Description";
3919 }
3920 i++;
3921 },
3922 };
3923
3924 await mountView({
3925 type: "form",
3926 resModel: "partner",
3927 arch: `
3928 <form>
3929 <group>
3930 <field name="turtles">
3931 <list editable="top">
3932 <field name="turtle_trululu"/>
3933 <field name="turtle_description"/>
3934 </list>
3935 </field>
3936 </group>
3937 </form>`,
3938 resId: 2,
3939 });
3940
3941 // edit mode, then click on Add an item
3942 expect("tr.o_data_row").toHaveCount(0);
3943 await contains(".o_field_x2many_list_row_add a").click();
3944 expect(".o_data_row textarea").toHaveValue("");
3945
3946 // add a value in the turtle_trululu field to trigger an onchange
3947 await clickFieldDropdown("turtle_trululu");
3948 await press("Enter");
3949 await animationFrame();
3950 expect(".o_data_row textarea").toHaveValue("Some Description");
3951 });
3952
3953 test("one2many list (editable): edition, part 5", async () => {
3954 await mountView({
3955 type: "form",
3956 resModel: "partner",
3957 arch: `
3958 <form>
3959 <group>
3960 <field name="turtles">
3961 <list editable="top">
3962 <field name="turtle_foo"/>
3963 </list>
3964 </field>
3965 </group>
3966 </form>`,
3967 resId: 1,
3968 });
3969
3970 // edit mode, then click on Add an item, enter value in turtle_foo and Add an item again
3971 expect("tr.o_data_row").toHaveCount(1);
3972 expect(".o_data_cell").toHaveText("blip");
3973 await contains(".o_field_x2many_list_row_add a").click();
3974 await contains(".o_field_widget[name=turtle_foo] input").edit("aaa", { confirm: "false" });
3975 expect("tr.o_data_row").toHaveCount(2);
3976 await contains(".o_list_record_remove:eq(1)").click();
3977 expect("tr.o_data_row").toHaveCount(1);
3978
3979 // cancel the edition
3980 await contains(".o_form_button_cancel").click();
3981 expect("tr.o_data_row").toHaveCount(1);
3982 expect(".o_data_cell").toHaveText("blip");
3983 });
3984
3985 test("one2many list (editable): discarding required empty data", async () => {
3986 Turtle._fields.turtle_foo = fields.Char({ required: true });
3987 onRpc((args) => {
3988 expect.step(args.method);
3989 });
3990 await mountView({
3991 type: "form",
3992 resModel: "partner",
3993 arch: `
3994 <form>
3995 <field name="turtles">
3996 <list editable="top">
3997 <field name="turtle_foo"/>
3998 </list>
3999 </field>
4000 </form>`,
4001 resId: 2,
4002 });
4003
4004 // edit mode, then click on Add an item, then click elsewhere
4005 expect("tr.o_data_row").toHaveCount(0);
4006 await contains(".o_field_x2many_list_row_add a").click();
4007 await contains(getFixture()).click();
4008 expect("tr.o_data_row").toHaveCount(0);
4009
4010 // click on Add an item again, then click on save
4011 await contains(".o_field_x2many_list_row_add a").click();
4012 await clickSave();
4013 expect("tr.o_data_row").toHaveCount(0);
4014
4015 expect.verifySteps(["get_views", "web_read", "onchange", "onchange"]);
4016 });
4017
4018 test.tags("desktop");
4019 test("discard O2M field with close button", async () => {
4020 Partner._records[0].p = [2];
4021 await mountView({
4022 type: "form",
4023 resModel: "partner",
4024 arch: `
4025 <form>
4026 <field name="p">
4027 <list>
4028 <field name="name" />
4029 </list>
4030 <form>
4031 <field name="name" />
4032 </form>
4033 </field>
4034 </form>`,
4035 resId: 1,
4036 });
4037 expect(".o_data_row").toHaveText("second record");
4038
4039 await contains(".o_data_row .o_data_cell").click();
4040 expect(".o_dialog").toHaveCount(1);
4041 expect(".modal .o_field_widget[name=name] input").toHaveValue("second record");
4042
4043 await contains(".modal .o_field_widget[name=name] input").edit("plop");
4044 await contains(".modal .btn-close").click();
4045 expect(".o_data_row").toHaveText("second record");
4046
4047 await contains(".o_data_row .o_data_cell").click();
4048 expect(".o_dialog").toHaveCount(1);
4049 expect(".modal .o_field_widget[name=name] input").toHaveValue("second record");
4050 });
4051
4052 test("editable one2many list, adding line when only one page", async () => {
4053 Partner._records[0].turtles = [1, 2, 3];
4054 await mountView({
4055 type: "form",
4056 resModel: "partner",
4057 arch: `
4058 <form>
4059 <field name="turtles">
4060 <list editable="bottom" limit="3">
4061 <field name="turtle_foo"/>
4062 </list>
4063 </field>
4064 </form>`,
4065 resId: 1,
4066 });
4067
4068 // add a record, to reach the page size limit
4069 await contains(".o_field_x2many_list_row_add a").click();
4070 // the record currently being added should not count in the pager
4071 expect(".o_field_widget[name=turtles] .o_pager").toHaveCount(0);
4072
4073 // enter value in turtle_foo field and click outside to unselect the row
4074 await contains('.o_field_widget[name="turtle_foo"] input').edit("nora");
4075 await contains(getFixture()).click();
4076 expect(".o_selected_row").toHaveCount(0);
4077 expect(".o_field_widget[name=turtles] .o_pager").toHaveCount(0);
4078
4079 await clickSave();
4080 expect(".o_field_widget[name=turtles] .o_pager").toHaveCount(1);
4081 });
4082
4083 test.tags("desktop");
4084 test("editable one2many list, adding line when only one page on desktop", async () => {
4085 Partner._records[0].turtles = [1, 2, 3];
4086 await mountView({
4087 type: "form",
4088 resModel: "partner",
4089 arch: `
4090 <form>
4091 <field name="turtles">
4092 <list editable="bottom" limit="3">
4093 <field name="turtle_foo"/>
4094 </list>
4095 </field>
4096 </form>`,
4097 resId: 1,
4098 });
4099
4100 // add a record, to reach the page size limit
4101 await contains(".o_field_x2many_list_row_add a").click();
4102
4103 // enter value in turtle_foo field and click outside to unselect the row
4104 await contains('.o_field_widget[name="turtle_foo"] input').edit("nora");
4105 await contains(getFixture()).click();
4106 await clickSave();
4107 expect(".o_field_widget[name=turtles] .o_pager").toHaveText("1-3 / 4");
4108 });
4109
4110 test("editable one2many list, adding line, then discarding", async () => {
4111 Turtle._records.push({ id: 4, turtle_foo: "stephen hawking" });
4112 Partner._records[0].turtles = [1, 2, 3, 4];
4113
4114 await mountView({
4115 type: "form",
4116 resModel: "partner",
4117 arch: `
4118 <form>
4119 <field name="turtles">
4120 <list editable="bottom" limit="3">
4121 <field name="turtle_foo"/>
4122 </list>
4123 </field>
4124 </form>`,
4125 resId: 1,
4126 });
4127
4128 // add a record, then discard
4129 await contains(".o_field_x2many_list_row_add a").click();
4130
4131 await contains(".o_form_button_cancel").click();
4132 expect(".modal").toHaveCount(0);
4133
4134 expect(".o_field_widget[name=turtles] .o_pager").toBeVisible();
4135 });
4136
4137 test.tags("desktop");
4138 test("editable one2many list, adding line, then discarding on desktop", async () => {
4139 Turtle._records.push({ id: 4, turtle_foo: "stephen hawking" });
4140 Partner._records[0].turtles = [1, 2, 3, 4];
4141
4142 await mountView({
4143 type: "form",
4144 resModel: "partner",
4145 arch: `
4146 <form>
4147 <field name="turtles">
4148 <list editable="bottom" limit="3">
4149 <field name="turtle_foo"/>
4150 </list>
4151 </field>
4152 </form>`,
4153 resId: 1,
4154 });
4155
4156 // add a record, then discard
4157 await contains(".o_field_x2many_list_row_add a").click();
4158 await contains(".o_form_button_cancel").click();
4159 expect(".o_field_widget[name=turtles] .o_pager").toHaveText("1-3 / 4");
4160 });
4161
4162 test("editable one2many list, required field and pager", async () => {
4163 Turtle._records.push({ id: 4, turtle_foo: "stephen hawking" });
4164 Turtle._fields.turtle_foo = fields.Char({ required: true });
4165 Partner._records[0].turtles = [1, 2, 3, 4];
4166
4167 await mountView({
4168 type: "form",
4169 resModel: "partner",
4170 arch: `
4171 <form>
4172 <field name="turtles">
4173 <list editable="bottom" limit="3">
4174 <field name="turtle_foo"/>
4175 </list>
4176 </field>
4177 </form>`,
4178 resId: 1,
4179 });
4180
4181 // add a (empty) record
4182 await contains(".o_field_x2many_list_row_add a").click();
4183
4184 // go on next page. The new record is not valid and should be discarded
4185 await contains(".o_field_widget[name=turtles] .o_pager_next").click();
4186 expect("tr.o_data_row").toHaveCount(1);
4187 });
4188
4189 test.tags("desktop");
4190 test("editable one2many list, required field, pager and confirm discard on desktop", async () => {
4191 Turtle._records.push({ id: 4, turtle_foo: "stephen hawking" });
4192 Turtle._fields.turtle_foo = fields.Char({ required: true });
4193 Partner._records[0].turtles = [1, 2, 3, 4];
4194
4195 await mountView({
4196 type: "form",
4197 resModel: "partner",
4198 arch: `
4199 <form>
4200 <field name="turtles">
4201 <list editable="bottom" limit="3">
4202 <field name="turtle_foo"/>
4203 <field name="turtle_int"/>
4204 </list>
4205 </field>
4206 </form>`,
4207 resId: 1,
4208 });
4209
4210 // add a record with a dirty state, but not valid
4211 await contains(".o_field_x2many_list_row_add a").click();
4212 await contains('.o_field_widget[name="turtle_int"] input').edit(4321);
4213
4214 // try to go to next page. The new record is not valid, but dirty so we should
4215 // stay on the current page, and the record should be marked as invalid
4216 await contains(".o_field_widget[name=turtles] .o_pager_next").click();
4217
4218 expect(".o_field_widget[name=turtles] .o_pager").toHaveText("1-4 / 5");
4219
4220 expect(".o_field_widget[name=turtles] .o_pager").toHaveText("1-4 / 5");
4221 expect(".o_field_widget[name=turtle_foo].o_field_invalid").toHaveCount(1);
4222 });
4223
4224 test("save a record with not new, dirty and invalid subrecord", async () => {
4225 Partner._records[0].p = [2];
4226 Partner._records[1].name = ""; // invalid record
4227 onRpc("write", () => {
4228 throw new Error("Should not call write as record is invalid");
4229 });
4230 await mountView({
4231 type: "form",
4232 resModel: "partner",
4233 arch: `
4234 <form>
4235 <field name="p">
4236 <list editable="bottom">
4237 <field name="name" required="1"/>
4238 <field name="int_field"/>
4239 </list>
4240 </field>
4241 </form>`,
4242 resId: 1,
4243 });
4244
4245 expect(".o_form_editable").toHaveCount(1);
4246 await contains(".o_data_cell").click(); // edit the first row
4247 expect(".o_data_row").toHaveClass("o_selected_row");
4248 await contains(".o_field_widget[name=int_field] input").edit(44);
4249 await contains(".o_form_button_save").click();
4250 expect(".o_form_editable").toHaveCount(1);
4251 expect(".o_invalid_cell").toHaveCount(1);
4252 });
4253
4254 test("editable one2many list, adding, discarding, and pager", async () => {
4255 Partner._records[0].turtles = [1];
4256
4257 await mountView({
4258 type: "form",
4259 resModel: "partner",
4260 arch: `
4261 <form>
4262 <field name="turtles">
4263 <list editable="bottom" limit="3">
4264 <field name="turtle_foo"/>
4265 </list>
4266 </field>
4267 </form>`,
4268 resId: 1,
4269 });
4270
4271 // add 4 records (to have more records than the limit)
4272 await contains(".o_field_x2many_list_row_add a").click();
4273 await contains('.o_field_widget[name="turtle_foo"] input').edit("nora", { confirm: false });
4274 await contains(".o_field_x2many_list_row_add a").click();
4275 await contains('.o_field_widget[name="turtle_foo"] input').edit("nora", { confirm: false });
4276 await contains(".o_field_x2many_list_row_add a").click();
4277 await contains('.o_field_widget[name="turtle_foo"] input').edit("nora", { confirm: false });
4278 await contains(".o_field_x2many_list_row_add a").click();
4279
4280 expect("tr.o_data_row").toHaveCount(5);
4281 expect(".o_field_widget[name=turtles] .o_pager").toHaveCount(0);
4282
4283 // discard
4284 await contains(".o_form_button_cancel").click();
4285 expect(".modal").toHaveCount(0);
4286
4287 expect("tr.o_data_row").toHaveCount(1);
4288 expect(".o_field_widget[name=turtles] .o_pager").toHaveCount(0);
4289 });
4290
4291 test("unselecting a line with missing required data", async () => {
4292 Turtle._fields.turtle_foo = fields.Char({ required: true });
4293
4294 await mountView({
4295 type: "form",
4296 resModel: "partner",
4297 arch: `
4298 <form>
4299 <field name="turtles">
4300 <list editable="top">
4301 <field name="turtle_foo"/>
4302 <field name="turtle_int"/>
4303 </list>
4304 </field>
4305 </form>`,
4306 resId: 2,
4307 });
4308
4309 // edit mode, then click on Add an item, then click elsewhere
4310 expect("tr.o_data_row").toHaveCount(0);
4311 await contains(".o_field_x2many_list_row_add a").click();
4312 expect("tr.o_data_row").toHaveCount(1);
4313
4314 // adding a value in the non required field, so it is dirty, but with
4315 // a missing required field
4316 await contains('.o_field_widget[name="turtle_int"] input').edit("12345");
4317
4318 // click elsewhere
4319 await contains(getFixture()).click();
4320 expect(".modal").toHaveCount(0);
4321
4322 // the line should still be selected
4323 expect("tr.o_data_row.o_selected_row").toHaveCount(1);
4324
4325 // click discard
4326 await contains(".o_form_button_cancel").click();
4327 expect(".modal").toHaveCount(0);
4328 expect("tr.o_data_row").toHaveCount(0);
4329 });
4330
4331 test("pressing enter in a o2m with a required empty field", async () => {
4332 Turtle._fields.turtle_foo = fields.Char({ required: true });
4333 onRpc((args) => {
4334 expect.step(args.method);
4335 });
4336 await mountView({
4337 type: "form",
4338 resModel: "partner",
4339 arch: `
4340 <form>
4341 <field name="turtles">
4342 <list editable="bottom">
4343 <field name="turtle_foo"/>
4344 </list>
4345 </field>
4346 </form>`,
4347 resId: 2,
4348 });
4349
4350 // edit mode, then click on Add an item, then press enter
4351 await contains(".o_field_x2many_list_row_add a").click();
4352 await press("Enter");
4353 await animationFrame();
4354 expect('div[name="turtle_foo"]').toHaveClass("o_field_invalid");
4355 expect.verifySteps(["get_views", "web_read", "onchange"]);
4356 });
4357
4358 test("pressing enter several times in a one2many", async () => {
4359 await mountView({
4360 type: "form",
4361 resModel: "partner",
4362 arch: `
4363 <form>
4364 <field name="turtles">
4365 <list editable="bottom">
4366 <field name="turtle_foo"/>
4367 </list>
4368 </field>
4369 </form>`,
4370 resId: 2,
4371 });
4372
4373 await contains(".o_field_x2many_list_row_add a").click();
4374 expect(".o_data_row").toHaveCount(1);
4375 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row");
4376
4377 await contains("[name='turtle_foo'] input").edit("a", { confirm: false });
4378 await press("Enter");
4379 await animationFrame();
4380 expect(".o_data_row").toHaveCount(2);
4381 expect(".o_data_row:eq(1)").toHaveClass("o_selected_row");
4382
4383 await contains("[name='turtle_foo'] input").edit("a", { confirm: false });
4384 await press("Enter");
4385 await animationFrame();
4386 expect(".o_data_row").toHaveCount(3);
4387 expect(".o_data_row:eq(2)").toHaveClass("o_selected_row");
4388
4389 // this is a weird case, but there's no required fields, so the record is already valid, we can press Enter directly.
4390 await press("Enter");
4391 await animationFrame();
4392 expect(".o_data_row").toHaveCount(4);
4393 expect(".o_data_row:eq(3)").toHaveClass("o_selected_row");
4394 });
4395
4396 test("creating a new line in an o2m with an handle field does not focus the handler", async () => {
4397 await mountView({
4398 type: "form",
4399 resModel: "partner",
4400 arch: `
4401 <form>
4402 <field name="turtles">
4403 <list editable="bottom">
4404 <field name="turtle_int" widget="handle"/>
4405 <field name="turtle_foo"/>
4406 </list>
4407 </field>
4408 </form>`,
4409 resId: 2,
4410 });
4411
4412 await contains(".o_field_x2many_list_row_add a").click();
4413 expect("[name='turtle_foo'] input").toBeFocused();
4414
4415 await press("Enter");
4416 await animationFrame();
4417 expect("[name='turtle_foo'] input").toBeFocused();
4418 });
4419
4420 test("editing a o2m, with required field and onchange", async () => {
4421 Turtle._fields.turtle_foo = fields.Char({ required: true });
4422 Turtle._onChanges = {
4423 turtle_foo: function (obj) {
4424 obj.turtle_int = obj.turtle_foo.length;
4425 },
4426 };
4427 onRpc((args) => {
4428 if (args.method) {
4429 expect.step(args.method);
4430 }
4431 });
4432 await mountView({
4433 type: "form",
4434 resModel: "partner",
4435 arch: `
4436 <form>
4437 <group>
4438 <field name="turtles">
4439 <list editable="top">
4440 <field name="turtle_foo"/>
4441 <field name="turtle_int"/>
4442 </list>
4443 </field>
4444 </group>
4445 </form>`,
4446 resId: 2,
4447 });
4448
4449 // edit mode, then click on Add an item
4450 expect("tr.o_data_row").toHaveCount(0);
4451 await contains(".o_field_x2many_list_row_add a").click();
4452
4453 // input some text in required turtle_foo field
4454 await contains('.o_field_widget[name="turtle_foo"] input').edit("aubergine", {
4455 confirm: "blur",
4456 });
4457 expect('.o_field_cell[name="turtle_int"]').toHaveText("9");
4458
4459 // save and check everything is fine
4460 await clickSave();
4461
4462 expect(".o_data_row .o_data_cell.o_list_char").toHaveText("aubergine");
4463 expect(".o_data_row .o_data_cell.o_list_number").toHaveText("9");
4464
4465 expect.verifySteps(["get_views", "web_read", "onchange", "onchange", "web_save"]);
4466 });
4467
4468 test("editable o2m, pressing ESC discard current changes", async () => {
4469 onRpc((args) => {
4470 expect.step(args.method);
4471 });
4472 await mountView({
4473 type: "form",
4474 resModel: "partner",
4475 arch: `
4476 <form>
4477 <field name="turtles">
4478 <list editable="top">
4479 <field name="turtle_foo"/>
4480 </list>
4481 </field>
4482 </form>`,
4483 resId: 2,
4484 });
4485
4486 await contains(".o_field_x2many_list_row_add a").click();
4487 expect("tr.o_data_row").toHaveCount(1);
4488
4489 await press("Escape");
4490 await animationFrame();
4491 expect("tr.o_data_row").toHaveCount(0);
4492 expect.verifySteps(["get_views", "web_read", "onchange"]);
4493 });
4494
4495 test("editable o2m with required field, pressing ESC discard current changes", async () => {
4496 Turtle._fields.turtle_foo = fields.Char({ required: true });
4497 onRpc((args) => {
4498 expect.step(args.method);
4499 });
4500 await mountView({
4501 type: "form",
4502 resModel: "partner",
4503 arch: `
4504 <form>
4505 <field name="turtles">
4506 <list editable="top">
4507 <field name="turtle_foo"/>
4508 </list>
4509 </field>
4510 </form>`,
4511 resId: 2,
4512 });
4513
4514 await contains(".o_field_x2many_list_row_add a").click();
4515 expect("tr.o_data_row").toHaveCount(1);
4516
4517 await press("Escape");
4518 await animationFrame();
4519 expect("tr.o_data_row").toHaveCount(0);
4520 expect.verifySteps(["get_views", "web_read", "onchange"]);
4521 });
4522
4523 test("pressing escape in editable o2m list in dialog", async () => {
4524 Partner._views = {
4525 form: `
4526 <form>
4527 <field name="p">
4528 <list editable="bottom">
4529 <field name="name"/>
4530 </list>
4531 </field>
4532 </form>`,
4533 };
4534
4535 await mountView({
4536 type: "form",
4537 resModel: "partner",
4538 arch: `
4539 <form>
4540 <field name="p">
4541 <list>
4542 <field name="name"/>
4543 </list>
4544 </field>
4545 </form>`,
4546 resId: 1,
4547 });
4548
4549 await contains(".o_field_x2many_list_row_add a").click();
4550 await contains(".modal .o_field_x2many_list_row_add a").click();
4551
4552 expect(".modal .o_data_row.o_selected_row").toHaveCount(1);
4553
4554 await press("Escape");
4555 await animationFrame();
4556 expect(".modal").toHaveCount(1);
4557 expect(".modal .o_data_row").toHaveCount(0);
4558 });
4559
4560 test.tags("desktop");
4561 test("editable o2m with onchange and required field: delete an invalid line", async () => {
4562 Partner._onChanges = {
4563 turtles: function () {},
4564 };
4565 Partner._records[0].turtles = [1];
4566 Turtle._records[0].product_id = 37;
4567 onRpc((args) => {
4568 expect.step(args.method);
4569 });
4570 await mountView({
4571 type: "form",
4572 resModel: "partner",
4573 arch: `
4574 <form>
4575 <field name="turtles">
4576 <list editable="top">
4577 <field name="product_id"/>
4578 </list>
4579 </field>
4580 </form>`,
4581 resId: 1,
4582 });
4583
4584 expect.verifySteps(["get_views", "web_read"]);
4585 await contains(".o_data_cell").click();
4586 await contains(".o_field_widget[name=product_id] input").clear();
4587 // no onchange should be done as line is invalid
4588 expect.verifySteps([]);
4589 await contains(".o_list_record_remove").click();
4590 // onchange should have been done
4591 expect.verifySteps(["onchange"]);
4592 });
4593
4594 test("onchange in a one2many", async () => {
4595 Partner._records.push({
4596 id: 3,
4597 foo: "relational record 1",
4598 });
4599 Partner._records[1].p = [3];
4600 Partner._onChanges = { p: () => {} };
4601 onRpc("onchange", (args) => ({
4602 value: {
4603 p: [
4604 [2, 3], // delete 3
4605 [0, 0, { foo: "from onchange" }], // create new
4606 ],
4607 },
4608 }));
4609 await mountView({
4610 type: "form",
4611 resModel: "partner",
4612 arch: `
4613 <form>
4614 <field name="p">
4615 <list editable="top">
4616 <field name="foo"/>
4617 </list>
4618 </field>
4619 </form>`,
4620 resId: 2,
4621 });
4622
4623 await contains(".o_field_one2many tbody td").click();
4624 await contains(".o_field_one2many tbody td input").edit("new value", { confirm: false });
4625 await clickSave();
4626
4627 expect(".o_field_one2many tbody td:eq(0)").toHaveText("from onchange");
4628 });
4629
4630 test("one2many, default_get and onchange (basic)", async () => {
4631 Partner._fields.p = fields.One2many({
4632 string: "one2many field",
4633 relation: "partner",
4634 relation_field: "trululu",
4635 default: [],
4636 });
4637 Partner._onChanges = { p: () => {} };
4638 onRpc("onchange", (args) => ({
4639 value: {
4640 p: [
4641 [0, 0, { foo: "from onchange" }], // create new
4642 ],
4643 },
4644 }));
4645 await mountView({
4646 type: "form",
4647 resModel: "partner",
4648 arch: `
4649 <form>
4650 <field name="p">
4651 <list>
4652 <field name="foo"/>
4653 </list>
4654 </field>
4655 </form>`,
4656 });
4657
4658 expect("td:eq(0)").toHaveText("from onchange");
4659 });
4660
4661 test("one2many and default_get (with date)", async () => {
4662 Partner._fields.p = fields.One2many({
4663 string: "one2many field",
4664 relation: "partner",
4665 relation_field: "trululu",
4666 default: [[0, false, { date: "2017-10-08", p: [] }]],
4667 });
4668
4669 await mountView({
4670 type: "form",
4671 resModel: "partner",
4672 arch: `
4673 <form>
4674 <field name="p">
4675 <list>
4676 <field name="date"/>
4677 </list>
4678 </field>
4679 </form>`,
4680 });
4681
4682 expect(".o_data_cell").toHaveText("Oct 8, 2017");
4683 });
4684
4685 test("one2many and onchange (with integer)", async () => {
4686 Turtle._onChanges = {
4687 turtle_int: function () {},
4688 };
4689 onRpc((args) => {
4690 expect.step(args.method);
4691 });
4692 await mountView({
4693 type: "form",
4694 resModel: "partner",
4695 arch: `
4696 <form>
4697 <field name="turtles">
4698 <list editable="bottom">
4699 <field name="turtle_int"/>
4700 </list>
4701 </field>
4702 </form>`,
4703 resId: 1,
4704 });
4705 expect("td:eq(0)").toHaveText("9");
4706 contains("td").click();
4707 await contains('td [name="turtle_int"] input').edit("3", { confirm: "blur" });
4708 expect.verifySteps(["get_views", "web_read", "onchange"]);
4709 });
4710
4711 test("one2many and onchange (with date)", async () => {
4712 Partner._onChanges = {
4713 date: function () {},
4714 };
4715 Partner._records[0].p = [2];
4716 onRpc((args) => {
4717 expect.step(args.method);
4718 });
4719 await mountView({
4720 type: "form",
4721 resModel: "partner",
4722 arch: `
4723 <form>
4724 <field name="p">
4725 <list editable="bottom">
4726 <field name="date"/>
4727 </list>
4728 </field>
4729 </form>`,
4730 resId: 1,
4731 });
4732 expect("td:eq(0)").toHaveText("Jan 25, 2017");
4733
4734 contains("td:eq(0)").click();
4735 await contains("td:eq(0) .o_field_date input").click();
4736 contains(getPickerCell("1")).click();
4737 await clickSave();
4738
4739 expect.verifySteps(["get_views", "web_read", "onchange", "web_save"]);
4740 });
4741
4742 test("one2many and onchange only write modified field", async () => {
4743 expect.assertions(2);
4744
4745 Partner._onChanges = {
4746 turtles: function (obj) {
4747 obj.turtles = [
4748 [
4749 1,
4750 3,
4751 {
4752 name: "coucou",
4753 turtle_foo: "has changed",
4754 turtle_int: 42,
4755 },
4756 ],
4757 ];
4758 },
4759 };
4760
4761 Partner._records[0].turtles = [3];
4762 onRpc("web_save", (args) => {
4763 expect(args.args[1].turtles).toEqual(
4764 [
4765 [
4766 1,
4767 3,
4768 {
4769 name: "coucou",
4770 turtle_foo: "has changed",
4771 turtle_int: 42,
4772 },
4773 ],
4774 ],
4775 { message: "correct commands should be sent (only send changed values)" }
4776 );
4777 });
4778 await mountView({
4779 type: "form",
4780 resModel: "partner",
4781 arch: `
4782 <form>
4783 <field name="foo"/>
4784 <field name="turtles">
4785 <list editable="bottom">
4786 <field name="name"/>
4787 <field name="product_id"/>
4788 <field name="turtle_bar"/>
4789 <field name="turtle_foo"/>
4790 <field name="turtle_int"/>
4791 <field name="turtle_qux"/>
4792 <field name="turtle_ref"/>
4793 </list>
4794 </field>
4795 </form>`,
4796 resId: 1,
4797 });
4798 expect(".o_data_row").toHaveCount(1);
4799 await contains(".o_field_one2many td").click();
4800 await contains(".o_field_widget[name=name] input").edit("blurp");
4801
4802 await clickSave();
4803 });
4804
4805 test("one2many with CREATE _onChanges correctly refreshed", async () => {
4806 let delta = 0;
4807 const fieldRegistry = registry.category("fields");
4808 for (const [name, field] of fieldRegistry.getEntries()) {
4809 class DeltaField extends field.component {
4810 setup() {
4811 super.setup();
4812 onWillStart(() => {
4813 delta++;
4814 });
4815 onWillDestroy(() => {
4816 delta--;
4817 });
4818 }
4819 }
4820 fieldRegistry.add(name, { ...field, component: DeltaField }, { force: true });
4821 }
4822 let _onChangestep = 0;
4823
4824 Partner._records[0].turtles = [];
4825 Partner._onChanges = {
4826 turtles: function (obj) {
4827 // the onchange will either:
4828 // - create a second line if there is only one line
4829 // - edit the second line if there are two lines
4830 if (_onChangestep === 1) {
4831 obj.turtles = [
4832 [
4833 1,
4834 obj.turtles[0][1],
4835 {
4836 name: "first",
4837 },
4838 ],
4839 [
4840 0,
4841 0,
4842 {
4843 name: "second",
4844 turtle_int: -obj.turtles[0][2].turtle_int,
4845 },
4846 ],
4847 ];
4848 } else if (_onChangestep === 2) {
4849 obj.turtles = [
4850 [
4851 1,
4852 obj.turtles[1][1],
4853 {
4854 turtle_int: -obj.turtles[0][2].turtle_int,
4855 },
4856 ],
4857 ];
4858 }
4859 },
4860 };
4861
4862 await mountView({
4863 type: "form",
4864 resModel: "partner",
4865 arch: `
4866 <form>
4867 <field name="foo"/>
4868 <field name="turtles">
4869 <list editable="bottom">
4870 <field name="name" widget="char"/>
4871 <field name="turtle_int"/>
4872 </list>
4873 </field>
4874 </form>`,
4875 resId: 1,
4876 });
4877 expect(".o_data_row").toHaveCount(0);
4878
4879 await contains(".o_field_x2many_list_row_add a").click();
4880 // trigger the first onchange
4881 _onChangestep = 1;
4882 await contains('[name="turtle_int"] input').edit("10", { confirm: "blur" });
4883 // put the list back in non edit mode
4884 await click('[name="foo"] input');
4885 expect(queryAllTexts(".o_data_row")).toEqual(["first 10", "second -10"]);
4886
4887 // trigger the second onchange
4888 _onChangestep = 2;
4889 await contains(".o_field_x2many_list tbody tr td").click();
4890 await contains('[name="turtle_int"] input').edit("20", { confirm: "blur" });
4891 await click('[name="foo"] input');
4892 expect(queryAllTexts(".o_data_row")).toEqual(["first 20", "second -20"]);
4893 expect(".o_field_widget").toHaveCount(delta);
4894
4895 await clickSave();
4896 expect(queryAllTexts(".o_data_row")).toEqual(["first 20", "second -20"]);
4897 });
4898
4899 test("editable one2many with sub widgets are rendered in readonly", async () => {
4900 await mountView({
4901 type: "form",
4902 resModel: "partner",
4903 arch: `
4904 <form>
4905 <field name="turtles">
4906 <list editable="bottom">
4907 <field name="turtle_foo" widget="char" readonly="turtle_int == 11111"/>
4908 <field name="turtle_int"/>
4909 </list>
4910 </field>
4911 </form>`,
4912 resId: 1,
4913 });
4914
4915 expect(".o_form_view .o_field_x2many_list_row_add ").toHaveCount(1);
4916 expect(".o_form_view input").toHaveCount(0);
4917
4918 await contains(".o_field_x2many_list_row_add a").click();
4919 expect(".o_form_view .o_field_x2many_list_row_add ").toHaveCount(1);
4920 expect(".o_form_view input").toHaveCount(2);
4921 });
4922
4923 test("one2many editable list with onchange keeps the order", async () => {
4924 Partner._records[0].p = [1, 2, 4];
4925 Partner._onChanges = {
4926 p: function () {},
4927 };
4928
4929 await mountView({
4930 type: "form",
4931 resModel: "partner",
4932 arch: `
4933 <form>
4934 <field name="p">
4935 <list editable="bottom">
4936 <field name="name"/>
4937 </list>
4938 </field>
4939 </form>`,
4940 resId: 1,
4941 });
4942 expect(queryAllTexts(".o_data_cell")).toEqual(["first record", "second record", "aaa"]);
4943
4944 await contains(".o_data_row .o_data_cell").click();
4945 await contains(".o_selected_row .o_field_widget[name=name] input").edit("new", {
4946 confirm: "blur",
4947 });
4948 contains(".o_form_view").click();
4949 expect(queryAllTexts(".o_data_cell")).toEqual(["new", "second record", "aaa"]);
4950 });
4951
4952 test("one2many list: sort and save", async () => {
4953 Partner._records[0].p = [1, 2, 4];
4954
4955 await mountView({
4956 type: "form",
4957 resModel: "partner",
4958 arch: `
4959 <form>
4960 <field name="int_field"/>
4961 <field name="p">
4962 <list>
4963 <field name="name"/>
4964 </list>
4965 </field>
4966 </form>`,
4967 resId: 1,
4968 });
4969 expect(queryAllTexts(".o_data_cell")).toEqual(["first record", "second record", "aaa"]);
4970
4971 await contains("th.o_column_sortable").click();
4972 expect(queryAllTexts(".o_data_cell")).toEqual(["aaa", "first record", "second record"]);
4973
4974 await contains(".o_field_widget[name=int_field] input").edit("44");
4975 await clickSave();
4976 expect(queryAllTexts(".o_data_cell")).toEqual(["aaa", "first record", "second record"]);
4977 });
4978
4979 test("one2many list (editable): readonly domain is evaluated", async () => {
4980 Partner._records[0].p = [2, 4];
4981 Partner._records[1].product_id = false;
4982 Partner._records[2].product_id = 37;
4983
4984 await mountView({
4985 type: "form",
4986 resModel: "partner",
4987 arch: `
4988 <form>
4989 <field name="p">
4990 <list editable="top">
4991 <field name="name" readonly="not product_id"/>
4992 <field name="product_id"/>
4993 </list>
4994 </field>
4995 </form>`,
4996 resId: 1,
4997 });
4998
4999 // switch the first row in edition
5000 await contains(".o_data_cell").click();
5001 expect(".o_selected_row .o_field_widget:eq(0)").toHaveClass("o_readonly_modifier", {
5002 message: "first record should have name in readonly mode",
5003 });
5004 // switch the second row in edition
5005 await contains(".o_data_row:not(.o_selected_row) .o_data_cell").click();
5006 expect(".o_selected_row .o_field_widget").not.toHaveClass("o_readonly_modifier", {
5007 message: "second record should not have name in readonly mode",
5008 });
5009 });
5010
5011 test("pager of one2many field in new record", async () => {
5012 Partner._records[0].p = [];
5013
5014 await mountView({
5015 type: "form",
5016 resModel: "partner",
5017 arch: `
5018 <form>
5019 <field name="p">
5020 <list editable="top">
5021 <field name="foo"/>
5022 </list>
5023 </field>
5024 </form>`,
5025 });
5026 expect(".o_x2m_control_panel .o_pager").toHaveCount(0, {
5027 message: "o2m pager should be hidden",
5028 });
5029
5030 // click to create a subrecord
5031 await contains(".o_field_x2many_list_row_add a").click();
5032 expect("tr.o_data_row").toHaveCount(1);
5033 expect(".o_x2m_control_panel .o_pager").toHaveCount(0, {
5034 message: "o2m pager should be hidden",
5035 });
5036 });
5037
5038 test.tags("desktop");
5039 test("one2many list with a many2one", async () => {
5040 expect.assertions(5);
5041
5042 let checkOnchange = false;
5043 Partner._records[0].p = [2];
5044 Partner._records[1].product_id = 37;
5045 Partner._onChanges.p = () => {};
5046 Partner._views.form = '<form><field name="product_id"/></form>';
5047 onRpc("onchange", (args) => {
5048 if (checkOnchange) {
5049 expect(args.args[1].p).toEqual([[0, args.args[1].p[0][1], { product_id: 41 }]], {
5050 message: "should trigger onchange with correct parameters",
5051 });
5052 }
5053 });
5054 await mountView({
5055 type: "form",
5056 resModel: "partner",
5057 arch: `
5058 <form>
5059 <field name="p">
5060 <list>
5061 <field name="product_id"/>
5062 </list>
5063 </field>
5064 </form>`,
5065 resId: 1,
5066 });
5067 expect(".o_data_cell[data-tooltip='xphone']").toHaveCount(1);
5068 expect(".o_data_cell[data-tooltip='xpad']").toHaveCount(0);
5069
5070 await contains(".o_field_x2many_list_row_add a").click();
5071
5072 checkOnchange = true;
5073 await clickFieldDropdown("product_id");
5074 await contains('div[name="product_id"] .o_input_dropdown li:eq(1)').click();
5075
5076 await contains(".modal .modal-footer button").click();
5077 expect(".o_data_cell[data-tooltip='xphone']").toHaveCount(1);
5078 expect(".o_data_cell[data-tooltip='xpad']").toHaveCount(1);
5079 });
5080
5081 test.tags("desktop");
5082 test("one2many list with inline form view", async () => {
5083 expect.assertions(5);
5084
5085 Partner._records[0].p = [];
5086 onRpc("web_save", (args) => {
5087 expect(args.args[1].p).toEqual([
5088 [
5089 0,
5090 args.args[1].p[0][1],
5091 {
5092 foo: "My little Foo Value",
5093 int_field: 123,
5094 product_id: 41,
5095 },
5096 ],
5097 ]);
5098 });
5099 await mountView({
5100 type: "form",
5101 resModel: "partner",
5102 // don't remove foo field in sub tree view, it is useful to make sure
5103 // the foo fieldwidget does not crash because the foo field is not in the form view
5104 arch: `
5105 <form>
5106 <field name="p">
5107 <form>
5108 <field name="product_id"/>
5109 <field name="int_field"/>
5110 </form>
5111 <list>
5112 <field name="product_id"/>
5113 <field name="foo"/>
5114 </list>
5115 </field>
5116 </form>`,
5117 resId: 1,
5118 });
5119 await contains(".o_field_x2many_list_row_add a").click();
5120
5121 // write in the many2one field, value = 37 (xphone)
5122 await clickFieldDropdown("product_id");
5123 await press("Enter");
5124 await animationFrame();
5125
5126 // write in the integer field
5127 await contains('.modal .modal-body div[name="int_field"] input').edit("123", {
5128 confirm: false,
5129 });
5130
5131 // save and close
5132 await contains(".modal .o_form_button_save").click();
5133
5134 expect(".o_data_cell[data-tooltip='xphone']").toHaveCount(1);
5135
5136 // reopen the record in form view
5137 await contains(".o_data_cell[data-tooltip='xphone']").click();
5138 expect(".modal .modal-body input:eq(0)").toHaveValue("xphone");
5139
5140 await contains('.modal .modal-body div[name="int_field"] input').edit("456", {
5141 confirm: false,
5142 });
5143
5144 // discard
5145 await contains(".modal .o_form_button_cancel").click();
5146
5147 // reopen the record in form view
5148 await contains(".o_data_cell[data-tooltip='xphone']").click();
5149
5150 expect('.modal .modal-body div[name="int_field"] input').toHaveValue("123", {
5151 message: "should display 123 (previous change has been discarded)",
5152 });
5153
5154 // write in the many2one field, value = 41 (xpad)
5155 await clickFieldDropdown("product_id");
5156 await contains('div[name="product_id"] .o_input_dropdown li:eq(1)').click();
5157
5158 // save and close
5159 await contains(".modal .o_form_button_save").click();
5160
5161 expect(".o_data_cell[data-tooltip='xpad']").toHaveCount(1);
5162
5163 // save the record
5164 await clickSave();
5165 });
5166
5167 test.tags("desktop");
5168 test("one2many, edit record in dialog, save, re-edit, discard", async () => {
5169 Partner._records[0].p = [2];
5170
5171 await mountView({
5172 type: "form",
5173 resModel: "partner",
5174 arch: `
5175 <form>
5176 <field name="p">
5177 <form>
5178 <field name="int_field"/>
5179 </form>
5180 <list>
5181 <field name="int_field"/>
5182 </list>
5183 </field>
5184 </form>`,
5185 resId: 1,
5186 });
5187
5188 expect(".o_data_cell[name=int_field]").toHaveText("9");
5189
5190 await contains(".o_data_row .o_data_cell").click();
5191 expect(".modal .o_field_widget[name=int_field] input").toHaveValue("9");
5192
5193 await contains(".modal .o_field_widget[name=int_field] input").edit("123");
5194 await contains(`.modal .modal-footer .o_form_button_save`).click();
5195 expect(".o_data_cell[name=int_field]").toHaveText("123");
5196
5197 await contains(".o_data_row .o_data_cell").click();
5198 expect(".modal .o_field_widget[name=int_field] input").toHaveValue("123");
5199
5200 await contains(`.modal .modal-footer .o_form_button_cancel`).click();
5201 expect(".o_data_cell[name=int_field]").toHaveText("123");
5202
5203 await contains(".o_data_row .o_data_cell").click();
5204 expect(".modal .o_field_widget[name=int_field] input").toHaveValue("123");
5205 });
5206
5207 test.tags("desktop");
5208 test("one2many list with inline form view with context with parent key", async () => {
5209 expect.assertions(2);
5210
5211 Partner._records[0].p = [2];
5212 Partner._records[0].product_id = 41;
5213 Partner._records[1].product_id = 37;
5214 onRpc("web_name_search", (args) => {
5215 expect(args.kwargs.context.partner_foo).toBe("yop", {
5216 message: "should have correctly evaluated parent foo field",
5217 });
5218 expect(args.kwargs.context.lalala).toBe(41, {
5219 message: "should have correctly evaluated parent product_id field",
5220 });
5221 });
5222 await mountView({
5223 type: "form",
5224 resModel: "partner",
5225 arch: `
5226 <form>
5227 <field name="foo"/>
5228 <field name="product_id"/>
5229 <field name="p">
5230 <form>
5231 <field name="product_id" context="{'partner_foo':parent.foo, 'lalala': parent.product_id}"/>
5232 </form>
5233 <list>
5234 <field name="product_id"/>
5235 </list>
5236 </field>
5237 </form>`,
5238 resId: 1,
5239 });
5240
5241 // open a modal
5242 await contains("tr.o_data_row td[data-tooltip='xphone']").click();
5243
5244 // write in the many2one field
5245 await contains(".modal .o_field_many2one input").click();
5246 });
5247
5248 test.tags("desktop");
5249 test("value of invisible x2many fields is correctly evaluated in context", async () => {
5250 expect.assertions(2);
5251
5252 Partner._records[0].timmy = [12];
5253 Partner._records[0].p = [2, 4];
5254 onRpc("web_name_search", (args) => {
5255 const { p, timmy } = args.kwargs.context;
5256 expect(p).toEqual([2, 4]);
5257 expect(timmy).toEqual([12]);
5258 });
5259 await mountView({
5260 type: "form",
5261 resModel: "partner",
5262 arch: `
5263 <form>
5264 <field name="product_id" context="{'p': p, 'timmy': timmy}"/>
5265 <field name="p" invisible="1"/>
5266 <field name="timmy" invisible="1"/>
5267 </form>`,
5268 resId: 1,
5269 });
5270
5271 await contains(".o_field_widget[name=product_id] input").click();
5272 });
5273
5274 test.tags("desktop");
5275 test("one2many list, editable, with many2one and with context with parent key", async () => {
5276 expect.assertions(1);
5277
5278 Partner._records[0].p = [2];
5279 Partner._records[1].product_id = 37;
5280 onRpc("web_name_search", (args) => {
5281 expect(args.kwargs.context.partner_foo).toBe("yop", {
5282 message: "should have correctly evaluated parent foo field",
5283 });
5284 });
5285 await mountView({
5286 type: "form",
5287 resModel: "partner",
5288 arch: `
5289 <form>
5290 <field name="foo"/>
5291 <field name="p">
5292 <list editable="bottom">
5293 <field name="product_id" context="{'partner_foo':parent.foo}"/>
5294 </list>
5295 </field>
5296 </form>`,
5297 resId: 1,
5298 });
5299
5300 await contains("tr.o_data_row td[data-tooltip='xphone']").click();
5301
5302 // trigger a name search
5303 await contains("table td input").click();
5304 });
5305
5306 test("one2many list, multi page, with many2one and with context with parent key", async () => {
5307 Partner._records[0].turtles = [1, 2, 3];
5308 onRpc("web_read", ({ method, model, kwargs }) => {
5309 if (model === "turtle") {
5310 expect.step("web_read turtle");
5311 expect(kwargs.specification.product_id.context).toEqual(
5312 { partner_foo: "yop" },
5313 { message: "should have correctly evaluated parent foo field" }
5314 );
5315 }
5316 });
5317 await mountView({
5318 type: "form",
5319 resModel: "partner",
5320 arch: `
5321 <form>
5322 <field name="foo"/>
5323 <field name="turtles">
5324 <list limit="2">
5325 <field name="product_id" context="{'partner_foo': parent.foo}"/>
5326 </list>
5327 </field>
5328 </form>`,
5329 resId: 1,
5330 });
5331
5332 await contains(".o_x2m_control_panel .o_pager_next").click();
5333 expect.verifySteps(["web_read turtle"]);
5334 });
5335
5336 test("one2many list, editable, with a date in the context", async () => {
5337 expect.assertions(1);
5338
5339 Partner._records[0].p = [2];
5340 Partner._records[1].product_id = 37;
5341 onRpc("onchange", (args) => {
5342 expect(args.kwargs.context.date).toBe("2017-01-25", {
5343 message: "should have properly evaluated date key in context",
5344 });
5345 });
5346 await mountView({
5347 type: "form",
5348 resModel: "partner",
5349 arch: `
5350 <form>
5351 <group>
5352 <field name="date"/>
5353 <field name="p" context="{'date':date}">
5354 <list editable="top">
5355 <field name="date"/>
5356 </list>
5357 </field>
5358 </group>
5359 </form>`,
5360 resId: 2,
5361 });
5362
5363 await contains(".o_field_x2many_list_row_add a").click();
5364 });
5365
5366 test("one2many field with context", async () => {
5367 expect.assertions(2);
5368 onRpc("onchange", (args) => {
5369 expect(args.kwargs.context.turtles).toEqual([2], {
5370 message: "should have properly evaluated turtles key in context",
5371 });
5372 });
5373 await mountView({
5374 type: "form",
5375 resModel: "partner",
5376 arch: `
5377 <form>
5378 <group>
5379 <field name="turtles" context="{'turtles':turtles}">
5380 <list editable="bottom">
5381 <field name="turtle_foo"/>
5382 </list>
5383 </field>
5384 </group>
5385 </form>`,
5386 resId: 1,
5387 });
5388
5389 await contains(".o_field_x2many_list_row_add a").click();
5390 await contains('[name="turtle_foo"] input').edit("hammer", { confirm: false });
5391 await contains(".o_field_x2many_list_row_add a").click();
5392 });
5393
5394 test("one2many list edition, some basic functionality", async () => {
5395 Partner._fields.foo = fields.Char({ default: false });
5396
5397 await mountView({
5398 type: "form",
5399 resModel: "partner",
5400 arch: `
5401 <form>
5402 <field name="p">
5403 <list editable="top">
5404 <field name="foo"/>
5405 </list>
5406 </field>
5407 </form>`,
5408 resId: 1,
5409 });
5410 await contains(".o_field_x2many_list_row_add a").click();
5411 expect("td .o_field_widget input").toHaveCount(1);
5412
5413 await contains("td .o_field_widget input").edit("a", { confirm: false });
5414 expect("td .o_field_widget input").toHaveCount(1, {
5415 message: "should not have unselected the row after edition",
5416 });
5417
5418 await contains("td .o_field_widget input").edit("abc", { confirm: false });
5419 await clickSave();
5420 expect("td:contains('abc')").toHaveCount(1);
5421 });
5422
5423 test("one2many list, the context is properly evaluated and sent", async () => {
5424 expect.assertions(2);
5425 onRpc("onchange", (args) => {
5426 const context = args.kwargs.context;
5427 expect(context.hello).toBe("world");
5428 expect(context.abc).toBe(10);
5429 });
5430 await mountView({
5431 type: "form",
5432 resModel: "partner",
5433 arch: `
5434 <form>
5435 <field name="int_field"/>
5436 <field name="p" context="{'hello': 'world', 'abc': int_field}">
5437 <list editable="top">
5438 <field name="foo"/>
5439 </list>
5440 </field>
5441 </form>`,
5442 resId: 1,
5443 });
5444
5445 await contains(".o_field_x2many_list_row_add a").click();
5446 });
5447
5448 test("one2many list not editable, the context is properly evaluated and sent", async () => {
5449 expect.assertions(4);
5450 Turtle._views = {
5451 form: '<form><field name="turtle_foo"/><field name="turtle_int" readonly="context.get(\'abc\') == 10"/></form>',
5452 };
5453 onRpc("turtle", "get_views", ({ kwargs }) => {
5454 const context = kwargs.context;
5455 expect(context).toEqual({
5456 allowed_company_ids: [1],
5457 lang: "en",
5458 tz: "taht",
5459 uid: 7,
5460 });
5461 });
5462 await mountView({
5463 type: "form",
5464 resModel: "partner",
5465 arch: `
5466 <form>
5467 <field name="int_field"/>
5468 <field name="turtles" context="{'hello': 'world', 'abc': int_field, 'default_turtle_int': 5}">
5469 <list>
5470 <field name="turtle_foo"/>
5471 </list>
5472 </field>
5473 </form>`,
5474 resId: 1,
5475 });
5476
5477 await contains(".o_field_x2many_list_row_add a").click();
5478 expect(".modal").toHaveCount(1);
5479 expect(".o_readonly_modifier").toHaveCount(1);
5480 expect(".o_readonly_modifier").toHaveText("5");
5481 });
5482
5483 test.tags("desktop");
5484 test("one2many with many2many widget: create", async () => {
5485 expect.assertions(10);
5486
5487 Turtle._views = {
5488 list: `
5489 <list>
5490 <field name="name"/>
5491 <field name="turtle_foo"/>
5492 <field name="turtle_bar"/>
5493 <field name="product_id"/>
5494 </list>`,
5495 search: `
5496 <search>
5497 <field name="turtle_foo"/>
5498 <field name="turtle_bar"/>
5499 <field name="product_id"/>
5500 </search>`,
5501 };
5502
5503 let expectedCommand;
5504 onRpc("turtle", "web_save", (args) => {
5505 expect.step("turtle save");
5506 });
5507 onRpc("partner", "web_save", (args) => {
5508 expect(args.args[0][0]).toBe(1, {
5509 message: "should write on the partner record 1",
5510 });
5511 expect(args.args[1].turtles).toEqual(expectedCommand, {
5512 message: "should send only a 'LINK TO' command",
5513 });
5514 });
5515 await mountView({
5516 type: "form",
5517 resModel: "partner",
5518 arch: `
5519 <form>
5520 <field name="turtles" widget="many2many">
5521 <list>
5522 <field name="turtle_foo"/>
5523 <field name="turtle_qux"/>
5524 <field name="turtle_int"/>
5525 <field name="product_id"/>
5526 </list>
5527 <form>
5528 <group>
5529 <field name="turtle_foo"/>
5530 <field name="turtle_bar"/>
5531 <field name="turtle_int"/>
5532 <field name="product_id"/>
5533 </group>
5534 </form>
5535 </field>
5536 </form>`,
5537 resId: 1,
5538 });
5539
5540 await contains(".o_field_x2many_list_row_add a").click();
5541
5542 expect(".modal .o_data_row").toHaveCount(2);
5543
5544 await contains(".modal .o_data_row .o_list_record_selector input").click();
5545 await animationFrame(); // additional render due to the change of selection (done in owl, not pure js)
5546 await contains(".modal .o_select_button").click();
5547 expectedCommand = [[4, 1]];
5548 await clickSave();
5549
5550 await contains(".o_field_x2many_list_row_add a").click();
5551 expect(".modal .o_data_row").toHaveCount(1);
5552
5553 await contains(".modal-footer button:eq(1)").click();
5554 await contains('.modal .o_field_widget[name="turtle_foo"] input').edit("tototo", {
5555 confirm: false,
5556 });
5557 await contains('.modal .o_field_widget[name="turtle_int"] input').edit(50, { confirm: false });
5558 await clickFieldDropdown("product_id");
5559 await press("Enter");
5560 await animationFrame();
5561
5562 await contains(".modal-footer button").click();
5563 expect.verifySteps(["turtle save"]);
5564
5565 expect(".modal").toHaveCount(0);
5566 expect(".o_data_row").toHaveCount(3);
5567 expect(queryAllTexts(".o_data_row")).toEqual(
5568 ["blip 1.5 9", "yop 1.5 0", "tototo 1.5 50 xphone"],
5569 {
5570 message: "should display the record values in one2many list",
5571 }
5572 );
5573
5574 expectedCommand = [[4, 4]];
5575 await clickSave();
5576 });
5577
5578 test.tags("desktop");
5579 test("one2many with many2many widget: edition", async () => {
5580 expect.assertions(7);
5581
5582 Turtle._views = {
5583 list: `
5584 <list>
5585 <field name="name"/>
5586 <field name="turtle_foo"/>
5587 <field name="turtle_bar"/>
5588 <field name="product_id"/>
5589 </list>`,
5590 search: `
5591 <search>
5592 <field name="turtle_foo"/>
5593 <field name="turtle_bar"/>
5594 <field name="product_id"/>
5595 </search>`,
5596 };
5597 onRpc("turtle", "web_save", ({ args }) => {
5598 expect(args[0]).toHaveLength(1);
5599 expect(args[1]).toEqual(
5600 { product_id: 37 },
5601 { message: "should write only the product_id on the turtle record" }
5602 );
5603 });
5604 onRpc("partner", "web_save", ({ args }) => {
5605 expect(args[0][0]).toBe(1, {
5606 message: "should write on the partner record 1",
5607 });
5608 expect(args[1].turtles[0][0]).toBe(4, {
5609 message: "should send only a 'link to' command",
5610 });
5611 });
5612 await mountView({
5613 type: "form",
5614 resModel: "partner",
5615 arch: `
5616 <form>
5617 <field name="turtles" widget="many2many">
5618 <list>
5619 <field name="turtle_foo"/>
5620 <field name="turtle_qux"/>
5621 <field name="turtle_int"/>
5622 <field name="product_id"/>
5623 </list>
5624 <form>
5625 <group>
5626 <field name="turtle_foo"/>
5627 <field name="turtle_bar"/>
5628 <field name="turtle_int"/>
5629 <field name="turtle_trululu"/>
5630 <field name="product_id"/>
5631 </group>
5632 </form>
5633 </field>
5634 </form>`,
5635 resId: 1,
5636 });
5637
5638 await contains(".o_data_cell").click();
5639 expect(".modal .modal-title:eq(0)").toHaveText("Open: one2many turtle field", {
5640 message: "modal should use the python field string as title",
5641 });
5642 await contains(".modal .o_form_button_cancel").click();
5643
5644 // edit the first one2many record
5645 await contains(".o_data_cell:eq(0)").click();
5646 await clickFieldDropdown("product_id");
5647 await press("Enter");
5648 await animationFrame();
5649 await contains(".modal .o_form_button_save").click();
5650
5651 // add a one2many record
5652 await contains(".o_field_x2many_list_row_add a").click();
5653 await contains(".modal .o_data_row:first .o_list_record_selector input:eq(0)").click();
5654 await animationFrame(); // wait for re-rendering because of the change of selection
5655 await contains(".modal .o_select_button:eq(0)").click();
5656
5657 // edit the second one2many record
5658 await contains(".o_data_row:eq(1) .o_data_cell:eq(0)").click();
5659 await clickFieldDropdown("product_id");
5660 await press("Enter");
5661 await animationFrame();
5662 await contains(".modal .modal-footer button:first:eq(0)").click();
5663
5664 await clickSave();
5665 });
5666
5667 test("new record, the context is properly evaluated and sent", async () => {
5668 expect.assertions(2);
5669
5670 Partner._fields.int_field = fields.Integer({ default: 17 });
5671 let n = 0;
5672 onRpc("onchange", (args) => {
5673 n++;
5674 if (n === 2) {
5675 const context = args.kwargs.context;
5676 expect(context.hello).toBe("world");
5677 expect(context.abc).toBe(17);
5678 }
5679 });
5680 await mountView({
5681 type: "form",
5682 resModel: "partner",
5683 arch: `
5684 <form>
5685 <field name="int_field"/>
5686 <field name="p" context="{'hello': 'world', 'abc': int_field}">
5687 <list editable="top">
5688 <field name="foo"/>
5689 </list>
5690 </field>
5691 </form>`,
5692 });
5693
5694 await contains(".o_field_x2many_list_row_add a").click();
5695 });
5696
5697 test("parent data is properly sent on an onchange rpc", async () => {
5698 expect.assertions(1);
5699 onRpc("onchange", (args) => {
5700 const fieldValues = args.args[1];
5701 expect(fieldValues.trululu).toEqual(
5702 { foo: "hello", id: 1 },
5703 { message: "should have properly sent the parent changes" }
5704 );
5705 });
5706 await mountView({
5707 type: "form",
5708 resModel: "partner",
5709 arch: `
5710 <form>
5711 <field name="name"/>
5712 <field name="foo"/>
5713 <field name="p">
5714 <list editable="top">
5715 <field name="bar"/>
5716 </list>
5717 </field>
5718 </form>`,
5719 resId: 1,
5720 });
5721
5722 await contains("[name=foo] input").edit("hello", { confirm: false });
5723 await contains(".o_field_x2many_list_row_add a").click();
5724 });
5725
5726 test("parent data is properly sent on an onchange rpc (existing x2many record)", async () => {
5727 expect.assertions(4);
5728
5729 Partner._onChanges = {
5730 name: function () {},
5731 foo: function () {},
5732 };
5733 Partner._records[0].p = [1];
5734 Partner._records[0].turtles = [2];
5735
5736 let count = 0;
5737 onRpc("onchange", (args) => {
5738 const fieldValues = args.args[1];
5739 if (count === 1) {
5740 expect(fieldValues.trululu).toEqual({
5741 foo: "hello",
5742 id: 1,
5743 });
5744 } else if (count === 2) {
5745 expect(fieldValues.trululu).toEqual({
5746 foo: "hello",
5747 id: 1,
5748 p: [[1, 1, { name: "new val" }]],
5749 });
5750 }
5751 count++;
5752 });
5753 await mountView({
5754 type: "form",
5755 resModel: "partner",
5756 arch: `
5757 <form>
5758 <field name="name"/>
5759 <field name="foo"/>
5760 <field name="p">
5761 <list editable="top">
5762 <field name="name"/>
5763 <field name="foo"/>
5764 <field name="turtles" widget="many2many_tags"/>
5765 </list>
5766 </field>
5767 </form>`,
5768 resId: 1,
5769 });
5770 expect(".o_data_row").toHaveCount(1);
5771
5772 await contains("[name=foo] input").edit("hello", { confirm: false });
5773 await contains(".o_data_row .o_data_cell").click();
5774 expect(".o_data_row.o_selected_row").toHaveCount(1);
5775
5776 await contains(".o_selected_row .o_field_widget[name=name] input").edit("new val", {
5777 confirm: false,
5778 });
5779 await contains(".o_selected_row .o_field_widget[name=foo] input").edit("new foo", {
5780 confirm: "blur",
5781 });
5782 });
5783
5784 test("parent data is properly sent on an onchange rpc, new record", async () => {
5785 expect.assertions(2);
5786
5787 Turtle._onChanges = { turtle_bar: function () {} };
5788 onRpc((args) => {
5789 expect.step(args.method);
5790 });
5791 onRpc("turtle", "onchange", (args) => {
5792 expect(args.args[1].turtle_trululu.foo).toBe("My little Foo Value", {
5793 message: "should have properly sent the parent foo value",
5794 });
5795 });
5796 await mountView({
5797 type: "form",
5798 resModel: "partner",
5799 arch: `
5800 <form>
5801 <field name="foo"/>
5802 <field name="turtles">
5803 <list editable="top">
5804 <field name="turtle_bar"/>
5805 </list>
5806 </field>
5807 </form>`,
5808 });
5809 await contains(".o_field_x2many_list_row_add a").click();
5810 expect.verifySteps(["get_views", "onchange", "onchange"]);
5811 });
5812
5813 test("id in one2many obtained in onchange is properly set", async () => {
5814 Partner._onChanges.turtles = function (obj) {
5815 obj.turtles = [
5816 [4, 3],
5817 [1, 3, { turtle_foo: "kawa" }],
5818 ];
5819 };
5820 await mountView({
5821 type: "form",
5822 resModel: "partner",
5823 arch: `
5824 <form>
5825 <field name="turtles">
5826 <list>
5827 <field name="id"/>
5828 <field name="turtle_foo"/>
5829 </list>
5830 </field>
5831 </form>`,
5832 });
5833
5834 expect(queryAllTexts("tr.o_data_row .o_data_cell")).toEqual(["3", "kawa"], {
5835 message: "should have properly displayed id and foo field",
5836 });
5837 });
5838
5839 test("id field in one2many in a new record", async () => {
5840 expect.assertions(1);
5841 onRpc("web_save", (args) => {
5842 const virtualID = args.args[1].turtles[0][1];
5843 expect(args.args[1].turtles).toEqual([[0, virtualID, { turtle_foo: "cat" }]], {
5844 message: "should send proper commands",
5845 });
5846 });
5847 await mountView({
5848 type: "form",
5849 resModel: "partner",
5850 arch: `
5851 <form>
5852 <field name="turtles">
5853 <list editable="bottom">
5854 <field name="id" invisible="1"/>
5855 <field name="turtle_foo"/>
5856 </list>
5857 </field>
5858 </form>`,
5859 });
5860 await contains(".o_field_x2many_list_row_add a").click();
5861 await contains('td [name="turtle_foo"] input').edit("cat", { confirm: false });
5862 await clickSave();
5863 });
5864
5865 test("sub form view with a required field", async () => {
5866 Partner._fields.foo = fields.Char({ required: true });
5867
5868 await mountView({
5869 type: "form",
5870 resModel: "partner",
5871 arch: `
5872 <form>
5873 <field name="p">
5874 <form>
5875 <group><field name="foo"/></group>
5876 </form>
5877 <list>
5878 <field name="foo"/>
5879 </list>
5880 </field>
5881 </form>`,
5882 resId: 1,
5883 });
5884
5885 await contains(".o_field_x2many_list_row_add a").click();
5886 await contains(".modal-footer button.btn-primary").click();
5887
5888 expect(".modal").toHaveCount(1);
5889 expect(".modal label.o_field_invalid").toHaveCount(1);
5890 });
5891
5892 test("one2many list with action button", async () => {
5893 expect.assertions(4);
5894
5895 Partner._records[0].p = [2];
5896 mockService("action", {
5897 doActionButton: (params) => {
5898 expect(params.resId).toBe(2);
5899 expect(params.resModel).toBe("partner");
5900 expect(params.name).toBe("method_name");
5901 expect(params.type).toBe("object");
5902 },
5903 });
5904 await mountView({
5905 type: "form",
5906 resModel: "partner",
5907 arch: `
5908 <form>
5909 <field name="int_field"/>
5910 <field name="p">
5911 <list>
5912 <field name="foo"/>
5913 <button name="method_name" type="object" icon="fa-plus"/>
5914 </list>
5915 </field>
5916 </form>`,
5917 resId: 1,
5918 });
5919
5920 await contains(".o_list_button button").click();
5921 });
5922
5923 test("one2many kanban with action button", async () => {
5924 expect.assertions(4);
5925
5926 Partner._records[0].p = [2];
5927 mockService("action", {
5928 doActionButton: (params) => {
5929 expect(params.resId).toBe(2);
5930 expect(params.resModel).toBe("partner");
5931 expect(params.name).toBe("method_name");
5932 expect(params.type).toBe("object");
5933 },
5934 });
5935 await mountView({
5936 type: "form",
5937 resModel: "partner",
5938 arch: `
5939 <form>
5940 <field name="p">
5941 <kanban>
5942 <templates>
5943 <t t-name="card">
5944 <field name="foo"/>
5945 <button name="method_name" type="object" class="fa fa-plus"/>
5946 </t>
5947 </templates>
5948 </kanban>
5949 </field>
5950 </form>`,
5951 resId: 1,
5952 });
5953
5954 await contains("button.oe_kanban_action").click();
5955 });
5956
5957 test("one2many without inline tree arch", async () => {
5958 Partner._records[0].turtles = [2, 3];
5959 Turtle._views = {
5960 list: `
5961 <list>
5962 <field name="turtle_bar"/>
5963 <field name="name"/>
5964 <field name="partner_ids"/>
5965 </list>`,
5966 };
5967 await mountView({
5968 type: "form",
5969 resModel: "partner",
5970 // should not call loadViews for the field with many2many_tags widget,
5971 // nor for the invisible field
5972 arch: `
5973 <form>
5974 <group>
5975 <field name="p" widget="many2many_tags"/>
5976 <field name="turtles"/>
5977 <field name="timmy" invisible="1"/>
5978 </group>
5979 </form>`,
5980 resId: 1,
5981 });
5982
5983 expect('.o_field_widget[name="turtles"] .o_list_renderer').toHaveCount(1, {
5984 message: "should display one2many list view in the modal",
5985 });
5986
5987 expect(".o_data_row").toHaveCount(2);
5988 });
5989
5990 test.tags("desktop");
5991 test("many2one and many2many in one2many", async () => {
5992 expect.assertions(8);
5993
5994 Turtle._records[1].product_id = 37;
5995 Partner._records[0].turtles = [2, 3];
5996 onRpc("web_save", (args) => {
5997 expect(args.args[1].turtles).toEqual(
5998 [
5999 [
6000 1,
6001 2,
6002 {
6003 partner_ids: [
6004 [3, 4],
6005 [4, 1],
6006 ],
6007 product_id: 41,
6008 },
6009 ],
6010 ],
6011 { message: "generated commands should be correct" }
6012 );
6013 });
6014 await mountView({
6015 type: "form",
6016 resModel: "partner",
6017 arch: `
6018 <form>
6019 <group>
6020 <field name="int_field"/>
6021 <field name="turtles">
6022 <list editable="top">
6023 <field name="name"/>
6024 <field name="product_id"/>
6025 <field name="partner_ids" widget="many2many_tags"/>
6026 </list>
6027 </field>
6028 </group>
6029 </form>`,
6030 resId: 1,
6031 });
6032
6033 expect(".o_data_row").toHaveCount(2);
6034 expect(".o_data_row .o_list_many2one").toHaveText("xphone");
6035 expect('.o_data_row td div[name="partner_ids"] .badge').toHaveCount(2);
6036
6037 // edit the m2m of first row
6038 await contains(".o_list_renderer tbody td").click();
6039
6040 expect(queryAllTexts(".o_selected_row .o_field_many2many_tags .badge")).toEqual([
6041 "second record",
6042 "aaa",
6043 ]);
6044
6045 // remove a tag
6046 await contains(".o_selected_row .o_field_many2many_tags .badge .o_delete:eq(1)").click();
6047
6048 expect(queryAllTexts(".o_selected_row .o_field_many2many_tags .badge")).toEqual([
6049 "second record",
6050 ]);
6051 // add a tag
6052 await contains('div[name="partner_ids"] input').click();
6053 await contains('div[name="partner_ids"] .o_input_dropdown li').click(); // xpad
6054
6055 expect(queryAllTexts(".o_selected_row .o_field_many2many_tags .badge")).toEqual([
6056 "second record",
6057 "first record",
6058 ]);
6059
6060 // edit the m2o of first row
6061 await clickFieldDropdown("product_id");
6062 await contains('div[name="product_id"] .o_input_dropdown li:eq(1)').click(); // xpad
6063
6064 expect(".o_selected_row .o_field_many2one input").toHaveValue("xpad");
6065
6066 // save (should correctly generate the commands)
6067 await clickSave();
6068 });
6069
6070 test("many2manytag in one2many, onchange, some modifiers, and more than one page", async () => {
6071 Partner._records[0].turtles = [1, 2, 3];
6072 Partner._onChanges.turtles = function () {};
6073 onRpc((args) => {
6074 expect.step(args.method);
6075 });
6076 await mountView({
6077 type: "form",
6078 resModel: "partner",
6079 arch: `
6080 <form>
6081 <field name="turtles">
6082 <list editable="top" limit="2">
6083 <field name="turtle_foo"/>
6084 <field name="partner_ids" widget="many2many_tags" readonly="turtle_foo == 'a'"/>
6085 </list>
6086 </field>
6087 </form>`,
6088 resId: 1,
6089 });
6090 expect(".o_data_row").toHaveCount(2);
6091
6092 await contains(".o_list_record_remove").click();
6093 expect(".o_data_row").toHaveCount(2);
6094
6095 await contains(".o_list_record_remove").click();
6096 expect(".o_data_row").toHaveCount(1);
6097
6098 expect.verifySteps([
6099 "get_views", // main form view
6100 "web_read", // initial read on partner
6101 "web_read", // after first delete, read on turtle (to fetch 3rd record)
6102 "onchange", // after first delete, onchange on field turtles
6103 "onchange", // onchange after second delete
6104 ]);
6105 });
6106
6107 test.tags("desktop");
6108 test("onchange many2many in one2many list editable", async () => {
6109 Product._records.push({
6110 id: 1,
6111 name: "xenomorphe",
6112 });
6113
6114 Turtle._onChanges = {
6115 product_id: function (rec) {
6116 if (rec.product_id === 41) {
6117 rec.partner_ids = [[4, 1]];
6118 } else if (rec.product_id === 37) {
6119 rec.partner_ids = [[4, 2]];
6120 }
6121 },
6122 };
6123 let enableOnchange = false;
6124 const partnerOnchange = function (rec) {
6125 if (!enableOnchange) {
6126 return;
6127 }
6128 rec.turtles = [
6129 [
6130 0,
6131 0,
6132 {
6133 name: "new line",
6134 product_id: [37, "xphone"],
6135 partner_ids: [[4, 1]],
6136 },
6137 ],
6138 [
6139 1,
6140 rec.turtles[0][1],
6141 {
6142 product_id: [1, "xenomorphe"],
6143 partner_ids: rec.turtles[0][2].partner_ids.length
6144 ? [
6145 [3, 1],
6146 [4, 2],
6147 ]
6148 : [[4, 2]],
6149 },
6150 ],
6151 ];
6152 };
6153
6154 Partner._onChanges = {
6155 int_field: partnerOnchange,
6156 turtles: partnerOnchange,
6157 };
6158
6159 await mountView({
6160 type: "form",
6161 resModel: "partner",
6162 arch: `
6163 <form>
6164 <group>
6165 <field name="int_field"/>
6166 <field name="turtles">
6167 <list editable="bottom">
6168 <field name="name"/>
6169 <field name="product_id"/>
6170 <field name="partner_ids" widget="many2many_tags"/>
6171 </list>
6172 </field>
6173 </group>
6174 </form>`,
6175 });
6176
6177 // add new line (first, xpad)
6178 await contains(".o_field_x2many_list_row_add a").click();
6179 await contains('div[name="name"] input').edit("first", { confirm: false });
6180 await clickFieldDropdown("product_id");
6181 await contains('div[name="product_id"] .o_input_dropdown li:eq(1)').click(); // xpad
6182
6183 expect(".o_field_many2many_tags .o_tags_input").toHaveCount(1, {
6184 message: "should display the line in editable mode",
6185 });
6186 expect(".o_field_many2one input").toHaveValue("xpad");
6187 expect(".o_field_many2many_tags .o_tag_badge_text").toHaveText("first record");
6188 expect(".o_data_cell .o_required_modifier input").toHaveValue("xpad");
6189
6190 await contains('div[name="int_field"] input').click();
6191
6192 expect(".o_field_many2many_tags input.o_input").toHaveCount(0, {
6193 message: "should display the tag in readonly",
6194 });
6195 // enable the many2many onchange and generate it
6196 enableOnchange = true;
6197 await contains('div[name="int_field"] input').edit("10");
6198
6199 expect(queryAllTexts(".o_data_cell")).toEqual([
6200 "first",
6201 "xenomorphe",
6202 "second record",
6203 "new line",
6204 "xphone",
6205 "first record",
6206 ]);
6207
6208 // disable the many2many onchange
6209 enableOnchange = false;
6210
6211 // remove and start over
6212 await contains(".o_list_record_remove button").click();
6213 await contains(".o_list_record_remove button").click();
6214
6215 // enable the many2many onchange
6216 enableOnchange = true;
6217 // add new line (first, xenomorphe)
6218 await contains(".o_field_x2many_list_row_add a").click();
6219 await contains('div[name="name"] input').edit("first", { confirm: false });
6220 await clickFieldDropdown("product_id");
6221 await contains('div[name="product_id"] .o_input_dropdown li:eq(2)').click(); // xenomorphe
6222
6223 expect(".o_field_many2many_tags .o_tags_input").toHaveCount(1, {
6224 message: "should display the line in editable mode",
6225 });
6226 expect('div[name="product_id"] input').toHaveValue("xenomorphe");
6227 expect(".o_field_many2many_tags .o_tag_badge_text:eq(0)").toHaveText("second record");
6228
6229 // put list in readonly mode
6230 await contains('div[name="int_field"] input').click();
6231
6232 expect(queryAllTexts(".o_data_cell")).toEqual([
6233 "first",
6234 "xenomorphe",
6235 "second record",
6236 "new line",
6237 "xphone",
6238 "first record",
6239 ]);
6240
6241 expect(".o_field_many2many_tags input.o_input").toHaveCount(0, {
6242 message: "should display the tag in readonly",
6243 });
6244
6245 await contains('div[name="int_field"] input').edit("10");
6246
6247 expect(queryAllTexts(".o_data_cell")).toEqual([
6248 "first",
6249 "xenomorphe",
6250 "second record",
6251 "new line",
6252 "xphone",
6253 "first record",
6254 ]);
6255
6256 await clickSave();
6257
6258 expect(queryAllTexts(".o_data_cell")).toEqual([
6259 "first",
6260 "xenomorphe",
6261 "second record",
6262 "new line",
6263 "xphone",
6264 "first record",
6265 ]);
6266 });
6267
6268 test.tags("desktop");
6269 test("load view for x2many in one2many", async () => {
6270 Turtle._records[1].product_id = 37;
6271 Partner._records[0].turtles = [2, 3];
6272 Partner._records[2].turtles = [1, 3];
6273 Partner._views = {
6274 list: `
6275 <list>
6276 <field name="name"/>
6277 </list>`,
6278 };
6279
6280 await mountView({
6281 type: "form",
6282 resModel: "partner",
6283 arch: `
6284 <form>
6285 <group>
6286 <field name="int_field"/>
6287 <field name="turtles">
6288 <form>
6289 <group>
6290 <field name="product_id"/>
6291 <field name="partner_ids"/>
6292 </group>
6293 </form>
6294 <list>
6295 <field name="name"/>
6296 </list>
6297 </field>
6298 </group>
6299 </form>`,
6300 resId: 1,
6301 });
6302
6303 expect(".o_data_row").toHaveCount(2);
6304
6305 await contains(".o_data_row td").click();
6306
6307 expect('.modal div[name="partner_ids"] .o_list_renderer').toHaveCount(1);
6308 });
6309
6310 test.tags("desktop");
6311 test("one2many (who contains a one2many) with list view and without form view", async () => {
6312 await mountView({
6313 type: "form",
6314 resModel: "partner",
6315 arch: `
6316 <form edit="0">
6317 <group>
6318 <field name="turtles">
6319 <list>
6320 <field name="partner_ids"/>
6321 </list>
6322 <form>
6323 <field name="turtle_foo"/>
6324 </form>
6325 </field>
6326 </group>
6327 </form>`,
6328 resId: 1,
6329 });
6330
6331 await contains(".o_data_row td").click();
6332
6333 expect('.modal div[name="turtle_foo"]').toHaveText("blip");
6334 });
6335
6336 test.tags("desktop");
6337 test("one2many with x2many in form view (but not in list view)", async () => {
6338 expect.assertions(1);
6339
6340 // avoid error when saving the edited related record (because the
6341 // related x2m field is unknown in the inline list view)
6342 // also ensure that the changes are correctly saved
6343 onRpc("web_save", (args) => {
6344 expect(args.args[1].turtles).toEqual([
6345 [
6346 1,
6347 2,
6348 {
6349 partner_ids: [[4, 1]],
6350 },
6351 ],
6352 ]);
6353 });
6354 await mountView({
6355 type: "form",
6356 resModel: "partner",
6357 arch: `
6358 <form>
6359 <group>
6360 <field name="turtles">
6361 <list>
6362 <field name="turtle_foo"/>
6363 </list>
6364 <form>
6365 <field name="partner_ids" widget="many2many_tags"/>
6366 </form>
6367 </field>
6368 </group>
6369 </form>`,
6370 resId: 1,
6371 });
6372
6373 await contains(".o_data_row td").click(); // edit first record
6374
6375 await contains('div[name="partner_ids"] input').click();
6376 await contains('div[name="partner_ids"] .o_input_dropdown li').click();
6377
6378 // add a many2many tag and save
6379 await contains(".modal .o_field_many2many_tags input").edit("test", { confirm: false });
6380
6381 await contains(".modal .modal-footer .btn-primary").click(); // save
6382
6383 await clickSave();
6384 });
6385
6386 test.tags("desktop");
6387 test("many2many list in a one2many opened by a many2one", async () => {
6388 expect.assertions(1);
6389
6390 Turtle._records[1].turtle_trululu = 2;
6391 Partner._views = { form: '<form><field name="timmy"/></form>' };
6392 PartnerType._views = {
6393 list: '<list editable="bottom"><field name="name"/></list>',
6394 };
6395 onRpc("partner", "get_formview_id", () => false);
6396 onRpc("web_save", (args) => {
6397 expect(args.args[1].timmy).toEqual([[4, 12]], {
6398 message: "should properly add id",
6399 });
6400 });
6401 await mountViewInDialog({
6402 type: "form",
6403 resModel: "partner",
6404 arch: `
6405 <form>
6406 <field name="turtles">
6407 <list editable="bottom">
6408 <field name="turtle_trululu"/>
6409 </list>
6410 </field>
6411 </form>`,
6412 resId: 1,
6413 });
6414
6415 // edit the first partner in the one2many partner form view
6416 await contains(".o_data_row td.o_data_cell").click();
6417 // open form view for many2one
6418 await contains(".o_external_button").click();
6419
6420 // click on add, to add a new partner in the m2m
6421 await contains(".modal:eq(1) .o_field_x2many_list_row_add a").click();
6422
6423 // select the PartnerType 'gold' (this closes the 3rd modal)
6424 await contains(".o_dialog:not(.o_inactive_modal) td.o_data_cell").click(); // select gold
6425
6426 // confirm the changes in the modal
6427 await contains(".modal:eq(1) .o_form_button_save").click();
6428
6429 await clickSave();
6430 });
6431
6432 test("nested x2many default values", async () => {
6433 Partner._fields.turtles = fields.One2many({
6434 string: "one2many turtle field",
6435 relation: "turtle",
6436 relation_field: "turtle_trululu",
6437 default: [
6438 [0, 0, { partner_ids: [[4, 4]] }],
6439 [0, 0, { partner_ids: [[4, 1]] }],
6440 ],
6441 });
6442
6443 await mountView({
6444 type: "form",
6445 resModel: "partner",
6446 arch: `
6447 <form>
6448 <field name="turtles">
6449 <list editable="top">
6450 <field name="partner_ids" widget="many2many_tags"/>
6451 </list>
6452 </field>
6453 </form>`,
6454 });
6455
6456 expect(".o_field_x2many_list .o_data_row").toHaveCount(2);
6457 expect('.o_field_x2many_list .o_field_many2many_tags[name="partner_ids"] .badge').toHaveCount(
6458 2
6459 );
6460 expect(
6461 queryAllTexts(
6462 '.o_field_x2many_list .o_field_many2many_tags[name="partner_ids"] .o_tag_badge_text'
6463 )
6464 ).toEqual(["aaa", "first record"]);
6465 });
6466
6467 test("nested x2many (inline form view) and _onChanges", async () => {
6468 expect.assertions(8);
6469 Partner._onChanges.bar = function (obj) {
6470 if (!obj.bar) {
6471 obj.p = [
6472 [
6473 0,
6474 0,
6475 {
6476 turtles: [
6477 [
6478 0,
6479 0,
6480 {
6481 turtle_foo: "new turtle",
6482 },
6483 ],
6484 ],
6485 },
6486 ],
6487 ];
6488 }
6489 };
6490 onRpc("onchange", (args) => {
6491 expect(args.args[3]).toEqual({
6492 bar: {},
6493 display_name: {},
6494 p: {
6495 fields: {
6496 turtles: {
6497 fields: {
6498 turtle_foo: {},
6499 },
6500 },
6501 },
6502 limit: 40,
6503 },
6504 });
6505 });
6506 await mountView({
6507 type: "form",
6508 resModel: "partner",
6509 arch: `
6510 <form>
6511 <field name="bar"/>
6512 <field name="p">
6513 <list>
6514 <field name="turtles"/>
6515 </list>
6516 <form>
6517 <field name="turtles">
6518 <list>
6519 <field name="turtle_foo"/>
6520 </list>
6521 </field>
6522 </form>
6523 </field>
6524 </form>`,
6525 });
6526 expect(".o_data_row").toHaveCount(0);
6527
6528 await contains(".o_field_widget[name=bar] input").click();
6529 expect(".o_data_row").toHaveCount(1);
6530 expect(".o_data_row").toHaveText("1 record");
6531
6532 await contains(".o_data_row td").click();
6533 expect(".modal .o_form_view").toHaveCount(1);
6534 expect(".modal .o_form_view .o_data_row").toHaveCount(1);
6535 expect(".modal .o_form_view .o_data_row").toHaveText("new turtle");
6536 });
6537
6538 test("nested x2many (non inline views and no widget on inner x2many in list)", async () => {
6539 Partner._records[0].p = [1];
6540 Partner._views = {
6541 list: `
6542 <list>
6543 <field name="turtles"/>
6544 </list>`,
6545 form: `
6546 <form>
6547 <field name="turtles" widget="many2many_tags"/>
6548 </form>`,
6549 };
6550 await mountView({
6551 type: "form",
6552 resModel: "partner",
6553 arch: '<form><field name="p"/></form>',
6554 resId: 1,
6555 });
6556
6557 expect(".o_data_row").toHaveCount(1);
6558 expect(".o_data_row").toHaveText("1 record");
6559
6560 await contains(".o_data_row td").click();
6561
6562 expect(".modal .o_form_view").toHaveCount(1);
6563 expect(".modal .o_form_view .o_field_many2many_tags .badge").toHaveCount(1);
6564 expect(".modal .o_field_many2many_tags").toHaveText("donatello");
6565 });
6566
6567 test("one2many (who contains name) with list view and without form view", async () => {
6568 Turtle._views = { form: '<form><field name="turtle_foo"/></form>' };
6569
6570 await mountView({
6571 type: "form",
6572 resModel: "partner",
6573 arch: `
6574 <form edit="0">
6575 <group>
6576 <field name="turtles">
6577 <list>
6578 <field name="name"/>
6579 </list>
6580 </field>
6581 </group>
6582 </form>`,
6583 resId: 1,
6584 });
6585
6586 await contains(".o_data_row td").click();
6587
6588 expect('.modal div[name="turtle_foo"]').toHaveText("blip");
6589 });
6590
6591 test("open a record in a one2many list (mode 'readonly') with a notebook", async () => {
6592 Turtle._views = {
6593 form: `
6594 <form>
6595 <notebook>
6596 <page string="Yop">
6597 <field name="name">
6598 </field>
6599 </page>
6600 </notebook>
6601 </form>`,
6602 };
6603
6604 await mountView({
6605 type: "form",
6606 resModel: "partner",
6607 arch: `
6608 <form>
6609 <field name="turtles">
6610 <list>
6611 <field name="turtle_foo"/>
6612 </list>
6613 </field>
6614 </form>`,
6615 resId: 1,
6616 });
6617
6618 await contains(".o_data_cell").click();
6619 expect(".modal .o_form_view").toHaveCount(1);
6620 expect(".modal .o_form_view .o_notebook_headers").toHaveCount(1);
6621 expect(".modal .o_form_view .o_notebook_headers").toHaveText("Yop");
6622 });
6623
6624 test("one2many field with virtual ids", async () => {
6625 Partner._views = { form: '<form><field name="foo"/></form>' };
6626
6627 await mountView({
6628 type: "form",
6629 resModel: "partner",
6630 arch: `
6631 <form>
6632 <sheet>
6633 <group>
6634 <notebook>
6635 <page>
6636 <field name="p" mode="kanban">
6637 <kanban>
6638 <templates>
6639 <t t-name="card">
6640 <field name="id" class="o_test_id"/>
6641 <field name="foo" class="o_test_foo"/>
6642 </t>
6643 </templates>
6644 </kanban>
6645 </field>
6646 </page>
6647 </notebook>
6648 </group>
6649 </sheet>
6650 </form>`,
6651 resId: 4,
6652 });
6653
6654 expect(".o_field_widget .o_kanban_renderer").toHaveCount(1, {
6655 message: "should have one inner kanban view for the one2many field",
6656 });
6657 expect(
6658 ".o_field_widget .o_kanban_renderer .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)"
6659 ).toHaveCount(0, { message: "should not have kanban records yet" });
6660
6661 // create a new kanban record
6662 await contains(".o_field_widget .o-kanban-button-new").click();
6663
6664 // save & close the modal
6665 expect(".modal-content .o_field_widget input").toHaveValue("My little Foo Value", {
6666 message: "should already have the default value for field foo",
6667 });
6668 await contains(".modal .o_form_button_save").click();
6669
6670 expect(".o_field_widget .o_kanban_renderer").toHaveCount(1, {
6671 message: "should have one inner kanban view for the one2many field",
6672 });
6673 expect(
6674 ".o_field_widget .o_kanban_renderer .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)"
6675 ).toHaveCount(1, { message: "should now have one kanban record" });
6676 expect(
6677 ".o_field_widget .o_kanban_renderer .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new) .o_test_id"
6678 ).toHaveText("", { message: "should not have a value for the id field" });
6679 expect(
6680 ".o_field_widget .o_kanban_renderer .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new) .o_test_foo"
6681 ).toHaveText("My little Foo Value", { message: "should have a value for the foo field" });
6682
6683 // save the view to force a create of the new record in the one2many
6684 await clickSave();
6685 expect(".o_field_widget .o_kanban_renderer").toHaveCount(1, {
6686 message: "should have one inner kanban view for the one2many field",
6687 });
6688 expect(
6689 ".o_field_widget .o_kanban_renderer .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)"
6690 ).toHaveCount(1, { message: "should now have one kanban record" });
6691 expect(
6692 ".o_field_widget .o_kanban_renderer .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new) .o_test_id"
6693 ).toHaveText("5", { message: "should now have a value for the id field" });
6694 expect(
6695 ".o_field_widget .o_kanban_renderer .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new) .o_test_foo"
6696 ).toHaveText("My little Foo Value", { message: "should still have a value for the foo field" });
6697 });
6698
6699 test("one2many field with virtual ids with kanban button", async () => {
6700 expect.assertions(23);
6701
6702 Partner._records[0].p = [4];
6703 onRpc("web_save", (args) => {
6704 expect.step(args.method);
6705 expect(args.args[1].p).toHaveLength(1);
6706 const command = args.args[1].p[0];
6707 expect(command[0]).toBe(0);
6708 expect(command[2]).toEqual({
6709 foo: "My little Foo Value",
6710 });
6711 });
6712 mockService("action", {
6713 doActionButton: (params) => {
6714 const { name, resModel, resId } = params;
6715 expect.step(`${name}_${resModel}_${resId}`);
6716 params.onClose();
6717 },
6718 });
6719 await mountView({
6720 type: "form",
6721 resModel: "partner",
6722 arch: `
6723 <form>
6724 <field name="p" mode="kanban">
6725 <kanban>
6726 <templates>
6727 <t t-name="card">
6728 <field name="foo"/>
6729 <button type="object" class="btn btn-link fa fa-shopping-cart" name="button_warn" string="button_warn" warn="warn" />
6730 <button type="object" class="btn btn-link fa fa-shopping-cart" name="button_disabled" string="button_disabled" />
6731 </t>
6732 </templates>
6733 </kanban>
6734 <form>
6735 <field name="foo"/>
6736 </form>
6737 </field>
6738 </form>`,
6739 resId: 1,
6740 });
6741
6742 // 1. Define all css selector
6743 const oKanbanView = ".o_field_widget .o_kanban_renderer";
6744 const oKanbanRecordActive =
6745 oKanbanView + " .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)";
6746 const oAllKanbanButton = oKanbanRecordActive + " button";
6747 const btn1 = oKanbanRecordActive + ":eq(0) button";
6748 const btn2 = oKanbanRecordActive + ":eq(1) button";
6749 const btn1Warn = btn1 + '[name="button_warn"]';
6750 const btn1Disabled = btn1 + '[name="button_disabled"]';
6751 const btn2Warn = btn2 + '[name="button_warn"]';
6752 const btn2Disabled = btn2 + '[name="button_disabled"]';
6753
6754 // check if we already have one kanban card
6755 expect(oKanbanView).toHaveCount(1, {
6756 message: "should have one inner kanban view for the one2many field",
6757 });
6758 expect(oKanbanRecordActive).toHaveCount(1, { message: "should have one kanban records yet" });
6759
6760 // we have 2 buttons
6761 expect(oAllKanbanButton).toHaveCount(2);
6762
6763 // disabled ?
6764 expect(oAllKanbanButton + "[disabled]").toHaveCount(0, {
6765 message: "should not have button type object disabled",
6766 });
6767
6768 // click on the button
6769 await contains(btn1Disabled).click();
6770 expect.verifySteps(["button_disabled_partner_4"]);
6771
6772 await contains(btn1Warn).click();
6773 expect.verifySteps(["button_warn_partner_4"]);
6774
6775 // click on existing buttons
6776 await contains(btn1Disabled).click();
6777 expect.verifySteps(["button_disabled_partner_4"]);
6778
6779 await contains(btn1Warn).click();
6780 expect.verifySteps(["button_warn_partner_4"]);
6781
6782 // create new kanban record
6783 await contains(".o_field_widget .o-kanban-button-new").click();
6784
6785 // save & close the modal
6786 expect(".modal-content .o_field_widget input").toHaveValue("My little Foo Value", {
6787 message: "should already have the default value for field foo",
6788 });
6789 await contains(".modal .o_form_button_save").click();
6790
6791 // check new item
6792 expect(oAllKanbanButton).toHaveCount(4);
6793 expect(btn1).toHaveCount(2);
6794 expect(btn2).toHaveCount(2);
6795 expect(oAllKanbanButton + "[disabled]").toHaveCount(0, {
6796 message: "should have 1 button type object disabled",
6797 });
6798
6799 expect(btn2Disabled).toBeEnabled();
6800 expect(btn2Warn).toBeEnabled();
6801
6802 expect(btn2Warn).toHaveAttribute("warn", "warn", {
6803 message: "Should have a button type object with warn attr in area 2",
6804 });
6805
6806 // click all buttons
6807 await contains(btn1Disabled).click();
6808 expect.verifySteps(["web_save", "button_disabled_partner_4"]);
6809 await contains(btn1Warn).click();
6810 await contains(btn2Disabled).click();
6811 await contains(btn2Warn).click();
6812 expect.verifySteps([
6813 "button_warn_partner_4",
6814 "button_disabled_partner_5",
6815 "button_warn_partner_5",
6816 ]);
6817
6818 // save the form
6819 expect(".o_form_saved").toHaveCount(1);
6820
6821 // click all buttons
6822 await contains(btn1Disabled).click();
6823 await contains(btn1Warn).click();
6824 await contains(btn2Disabled).click();
6825 await contains(btn2Warn).click();
6826
6827 // should have clicked once on every button
6828 expect.verifySteps([
6829 "button_disabled_partner_4",
6830 "button_warn_partner_4",
6831 "button_disabled_partner_5",
6832 "button_warn_partner_5",
6833 ]);
6834 });
6835
6836 test("focusing fields in one2many list", async () => {
6837 await mountView({
6838 type: "form",
6839 resModel: "partner",
6840 arch: `
6841 <form>
6842 <group>
6843 <field name="turtles">
6844 <list editable="top">
6845 <field name="turtle_foo"/>
6846 <field name="turtle_int"/>
6847 </list>
6848 </field>
6849 </group>
6850 <field name="foo"/>
6851 </form>`,
6852 resId: 1,
6853 });
6854
6855 await contains(".o_data_row td").click();
6856 expect('[name="turtle_foo"] input').toBeFocused();
6857
6858 await press("Tab");
6859 await animationFrame();
6860 expect('[name="turtle_int"] input').toBeFocused();
6861 });
6862
6863 test("one2many list editable = top", async () => {
6864 expect.assertions(5);
6865 Turtle._fields.turtle_foo = fields.Char({ default: "default foo turtle" });
6866 onRpc("web_save", (args) => {
6867 const commands = args.args[1].turtles;
6868 expect(commands).toEqual([[0, commands[0][1], { turtle_foo: "default foo turtle" }]]);
6869 });
6870 await mountView({
6871 type: "form",
6872 resModel: "partner",
6873 arch: `
6874 <form>
6875 <group>
6876 <field name="turtles">
6877 <list editable="top">
6878 <field name="turtle_foo"/>
6879 </list>
6880 </field>
6881 </group>
6882 </form>`,
6883 resId: 1,
6884 });
6885 expect(".o_data_row").toHaveCount(1);
6886
6887 await contains(".o_field_x2many_list_row_add a").click();
6888
6889 expect(".o_data_row").toHaveCount(2);
6890 expect("tr.o_data_row input").toHaveValue("default foo turtle", {
6891 message: "first row should be the new value",
6892 });
6893 expect("tr.o_data_row:eq(0)").toHaveClass("o_selected_row");
6894
6895 await clickSave();
6896 });
6897
6898 test("one2many list editable = bottom", async () => {
6899 expect.assertions(5);
6900 Turtle._fields.turtle_foo = fields.Char({ default: "default foo turtle" });
6901 onRpc("web_save", (args) => {
6902 const commands = args.args[1].turtles;
6903 expect(commands).toEqual([[0, commands[0][1], { turtle_foo: "default foo turtle" }]]);
6904 });
6905 await mountView({
6906 type: "form",
6907 resModel: "partner",
6908 arch: `
6909 <form>
6910 <group>
6911 <field name="turtles">
6912 <list editable="bottom">
6913 <field name="turtle_foo"/>
6914 </list>
6915 </field>
6916 </group>
6917 </form>`,
6918 resId: 1,
6919 });
6920
6921 expect(".o_data_row").toHaveCount(1);
6922
6923 await contains(".o_field_x2many_list_row_add a").click();
6924
6925 expect(".o_data_row").toHaveCount(2);
6926 expect("tr.o_data_row input").toHaveValue("default foo turtle", {
6927 message: "second row should be the new value",
6928 });
6929 expect("tr.o_data_row:eq(1)").toHaveClass("o_selected_row");
6930
6931 await clickSave();
6932 });
6933
6934 test("one2many list editable - should properly unselect the list field after shift+tab", async () => {
6935 await mountView({
6936 type: "form",
6937 resModel: "partner",
6938 arch: /* xml */ `
6939 <form>
6940 <group>
6941 <field name="name"/>
6942 <field name="turtles">
6943 <list editable="bottom">
6944 <field name="turtle_foo"/>
6945 <field name="turtle_bar" optional="hide"/>
6946 </list>
6947 </field>
6948 </group>
6949 </form>`,
6950 resId: 1,
6951 });
6952
6953 await contains(".o_data_row td:first-child").click();
6954 expect(".o_selected_row").toHaveCount(1);
6955 const events = await press("Shift+Tab");
6956 await animationFrame();
6957 expect(".o_selected_row").toHaveCount(0, { message: "list should not be in edition" });
6958 // We also check the event is not default prevented, to make sure that the
6959 // event flows and selection goes to the previous field.
6960 expect(events[0].defaultPrevented).toBe(false);
6961 expect(events[1].defaultPrevented).toBe(false);
6962 });
6963
6964 test("one2many list editable - should not allow tab navigation focus on the optional field toggler", async () => {
6965 await mountView({
6966 type: "form",
6967 resModel: "partner",
6968 arch: /* xml */ `
6969 <form>
6970 <group>
6971 <field name="name"/>
6972 <field name="turtles">
6973 <list editable="bottom">
6974 <field name="turtle_foo"/>
6975 <field name="turtle_bar" optional="hide"/>
6976 </list>
6977 </field>
6978 </group>
6979 </form>`,
6980 resId: 1,
6981 });
6982 expect(".o_optional_columns_dropdown .dropdown-toggle").toHaveProperty("tabIndex", -1);
6983 });
6984
6985 test('one2many list edition, no "Remove" button in modal', async () => {
6986 Partner._fields.foo = fields.Char({ default: false });
6987
6988 await mountView({
6989 type: "form",
6990 resModel: "partner",
6991 arch: `
6992 <form>
6993 <field name="p">
6994 <list>
6995 <field name="foo"/>
6996 </list>
6997 <form>
6998 <field name="name"/>
6999 </form>
7000 </field>
7001 </form>`,
7002 resId: 1,
7003 });
7004 await contains(".o_field_x2many_list_row_add a").click();
7005 expect(".modal").toHaveCount(1);
7006 expect(".modal .modal-footer .o_btn_remove").toHaveCount(0);
7007
7008 // Discard a modal
7009 await contains(".modal-footer .btn-secondary").click();
7010 });
7011
7012 test('x2many fields use their "mode" attribute', async () => {
7013 await mountView({
7014 type: "form",
7015 resModel: "partner",
7016 arch: `
7017 <form>
7018 <group>
7019 <field mode="kanban" name="turtles">
7020 <list>
7021 <field name="turtle_foo"/>
7022 </list>
7023 <kanban>
7024 <templates>
7025 <t t-name="card">
7026 <field name="turtle_int"/>
7027 </t>
7028 </templates>
7029 </kanban>
7030 </field>
7031 </group>
7032 </form>`,
7033 resId: 1,
7034 });
7035
7036 expect(".o_field_one2many .o_field_x2many_kanban").toHaveCount(1, {
7037 message: "should have rendered a kanban view",
7038 });
7039 });
7040
7041 test("one2many list editable, onchange and required field", async () => {
7042 Turtle._fields.turtle_foo = fields.Char({ required: true });
7043 let intFieldVal = 0;
7044 Partner._onChanges = {
7045 turtles: function (obj) {
7046 obj.int_field = intFieldVal;
7047 },
7048 };
7049 Partner._records[0].int_field = 0;
7050 Partner._records[0].turtles = [];
7051 onRpc((args) => {
7052 expect.step(args.method);
7053 });
7054 await mountView({
7055 type: "form",
7056 resModel: "partner",
7057 arch: `
7058 <form>
7059 <field name="int_field"/>
7060 <field name="turtles">
7061 <list editable="top">
7062 <field name="turtle_int"/>
7063 <field name="turtle_foo"/>
7064 </list>
7065 </field>
7066 </form>`,
7067 resId: 1,
7068 });
7069 expect('.o_field_widget[name="int_field"] input').toHaveValue("0");
7070
7071 intFieldVal = 1;
7072 await contains(".o_field_x2many_list_row_add a").click();
7073 expect('.o_field_widget[name="int_field"] input').toHaveValue("0");
7074 expect.verifySteps(["get_views", "web_read", "onchange"]);
7075
7076 await contains('.o_field_widget[name="turtle_foo"] input').edit("some text", {
7077 confirm: "blur",
7078 });
7079 expect.verifySteps(["onchange"]);
7080 expect('.o_field_widget[name="int_field"] input').toHaveValue("1");
7081 });
7082
7083 test.tags("desktop");
7084 test("one2many list editable: trigger onchange when row is valid", async () => {
7085 // should omit require fields that aren't in the view as they (obviously)
7086 // have no value, when checking the validity of required fields
7087 // shouldn't consider numerical fields with value 0 as unset
7088 Turtle._fields.turtle_foo = fields.Char({ required: true });
7089 Turtle._fields.turtle_bar = fields.Boolean({ required: true });
7090 Turtle._fields.turtle_int = fields.Integer({ required: true, default: 0 }); // required int field (default 0)
7091 Turtle._fields.partner_ids = fields.Many2many({ relation: "partner", required: true }); // required many2many
7092 let intFieldVal = 0;
7093 Partner._onChanges = {
7094 turtles: function (obj) {
7095 obj.int_field = intFieldVal;
7096 },
7097 };
7098 Partner._records[0].int_field = 0;
7099 Partner._records[0].turtles = [];
7100
7101 Turtle._views = {
7102 list: `
7103 <list editable="top">
7104 <field name="turtle_qux"/>
7105 <field name="turtle_bar"/>
7106 <field name="turtle_int"/>
7107 <field name="turtle_foo"/>
7108 <field name="partner_ids" widget="many2many_tags"/>
7109 </list>`,
7110 };
7111 onRpc((args) => {
7112 expect.step(args.method);
7113 });
7114 await mountView({
7115 type: "form",
7116 resModel: "partner",
7117 arch: `
7118 <form>
7119 <field name="int_field"/>
7120 <field name="turtles"/>
7121 </form>`,
7122 resId: 1,
7123 });
7124
7125 expect('.o_field_widget[name="int_field"] input').toHaveValue("0", {
7126 message: "int_field should start with value 0",
7127 });
7128
7129 intFieldVal = 1;
7130 // add a new row (which is invalid at first)
7131 await contains(".o_field_x2many_list_row_add a").click();
7132 expect('.o_field_widget[name="int_field"] input').toHaveValue("0", {
7133 message: "int_field should still be 0 (no onchange should have been done yet)",
7134 });
7135 expect.verifySteps(["get_views", "web_read", "onchange"]);
7136
7137 // fill turtle_foo field
7138 await contains('.o_field_widget[name="turtle_foo"] input').edit("some text", {
7139 confirm: false,
7140 });
7141 expect('.o_field_widget[name="int_field"] input').toHaveValue("0", {
7142 message: "int_field should still be 0 (no onchange should have been done yet)",
7143 });
7144 // no onchange should have been applied
7145 expect.verifySteps([]);
7146
7147 // fill partner_ids field with a tag (all required fields will then be set)
7148 await selectFieldDropdownItem("partner_ids", "first record");
7149
7150 expect('.o_field_widget[name="int_field"] input').toHaveValue("1", {
7151 message: "int_field should now be 1 (the onchange should have been done",
7152 });
7153 expect.verifySteps(["web_name_search", "web_read", "onchange"]);
7154 });
7155
7156 test("one2many list editable: 'required' modifiers is properly working", async () => {
7157 Partner._onChanges = {
7158 turtles: function (obj) {
7159 obj.int_field = 44;
7160 },
7161 };
7162
7163 Partner._records[0].turtles = [];
7164
7165 await mountView({
7166 type: "form",
7167 resModel: "partner",
7168 arch: `
7169 <form>
7170 <field name="int_field"/>
7171 <field name="turtles">
7172 <list editable="top">
7173 <field name="turtle_foo" required="1"/>
7174 </list>
7175 </field>
7176 </form>`,
7177 resId: 1,
7178 });
7179 expect('.o_field_widget[name="int_field"] input').toHaveValue("10");
7180
7181 await contains(".o_field_x2many_list_row_add a").click();
7182 expect('.o_field_widget[name="int_field"] input').toHaveValue("10");
7183
7184 // fill turtle_foo field
7185 await contains('.o_field_widget[name="turtle_foo"] input').edit("some text");
7186
7187 expect('.o_field_widget[name="int_field"] input').toHaveValue("44");
7188 });
7189
7190 test("one2many list editable: 'required' modifiers is properly working, part 2", async () => {
7191 Partner._onChanges = {
7192 turtles: function (obj) {
7193 obj.int_field = 44;
7194 },
7195 };
7196
7197 Partner._records[0].turtles = [];
7198
7199 await mountView({
7200 type: "form",
7201 resModel: "partner",
7202 arch: `
7203 <form>
7204 <field name="int_field"/>
7205 <field name="turtles">
7206 <list editable="top">
7207 <field name="turtle_int"/>
7208 <field name="turtle_foo" required='turtle_int == 0'/>
7209 </list>
7210 </field>
7211 </form>`,
7212 resId: 1,
7213 });
7214 expect('.o_field_widget[name="int_field"] input').toHaveValue("10");
7215
7216 await contains(".o_field_x2many_list_row_add a").click();
7217 expect('.o_field_widget[name="int_field"] input').toHaveValue("10");
7218
7219 // fill turtle_int field
7220 await contains('.o_field_widget[name="turtle_int"] input').edit("1");
7221 expect('.o_field_widget[name="int_field"] input').toHaveValue("44");
7222 });
7223
7224 test.tags("desktop");
7225 test("one2many list editable: add new line before onchange returns", async () => {
7226 // If the user adds a new row (with a required field with onchange), selects
7227 // a value for that field, then adds another row before the onchange returns,
7228 // the editable list must wait for the onchange to return before trying to
7229 // unselect the first row, otherwise it will be detected as invalid.
7230 Turtle._onChanges = {
7231 turtle_trululu: function () {},
7232 };
7233
7234 let def;
7235 onRpc("onchange", () => def);
7236 await mountView({
7237 type: "form",
7238 resModel: "partner",
7239 arch: `
7240 <form>
7241 <field name="turtles">
7242 <list editable="bottom">
7243 <field name="turtle_trululu" required="1"/>
7244 </list>
7245 </field>
7246 </form>`,
7247 });
7248
7249 // add a first line but hold the onchange back
7250 await contains(".o_field_x2many_list_row_add a").click();
7251 def = new Deferred();
7252 expect(".o_data_row").toHaveCount(1);
7253 await clickFieldDropdown("turtle_trululu");
7254 await press("Enter");
7255 await animationFrame();
7256
7257 // try to add a second line and check that it is correctly waiting
7258 // for the onchange to return
7259 await contains(".o_field_x2many_list_row_add a").click();
7260 expect(".modal").toHaveCount(0);
7261 expect(".o_field_invalid").toHaveCount(0);
7262 expect(".o_data_row").toHaveCount(1);
7263 expect(".o_data_row").toHaveClass("o_selected_row");
7264
7265 // resolve the onchange promise
7266 def.resolve();
7267 await animationFrame();
7268 expect(".o_data_row").toHaveCount(2);
7269 expect(".o_data_row:first").not.toHaveClass("o_selected_row");
7270 });
7271
7272 test("editable list: multiple clicks on Add an item do not create invalid rows", async () => {
7273 Turtle._onChanges = {
7274 turtle_trululu: function () {},
7275 };
7276
7277 let def;
7278 onRpc("onchange", () => def);
7279 await mountView({
7280 type: "form",
7281 resModel: "partner",
7282 arch: `
7283 <form>
7284 <field name="turtles">
7285 <list editable="bottom">
7286 <field name="turtle_trululu" required="1"/>
7287 </list>
7288 </field>
7289 </form>`,
7290 });
7291 def = new Deferred();
7292 // click twice to add a new line
7293 await contains(".o_field_x2many_list_row_add a").click();
7294 await contains(".o_field_x2many_list_row_add a").click();
7295 expect(".o_data_row").toHaveCount(0);
7296
7297 // resolve the onchange promise
7298 def.resolve();
7299 await animationFrame();
7300 expect(".o_data_row").toHaveCount(1);
7301 expect(".o_data_row").toHaveClass("o_selected_row");
7302 });
7303
7304 test("editable list: value reset by an onchange", async () => {
7305 // this test reproduces a subtle behavior that may occur in a form view:
7306 // the user adds a record in a one2many field, and directly clicks on a
7307 // datetime field of the form view which has an onchange, which totally
7308 // erases the value from the one2many (command 2 + command 0). The handler
7309 // that switches the edited row to readonly is then called after the
7310 // new value of the one2many field is applied (the one returned by the
7311 // onchange), so the row that must go to readonly doesn't exist anymore.
7312 Partner._onChanges = {
7313 datetime: function (obj) {
7314 if (obj.turtles.length) {
7315 obj.turtles = [
7316 [2, obj.turtles[0][1]],
7317 [0, 0, { name: "new" }],
7318 ];
7319 }
7320 },
7321 };
7322
7323 let def;
7324 onRpc("onchange", () => def);
7325 await mountView({
7326 type: "form",
7327 resModel: "partner",
7328 arch: `
7329 <form>
7330 <field name="datetime"/>
7331 <field name="turtles">
7332 <list editable="bottom">
7333 <field name="name"/>
7334 </list>
7335 </field>
7336 </form>`,
7337 });
7338
7339 // trigger the two _onChanges
7340 await contains(".o_field_x2many_list_row_add a").click();
7341 await contains(".o_data_row .o_field_widget input").edit("a name", { confirm: false });
7342 def = new Deferred();
7343 await contains(".o_field_datetime .o_input").edit("04/27/2022 14:08:52", { confirm: "blur" });
7344
7345 // resolve the onchange promise
7346 def.resolve();
7347 await animationFrame();
7348
7349 expect(".o_data_row").toHaveCount(1);
7350 expect(".o_data_row .o_data_cell").toHaveText("new");
7351 });
7352
7353 test("editable list: onchange that returns a warning", async () => {
7354 Turtle._onChanges = {
7355 name: function () {},
7356 };
7357
7358 const warning = {
7359 title: "Warning",
7360 message: "You must first select a partner",
7361 };
7362 onRpc("onchange", (args) => {
7363 expect.step(args.method);
7364 return {
7365 value: {},
7366 warning,
7367 };
7368 });
7369 mockService("notification", {
7370 add: (message, params) => {
7371 expect.step(params.type);
7372 expect(message).toBe(warning.message);
7373 expect(params.title).toBe(warning.title);
7374 },
7375 });
7376 await mountView({
7377 type: "form",
7378 resModel: "partner",
7379 arch: `
7380 <form>
7381 <field name="turtles">
7382 <list editable="bottom">
7383 <field name="name"/>
7384 </list>
7385 </field>
7386 </form>`,
7387 resId: 1,
7388 });
7389
7390 // add a line (this should trigger an onchange and a warning)
7391 await contains(".o_field_x2many_list_row_add a").click();
7392
7393 // check if 'Add an item' still works (this should trigger an onchange
7394 // and a warning again)
7395 await contains(".o_field_x2many_list_row_add a").click();
7396
7397 expect.verifySteps(["onchange", "warning", "onchange", "warning"]);
7398 });
7399
7400 test("editable list: contexts are correctly sent", async () => {
7401 expect.assertions(4);
7402
7403 Partner._records[0].timmy = [12];
7404 serverState.userContext = { someKey: "some value" };
7405 onRpc("partner", "web_read", ({ kwargs }) => {
7406 expect(kwargs.context).toEqual(
7407 {
7408 allowed_company_ids: [1],
7409 active_field: 2,
7410 bin_size: true,
7411 someKey: "some value",
7412 uid: 7,
7413 lang: "en",
7414 tz: "taht",
7415 },
7416 { message: "read partner context" }
7417 );
7418 expect(kwargs.specification.timmy.context).toEqual({ key2: "hello" });
7419 });
7420 onRpc("web_save", (args) => {
7421 expect(args.kwargs.context).toEqual(
7422 {
7423 allowed_company_ids: [1],
7424 active_field: 2,
7425 someKey: "some value",
7426 uid: 7,
7427 lang: "en",
7428 tz: "taht",
7429 },
7430 { message: "read partner context" }
7431 );
7432 expect(args.kwargs.specification.timmy.context).toEqual({ key2: "hello" });
7433 });
7434 await mountView({
7435 type: "form",
7436 resModel: "partner",
7437 arch: `
7438 <form>
7439 <field name="foo"/>
7440 <field name="timmy" context="{'key': foo, 'key2': 'hello'}">
7441 <list editable="top">
7442 <field name="name"/>
7443 </list>
7444 </field>
7445 </form>`,
7446 resId: 1,
7447 context: { active_field: 2 },
7448 });
7449 await contains(".o_data_cell").click();
7450 await contains(".o_field_widget[name=name] input").edit("abc", { confirm: false });
7451 await clickSave();
7452 });
7453
7454 test("contexts of nested x2manys are correctly sent (add line)", async () => {
7455 expect.assertions(4);
7456 Partner._fields.timmy = fields.Many2many({
7457 relation: "partner.type",
7458 string: "pokemon",
7459 default: [[4, 12]],
7460 });
7461 serverState.userContext = { someKey: "some value" };
7462 onRpc("onchange", (args) => {
7463 expect(args.kwargs.context).toEqual(
7464 {
7465 allowed_company_ids: [1],
7466 active_field: 2,
7467 someKey: "some value",
7468 uid: 7,
7469 lang: "en",
7470 tz: "taht",
7471 },
7472 { message: "onchange context" }
7473 );
7474 expect(args.args[3].timmy.context).toEqual({
7475 key: "yop",
7476 key2: "hello",
7477 });
7478 });
7479 onRpc("partner", "web_read", (args) => {
7480 expect(args.kwargs.context).toEqual(
7481 {
7482 allowed_company_ids: [1],
7483 active_field: 2,
7484 bin_size: true,
7485 someKey: "some value",
7486 uid: 7,
7487 lang: "en",
7488 tz: "taht",
7489 },
7490 { message: "read timmy context" }
7491 );
7492 expect(args.kwargs.specification.p.fields.timmy.context).toEqual({
7493 key2: "hello",
7494 });
7495 });
7496 await mountView({
7497 type: "form",
7498 resModel: "partner",
7499 arch: `
7500 <form>
7501 <field name="foo"/>
7502 <field name="p">
7503 <list editable="top">
7504 <field name="name"/>
7505 <field name="timmy" context="{'key': parent.foo, 'key2': 'hello'}" widget="many2many_tags"/>
7506 </list>
7507 </field>
7508 </form>`,
7509 resId: 1,
7510 context: { active_field: 2 },
7511 });
7512
7513 await contains(".o_field_x2many_list_row_add a").click();
7514 });
7515
7516 test("nested x2manys with context referencing parent record", async () => {
7517 expect.assertions(3);
7518
7519 Partner._records[0].p = [2];
7520
7521 let onchangeNb = 0;
7522 onRpc("onchange", (args) => {
7523 onchangeNb++;
7524 if (onchangeNb === 1) {
7525 expect(args.args[3].p.context).toEqual({ parent_foo: "yop" });
7526 } else {
7527 expect(args.kwargs.context.parent_foo).toBe("yop");
7528 }
7529 });
7530 await mountView({
7531 type: "form",
7532 resModel: "partner",
7533 arch: `
7534 <form>
7535 <field name="foo"/>
7536 <field name="p">
7537 <list>
7538 <field name="name"/>
7539 </list>
7540 <form>
7541 <field name="p" context="{'parent_foo': parent.foo}">
7542 <list>
7543 <field name="name"/>
7544 </list>
7545 </field>
7546 </form>
7547 </field>
7548 </form>`,
7549 resId: 1,
7550 });
7551
7552 await contains(".o_field_x2many_list_row_add a").click();
7553 expect(".o_dialog").toHaveCount(1);
7554 await contains(".o_dialog .o_field_x2many_list_row_add a").click();
7555 });
7556
7557 test("resetting invisible one2manys", async () => {
7558 Partner._records[0].turtles = [];
7559 Partner._onChanges.foo = function (obj) {
7560 obj.turtles = [[5], [4, 1]];
7561 };
7562 onRpc((args) => {
7563 expect.step(args.method);
7564 });
7565 await mountView({
7566 type: "form",
7567 resModel: "partner",
7568 arch: `
7569 <form>
7570 <field name="foo"/>
7571 <field name="turtles" invisible="1"/>
7572 </form>`,
7573 resId: 1,
7574 });
7575 await contains('[name="foo"] input').edit("abcd", { confirm: "blur" });
7576 expect.verifySteps(["get_views", "web_read", "onchange"]);
7577 });
7578
7579 test("one2many: onchange that returns unknown field in list, but not in form", async () => {
7580 expect.assertions(6);
7581 Partner._onChanges = {
7582 name: function (obj) {
7583 obj.p = [[0, 0, { name: "new", timmy: [[4, 12]] }]];
7584 },
7585 };
7586 onRpc("onchange", (args) => {
7587 expect(args.args[3]).toEqual({
7588 name: {},
7589 display_name: {},
7590 p: {
7591 fields: {
7592 name: {},
7593 timmy: {
7594 fields: {
7595 display_name: {},
7596 },
7597 },
7598 },
7599 limit: 40,
7600 },
7601 });
7602 });
7603 await mountView({
7604 type: "form",
7605 resModel: "partner",
7606 arch: `
7607 <form>
7608 <field name="name"/>
7609 <field name="p">
7610 <list>
7611 <field name="name"/>
7612 </list>
7613 <form>
7614 <field name="name"/>
7615 <field name="timmy" widget="many2many_tags"/>
7616 </form>
7617 </field>
7618 </form>`,
7619 });
7620
7621 expect(".o_data_row").toHaveCount(1);
7622 expect('.o_field_widget[name="timmy"]').toHaveCount(0);
7623
7624 await contains(".o_data_row td").click();
7625 expect('.modal .o_field_many2many_tags[name="timmy"]').toHaveCount(1);
7626 expect('.modal .o_field_many2many_tags[name="timmy"] .badge').toHaveCount(1);
7627 expect(queryAllTexts('.modal .o_field_many2many_tags[name="timmy"] .o_tag_badge_text')).toEqual(
7628 ["gold"]
7629 );
7630 });
7631
7632 test("multi level of nested x2manys, onchange", async () => {
7633 expect.assertions(7);
7634 Partner._records[0].p = [1];
7635 Partner._onChanges = {
7636 name: function () {},
7637 };
7638 onRpc("web_save", (args) => {
7639 expect(args.args[1].p[0][2]).toEqual({
7640 p: [[1, 1, { name: "new name" }]],
7641 });
7642 });
7643 await mountView({
7644 type: "form",
7645 resModel: "partner",
7646 arch: `
7647 <form>
7648 <field name="name"/>
7649 <field name="p" readonly="name == 'readonly'">
7650 <list><field name="name"/></list>
7651 <form>
7652 <field name="name"/>
7653 <field name="p">
7654 <list><field name="name"/></list>
7655 <form><field name="name"/></form>
7656 </field>
7657 </form>
7658 </field>
7659 </form>`,
7660 resId: 1,
7661 });
7662
7663 expect(".o_data_row").toHaveCount(1);
7664
7665 // open the dialog
7666 await contains(".o_data_row td").click();
7667 expect(".modal .o_form_editable").toHaveCount(1);
7668 expect(".modal .o_data_row").toHaveCount(1);
7669
7670 // open the o2m again, in the dialog
7671 await contains(".modal .o_data_row td").click();
7672
7673 expect(".modal .o_form_editable").toHaveCount(2);
7674
7675 // edit the name and click save modal that is on top
7676 await contains(".modal:eq(1) .o_field_widget[name=name] input").edit("new name", {
7677 confirm: false,
7678 });
7679 await contains(".modal:eq(1) .modal-footer .btn-primary").click();
7680
7681 expect(".modal .o_form_editable").toHaveCount(1);
7682
7683 // click save on the other modal
7684 await contains(".modal .modal-footer .btn-primary").click();
7685
7686 expect(".modal").toHaveCount(0);
7687
7688 // save the main record
7689 await clickSave();
7690 });
7691
7692 test("onchange and required fields with override in arch", async () => {
7693 Partner._onChanges = {
7694 turtles: function () {},
7695 };
7696 Turtle._fields.turtle_foo = fields.Char({ required: true });
7697 Partner._records[0].turtles = [];
7698 onRpc((args) => {
7699 expect.step(args.method);
7700 });
7701 await mountView({
7702 type: "form",
7703 resModel: "partner",
7704 arch: `
7705 <form>
7706 <field name="turtles">
7707 <list editable="bottom">
7708 <field name="turtle_int"/>
7709 <field name="turtle_foo" required="0"/>
7710 </list>
7711 </field>
7712 </form>`,
7713 resId: 1,
7714 });
7715 // triggers an onchange on partner, because the new record is valid
7716 await contains(".o_field_x2many_list_row_add a").click();
7717
7718 expect.verifySteps(["get_views", "web_read", "onchange", "onchange"]);
7719 });
7720
7721 test("onchange on a one2many containing a one2many", async () => {
7722 // the purpose of this test is to ensure that the onchange specs are
7723 // correctly and recursively computed
7724 expect.assertions(1);
7725
7726 Partner._onChanges = {
7727 p: function () {},
7728 };
7729 let checkOnchange = false;
7730 onRpc("onchange", (args) => {
7731 if (checkOnchange) {
7732 expect(args.args[3]).toEqual({
7733 display_name: {},
7734 p: {
7735 fields: {
7736 name: {},
7737 p: {
7738 fields: {
7739 name: {},
7740 },
7741 limit: 40,
7742 },
7743 },
7744 limit: 40,
7745 },
7746 });
7747 }
7748 });
7749 await mountView({
7750 type: "form",
7751 resModel: "partner",
7752 arch: `
7753 <form>
7754 <field name="p">
7755 <list>
7756 <field name="name"/>
7757 </list>
7758 <form>
7759 <field name="name"/>
7760 <field name="p">
7761 <list editable="bottom">
7762 <field name="name"/>
7763 </list>
7764 </field>
7765 </form>
7766 </field>
7767 </form>`,
7768 });
7769
7770 await contains(".o_field_x2many_list_row_add a").click();
7771 await contains(".modal .o_field_x2many_list_row_add a").click();
7772 await contains(".modal .o_data_cell input").edit("new record", { confirm: "blur" });
7773 checkOnchange = true;
7774 await contains(".modal .modal-footer .btn-primary").click();
7775 });
7776
7777 test("editing tabbed one2many (editable=bottom)", async () => {
7778 expect.assertions(6);
7779
7780 Partner._records[0].turtles = [];
7781 for (let i = 0; i < 42; i++) {
7782 const id = 100 + i;
7783 Turtle._records.push({ id: id, turtle_foo: "turtle" + (id - 99) });
7784 Partner._records[0].turtles.push(id);
7785 }
7786 onRpc((args) => {
7787 expect.step(args.method);
7788 });
7789 onRpc("web_save", (args) => {
7790 expect(args.args[1].turtles[0][0]).toBe(0, {
7791 message: "should send a create command",
7792 });
7793 expect(args.args[1].turtles[0][2]).toEqual({ turtle_foo: "rainbow dash" });
7794 });
7795 await mountView({
7796 type: "form",
7797 resModel: "partner",
7798 arch: `
7799 <form>
7800 <sheet>
7801 <field name="turtles">
7802 <list editable="bottom">
7803 <field name="turtle_foo"/>
7804 </list>
7805 </field>
7806 </sheet>
7807 </form>`,
7808 resId: 1,
7809 });
7810 await contains(".o_field_x2many_list_row_add a").click();
7811 expect("tr.o_data_row").toHaveCount(41);
7812 expect("tr.o_data_row:last").toHaveClass("o_selected_row");
7813
7814 await contains('.o_data_row [name="turtle_foo"] input').edit("rainbow dash", {
7815 confirm: false,
7816 });
7817 await clickSave();
7818 expect("tr.o_data_row").toHaveCount(40);
7819
7820 expect.verifySteps(["get_views", "web_read", "onchange", "web_save"]);
7821 });
7822
7823 test("editing tabbed one2many (editable=bottom), again...", async () => {
7824 Partner._records[0].turtles = [];
7825 for (let i = 0; i < 9; i++) {
7826 const id = 100 + i;
7827 Turtle._records.push({ id: id, turtle_foo: "turtle" + (id - 99) });
7828 Partner._records[0].turtles.push(id);
7829 }
7830
7831 await mountView({
7832 type: "form",
7833 resModel: "partner",
7834 arch: `
7835 <form>
7836 <field name="turtles">
7837 <list editable="bottom" limit="3">
7838 <field name="turtle_foo"/>
7839 </list>
7840 </field>
7841 </form>`,
7842 resId: 1,
7843 });
7844 // add a new record page 1 (this increases the limit to 4)
7845 await contains(".o_field_x2many_list_row_add a").click();
7846 await contains('.o_data_row [name="turtle_foo"] input').edit("rainbow dash", {
7847 confirm: false,
7848 });
7849 await contains(".o_x2m_control_panel .o_pager_next").click(); // page 2: 4 records
7850 await contains(".o_x2m_control_panel .o_pager_next").click(); // page 3: 2 records
7851 expect("tr.o_data_row").toHaveCount(2);
7852 });
7853
7854 test("editing tabbed one2many (editable=top)", async () => {
7855 expect.assertions(8);
7856
7857 Partner._records[0].turtles = [];
7858 Turtle._fields.turtle_foo = fields.Char({ default: "default foo" });
7859 for (let i = 0; i < 42; i++) {
7860 const id = 100 + i;
7861 Turtle._records.push({ id: id, turtle_foo: "turtle" + (id - 99) });
7862 Partner._records[0].turtles.push(id);
7863 }
7864 onRpc((args) => {
7865 expect.step(args.method);
7866 });
7867 onRpc("web_save", (args) => {
7868 expect(args.args[1].turtles[0][0]).toBe(0);
7869 expect(args.args[1].turtles[0][2]).toEqual({ turtle_foo: "rainbow dash" });
7870 });
7871 await mountView({
7872 type: "form",
7873 resModel: "partner",
7874 arch: `
7875 <form>
7876 <sheet>
7877 <field name="turtles">
7878 <list editable="top">
7879 <field name="turtle_foo"/>
7880 </list>
7881 </field>
7882 </sheet>
7883 </form>`,
7884 resId: 1,
7885 });
7886 await contains(".o_field_widget[name=turtles] .o_pager_next").click();
7887 expect("tr.o_data_row").toHaveCount(2);
7888
7889 await contains(".o_field_x2many_list_row_add a").click();
7890 expect("tr.o_data_row").toHaveCount(3);
7891 expect("tr.o_data_row:eq(0)").toHaveClass("o_selected_row");
7892 expect("tr.o_data_row input").toHaveValue("default foo");
7893
7894 await contains('.o_data_row [name="turtle_foo"] input').edit("rainbow dash", {
7895 confirm: false,
7896 });
7897 await clickSave();
7898 expect("tr.o_data_row").toHaveCount(40);
7899
7900 expect.verifySteps(["get_views", "web_read", "web_read", "onchange", "web_save"]);
7901 });
7902
7903 test.tags("desktop");
7904 test("one2many field: change value before pending onchange returns", async () => {
7905 Partner._onChanges = {
7906 int_field: function () {},
7907 };
7908 let def;
7909 onRpc("onchange", () => def);
7910 await mountView({
7911 type: "form",
7912 resModel: "partner",
7913 arch: `
7914 <form>
7915 <field name="p">
7916 <list editable="bottom">
7917 <field name="int_field"/>
7918 <field name="trululu"/>
7919 </list>
7920 </field>
7921 </form>`,
7922 });
7923
7924 await contains(".o_field_x2many_list_row_add a").click();
7925 def = new Deferred();
7926 await contains(".o_field_widget[name=int_field] input").edit("44", { confirm: false });
7927
7928 // set trululu before onchange
7929 await contains(".o_field_widget[name=trululu] input").edit("first", { confirm: false });
7930 await runAllTimers();
7931
7932 // complete the onchange
7933 def.resolve();
7934 expect(".o_field_many2one input").toHaveValue("first");
7935 await animationFrame();
7936 // check name_search result
7937 expect(".o_field_many2one input").toHaveValue("first");
7938 expect(".dropdown-menu li:not(.o_m2o_dropdown_option)").toHaveCount(1);
7939 });
7940
7941 test.tags("desktop");
7942 test("focus is correctly reset after an onchange in an x2many", async () => {
7943 Partner._onChanges = {
7944 int_field: function () {},
7945 };
7946
7947 let def;
7948 onRpc("onchange", () => def);
7949 await mountView({
7950 type: "form",
7951 resModel: "partner",
7952 arch: `
7953 <form>
7954 <field name="p">
7955 <list editable="bottom">
7956 <field name="int_field"/>
7957 <button string="hello"/>
7958 <field name="qux"/>
7959 <field name="trululu"/>
7960 </list>
7961 </field>
7962 </form>`,
7963 });
7964
7965 await contains(".o_field_x2many_list_row_add a").click();
7966
7967 def = new Deferred();
7968
7969 contains("[name=int_field] input").edit("44", { confirm: false });
7970
7971 await contains(".o_field_widget[name=qux]").click();
7972 expect(".o_field_widget[name=qux] input").toBeFocused();
7973
7974 def.resolve();
7975 await animationFrame();
7976 expect(".o_field_widget[name=qux] input").toBeFocused();
7977
7978 await clickFieldDropdown("trululu");
7979 await press("Enter");
7980 await animationFrame();
7981 expect(".o_field_widget[name=trululu] input").toHaveValue("first record");
7982 });
7983
7984 test("checkbox in an x2many that triggers an onchange", async () => {
7985 Partner._onChanges = {
7986 bar: function () {},
7987 };
7988
7989 await mountView({
7990 type: "form",
7991 resModel: "partner",
7992 arch: `
7993 <form>
7994 <field name="p">
7995 <list editable="bottom">
7996 <field name="bar"/>
7997 </list>
7998 </field>
7999 </form>`,
8000 });
8001
8002 await contains(".o_field_x2many_list_row_add a").click();
8003 expect(".o_field_widget[name=bar] input").toBeChecked();
8004
8005 await contains(".o_field_widget[name=bar] input").click();
8006 expect(".o_field_widget[name=bar] input").not.toBeChecked();
8007 });
8008
8009 test("one2many with default value: edit line to make it invalid", async () => {
8010 Partner._fields.p = fields.One2many({
8011 string: "one2many field",
8012 relation: "partner",
8013 relation_field: "trululu",
8014 default: [[0, false, { foo: "coucou", int_field: 5, p: [] }]],
8015 });
8016 await mountView({
8017 type: "form",
8018 resModel: "partner",
8019 arch: `
8020 <form>
8021 <field name="p">
8022 <list editable="bottom">
8023 <field name="foo"/>
8024 <field name="int_field"/>
8025 </list>
8026 </field>
8027 </form>`,
8028 });
8029
8030 // edit the line and enter an invalid value for int_field
8031 await contains(".o_data_row .o_data_cell:eq(1)").click();
8032 await contains(".o_field_widget[name=int_field] input").edit("e", { confirm: false });
8033 await contains(".o_form_view").click();
8034
8035 expect(".o_data_row.o_selected_row").toHaveCount(1, {
8036 message: "line should not have been removed and should still be in edition",
8037 });
8038 expect(".modal").toHaveCount(0, { message: "a confirmation dialog should not be opened" });
8039 expect(".o_field_widget[name=int_field]").toHaveClass("o_field_invalid");
8040 });
8041
8042 test("one2many with invalid value and click on another row", async () => {
8043 Partner._records[0].p = [2, 4];
8044
8045 await mountView({
8046 type: "form",
8047 resModel: "partner",
8048 arch: `
8049 <form>
8050 <field name="p">
8051 <list editable="bottom">
8052 <field name="name"/>
8053 <field name="int_field"/>
8054 </list>
8055 </field>
8056 </form>`,
8057 resId: 1,
8058 });
8059 await contains(".o_data_row:eq(0) .o_data_cell").click();
8060 expect(".o_data_row.o_selected_row").toHaveCount(1);
8061 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row");
8062 expect(".o_data_row:eq(1)").not.toHaveClass("o_selected_row");
8063
8064 await contains(".o_data_row [name='int_field'] input").edit("abc", { confirm: false });
8065 await contains(".o_data_row:eq(1) .o_data_cell").click();
8066 // Stays on the invalid row
8067 expect(".o_data_row.o_selected_row").toHaveCount(1);
8068 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row");
8069 expect(".o_data_row:eq(0) [name='int_field'] .o_field_invalid").toHaveCount(1);
8070 expect(".o_data_row:eq(1)").not.toHaveClass("o_selected_row");
8071 });
8072
8073 test("default value for nested one2manys (coming from onchange)", async () => {
8074 expect.assertions(3);
8075
8076 Partner._onChanges.p = function (obj) {
8077 obj.p = [
8078 [5],
8079 [0, 0, { turtles: [[5], [4, 1, false]] }], // link record 1 by default
8080 ];
8081 };
8082 onRpc("web_save", (args) => {
8083 expect(args.args[1].p[0][0]).toBe(0, {
8084 message: "should send a command 0 (CREATE) for p",
8085 });
8086 expect(args.args[1].p[0][2]).toEqual(
8087 { turtles: [[4, 1]] },
8088 { message: "should send the correct values" }
8089 );
8090 });
8091 await mountView({
8092 type: "form",
8093 resModel: "partner",
8094 arch: `
8095 <form>
8096 <sheet>
8097 <field name="p">
8098 <list>
8099 <field name="turtles"/>
8100 </list>
8101 </field>
8102 </sheet>
8103 </form>`,
8104 });
8105
8106 expect(queryAllTexts(".o_data_cell")).toEqual(["1 record"]);
8107
8108 await clickSave();
8109 });
8110
8111 test("display correct value after validation error", async () => {
8112 expect.assertions(5);
8113
8114 function validationHandler(env, error, originalError) {
8115 if (originalError.data.name === "odoo.exceptions.ValidationError") {
8116 return true;
8117 }
8118 }
8119 const errorHandlerRegistry = registry.category("error_handlers");
8120 errorHandlerRegistry.add("validationHandler", validationHandler, { sequence: 1 });
8121
8122 Partner._onChanges.turtles = function () {};
8123 onRpc("onchange", (args) => {
8124 if (args.args[1].turtles[0][2].turtle_foo === "pinky") {
8125 throw makeServerError({ type: "ValidationError" });
8126 }
8127 });
8128 onRpc("web_save", (args) => {
8129 expect(args.args[1].turtles[0]).toEqual([1, 2, { turtle_foo: "foo" }], {
8130 message: 'should send the "good" value',
8131 });
8132 });
8133 await mountView({
8134 type: "form",
8135 resModel: "partner",
8136 arch: `
8137 <form>
8138 <sheet>
8139 <field name="turtles">
8140 <list editable="bottom">
8141 <field name="turtle_foo"/>
8142 </list>
8143 </field>
8144 </sheet>
8145 </form>`,
8146 resId: 1,
8147 });
8148 expect(".o_data_row .o_data_cell").toHaveText("blip");
8149
8150 // click and edit value to 'foo', which will trigger onchange
8151 await contains(".o_data_row .o_data_cell").click();
8152 await contains(".o_field_widget[name=turtle_foo] input").edit("foo", { confirm: false });
8153 await contains(".o_form_view").click();
8154 expect(".o_data_row .o_data_cell").toHaveText("foo");
8155
8156 // click and edit value to 'pinky', which trigger a failed onchange
8157 await contains(".o_data_row .o_data_cell").click();
8158 await contains(".o_field_widget[name=turtle_foo] input").edit("pinky", { confirm: false });
8159 expect.errors(1);
8160 await contains(".o_form_view").click();
8161 expect.verifyErrors(["RPC_ERROR"]);
8162 expect(".o_data_row .o_data_cell").toHaveText("foo");
8163
8164 // we make sure here that when we save, the values are the current
8165 // values displayed in the field.
8166 await clickSave();
8167 });
8168
8169 test("propagate context to sub views without default_* keys", async () => {
8170 expect.assertions(4);
8171 onRpc("onchange", (args) => {
8172 expect(args.kwargs.context.flutter).toBe("shy", {
8173 message: "view context key should be used for every rpcs",
8174 });
8175 if (args.model === "partner") {
8176 expect(args.kwargs.context.default_flutter).toBe("why", {
8177 message: "should have default_* values in context for form view RPCs",
8178 });
8179 } else if (args.model === "turtle") {
8180 expect(args.kwargs.context.default_flutter).toBe(undefined, {
8181 message: "should not have default_* values in context for subview RPCs",
8182 });
8183 }
8184 });
8185 await mountView({
8186 type: "form",
8187 resModel: "partner",
8188 arch: `
8189 <form>
8190 <sheet>
8191 <field name="turtles">
8192 <list editable="bottom">
8193 <field name="turtle_foo"/>
8194 </list>
8195 </field>
8196 </sheet>
8197 </form>`,
8198 context: {
8199 flutter: "shy",
8200 default_flutter: "why",
8201 },
8202 });
8203 await contains(".o_field_x2many_list_row_add a").click();
8204 await contains('[name="turtle_foo"] input').edit("pinky pie", { confirm: false });
8205 await clickSave();
8206 });
8207
8208 test("nested one2manys with no widget in list and as invisible list in form", async () => {
8209 Partner._records[0].p = [1];
8210
8211 await mountView({
8212 type: "form",
8213 resModel: "partner",
8214 arch: `
8215 <form>
8216 <field name="p">
8217 <list>
8218 <field name="turtles"/>
8219 </list>
8220 <form>
8221 <field name="turtles" invisible="1"/>
8222 </form>
8223 </field>
8224 </form>`,
8225 resId: 1,
8226 });
8227 expect(".o_data_row").toHaveCount(1);
8228 expect(queryAllTexts(".o_data_row .o_data_cell")).toEqual(["1 record"]);
8229
8230 await contains(".o_data_row td").click();
8231 expect(".modal .o_form_view").toHaveCount(1);
8232 expect(".modal .o_form_view .o_field_one2many").toHaveCount(0);
8233
8234 // Test possible caching issues
8235 await contains(".modal .o_form_button_cancel").click();
8236 await contains(".o_data_row td").click();
8237 expect(".modal .o_form_view").toHaveCount(1);
8238 expect(".modal .o_form_view .o_field_one2many").toHaveCount(0);
8239 });
8240
8241 test("onchange on nested one2manys", async () => {
8242 expect.assertions(3);
8243
8244 Partner._onChanges.name = function (obj) {
8245 if (obj.name) {
8246 obj.p = [
8247 [
8248 0,
8249 0,
8250 {
8251 name: "test",
8252 turtles: [[0, 0, { name: "test nested" }]],
8253 },
8254 ],
8255 ];
8256 }
8257 };
8258 onRpc("web_save", (args) => {
8259 const commands = args.args[1].p;
8260 expect(commands).toEqual([
8261 [
8262 0,
8263 commands[0][1],
8264 {
8265 name: "test",
8266 turtles: [[0, commands[0][2].turtles[0][1], { name: "test nested" }]],
8267 },
8268 ],
8269 ]);
8270 });
8271 await mountView({
8272 type: "form",
8273 resModel: "partner",
8274 arch: `
8275 <form>
8276 <sheet>
8277 <field name="name"/>
8278 <field name="p">
8279 <list>
8280 <field name="name"/>
8281 </list>
8282 <form>
8283 <field name="turtles">
8284 <list>
8285 <field name="name"/>
8286 </list>
8287 </field>
8288 </form>
8289 </field>
8290 </sheet>
8291 </form>`,
8292 });
8293
8294 await contains(".o_field_widget[name=name] input").edit("trigger onchange", {
8295 confirm: "blur",
8296 });
8297 expect(queryAllTexts(".o_data_cell")).toEqual(["test"]);
8298
8299 // open the new subrecord to check the value of the nested o2m, and to
8300 // ensure that it will be saved
8301 await contains(".o_data_cell").click();
8302 expect(queryAllTexts(".modal .o_data_cell")).toEqual(["test nested"]);
8303
8304 await contains(".modal .modal-footer .btn-primary").click();
8305 await clickSave();
8306 });
8307
8308 test("one2many with multiple pages and sequence field", async () => {
8309 Partner._records[0].turtles = [3, 2, 1];
8310 Partner._onChanges.turtles = function () {};
8311 onRpc("onchange", () => ({
8312 value: {
8313 turtles: [
8314 [2, 2],
8315 [2, 3],
8316 [4, 1, { id: 1, turtle_int: 0, turtle_foo: "yop", partner_ids: [] }],
8317 [1, 1, { turtle_foo: "from onchange" }],
8318 ],
8319 },
8320 }));
8321 await mountView({
8322 type: "form",
8323 resModel: "partner",
8324 arch: `
8325 <form>
8326 <field name="turtles">
8327 <list limit="2">
8328 <field name="turtle_int" widget="handle"/>
8329 <field name="turtle_foo"/>
8330 <field name="partner_ids" invisible="1"/>
8331 </list>
8332 </field>
8333 </form>`,
8334 resId: 1,
8335 });
8336 await contains(".o_list_record_remove button").click();
8337 expect(queryAllTexts(".o_data_row")).toEqual(["from onchange"]);
8338 });
8339
8340 test("one2many with multiple pages and sequence field, part2", async () => {
8341 Partner._records[0].turtles = [3, 2, 1];
8342 Partner._onChanges.turtles = function () {};
8343 onRpc("onchange", () => ({
8344 value: {
8345 turtles: [
8346 [2, 2],
8347 [4, 1, { id: 1, turtle_int: 0, turtle_foo: "yop", partner_ids: [] }],
8348 [1, 1, { turtle_foo: "from onchange id2" }],
8349 [1, 3, { turtle_foo: "from onchange id3" }],
8350 ],
8351 },
8352 }));
8353 await mountView({
8354 type: "form",
8355 resModel: "partner",
8356 arch: `
8357 <form>
8358 <field name="turtles">
8359 <list limit="2">
8360 <field name="turtle_int" widget="handle"/>
8361 <field name="turtle_foo"/>
8362 <field name="partner_ids" invisible="1"/>
8363 </list>
8364 <form/>
8365 </field>
8366 </form>`,
8367 resId: 1,
8368 });
8369 expect(queryAllTexts(".o_data_row .o_data_cell.o_list_char")).toEqual(["yop", "blip"]);
8370 await contains(".o_list_record_remove button").click();
8371 expect(queryAllTexts(".o_data_row .o_data_cell.o_list_char")).toEqual([
8372 "from onchange id3",
8373 "from onchange id2",
8374 ]);
8375 });
8376
8377 test("one2many with sequence field, override default_get, bottom when inline", async () => {
8378 Partner._records[0].turtles = [3, 2, 1];
8379 Turtle._fields.turtle_int = fields.Integer({ default: 10 });
8380
8381 await mountView({
8382 type: "form",
8383 resModel: "partner",
8384 arch: `
8385 <form>
8386 <field name="turtles">
8387 <list editable="bottom">
8388 <field name="turtle_int" widget="handle"/>
8389 <field name="turtle_foo"/>
8390 </list>
8391 </field>
8392 </form>`,
8393 resId: 1,
8394 });
8395 // starting condition
8396 expect(queryAllTexts(".o_data_row")).toEqual(["blip", "yop", "kawa"]);
8397
8398 // click add a new line
8399 // save the record
8400 // check line is at the correct place
8401 const inputText = "ninja";
8402 await contains(".o_field_x2many_list_row_add a").click();
8403 await contains('[name="turtle_foo"] input').edit(inputText, { confirm: false });
8404 await clickSave();
8405
8406 expect(queryAllTexts(".o_data_row")).toEqual(["blip", "yop", "kawa", inputText]);
8407 });
8408
8409 test("one2many with sequence field, override default_get, top when inline", async () => {
8410 Partner._records[0].turtles = [3, 2, 1];
8411 Turtle._fields.turtle_int = fields.Integer({ default: 10 });
8412
8413 await mountView({
8414 type: "form",
8415 resModel: "partner",
8416 arch: `
8417 <form>
8418 <field name="turtles">
8419 <list editable="top">
8420 <field name="turtle_int" widget="handle"/>
8421 <field name="turtle_foo"/>
8422 </list>
8423 </field>
8424 </form>`,
8425 resId: 1,
8426 });
8427
8428 // starting condition
8429 expect(queryAllTexts(".o_data_row")).toEqual(["blip", "yop", "kawa"]);
8430
8431 // click add a new line
8432 // save the record
8433 // check line is at the correct place
8434 const inputText = "ninja";
8435 await contains(".o_field_x2many_list_row_add a").click();
8436 await contains('[name="turtle_foo"] input').edit(inputText, { confirm: false });
8437 await clickSave();
8438
8439 expect(queryAllTexts(".o_data_row")).toEqual([inputText, "blip", "yop", "kawa"]);
8440 });
8441
8442 test("one2many with sequence field, override default_get, bottom when popup", async () => {
8443 Partner._records[0].turtles = [3, 2, 1];
8444 Turtle._fields.turtle_int = fields.Integer({ default: 10 });
8445
8446 await mountView({
8447 type: "form",
8448 resModel: "partner",
8449 arch: `
8450 <form>
8451 <field name="turtles">
8452 <list>
8453 <field name="turtle_int" widget="handle"/>
8454 <field name="turtle_foo"/>
8455 </list>
8456 <form>
8457 <field name="turtle_int" invisible="1"/>
8458 <field name="turtle_foo"/>
8459 </form>
8460 </field>
8461 </form>`,
8462 resId: 1,
8463 });
8464
8465 // starting condition
8466 expect(queryAllTexts(".o_data_row")).toEqual(["blip", "yop", "kawa"]);
8467
8468 // click add a new line
8469 // save the record
8470 // check line is at the correct place
8471 const inputText = "ninja";
8472 await contains(".o_field_x2many_list_row_add a").click();
8473 await contains('.modal [name="turtle_foo"] input').edit(inputText, { confirm: false });
8474 await contains(".modal .o_form_button_save").click();
8475
8476 expect(queryAllTexts(".o_data_row")).toEqual(["blip", "yop", "kawa", inputText]);
8477
8478 await clickSave();
8479
8480 expect(queryAllTexts(".o_data_row")).toEqual(["blip", "yop", "kawa", inputText]);
8481 });
8482
8483 test("one2many with sequence field, override default_get, not last page", async () => {
8484 Partner._records[0].turtles = [3, 2, 1];
8485
8486 Turtle._fields.turtle_int = fields.Integer({ default: 5 });
8487
8488 await mountView({
8489 type: "form",
8490 resModel: "partner",
8491 arch: `
8492 <form>
8493 <field name="turtles">
8494 <list limit="2">
8495 <field name="turtle_int" widget="handle"/>
8496 </list>
8497 <form>
8498 <field name="turtle_int"/>
8499 </form>
8500 </field>
8501 </form>`,
8502 resId: 1,
8503 });
8504 // click add a new line
8505 // check turtle_int for new is the current max of the page
8506 await contains(".o_field_x2many_list_row_add a").click();
8507 expect('.modal [name="turtle_int"] input').toHaveValue("9");
8508 });
8509
8510 test("one2many with sequence field, override default_get, last page", async () => {
8511 Partner._records[0].turtles = [3, 2, 1];
8512 Turtle._fields.turtle_int = fields.Integer({ default: 10 });
8513
8514 await mountView({
8515 type: "form",
8516 resModel: "partner",
8517 arch: `
8518 <form>
8519 <field name="turtles">
8520 <list limit="4">
8521 <field name="turtle_int" widget="handle"/>
8522 </list>
8523 <form>
8524 <field name="turtle_int"/>
8525 </form>
8526 </field>
8527 </form>`,
8528 resId: 1,
8529 });
8530 // click add a new line
8531 // check turtle_int for new is the current max of the page +1
8532 await contains(".o_field_x2many_list_row_add a").click();
8533 expect('.modal [name="turtle_int"] input').toHaveValue("22");
8534 });
8535
8536 test("one2many with sequence field and text field", async () => {
8537 Turtle._fields.turtle_int = fields.Integer({ default: 10 });
8538 Turtle._fields.product_id = fields.Many2one({
8539 relation: "product",
8540 required: true,
8541 default: 37,
8542 });
8543 Turtle._fields.not_required_product_id = fields.Many2one({
8544 string: "Product",
8545 relation: "product",
8546 });
8547
8548 await mountView({
8549 type: "form",
8550 resModel: "partner",
8551 arch: `
8552 <form>
8553 <field name="turtles">
8554 <list editable="bottom">
8555 <field name="turtle_int" widget="handle"/>
8556 <field name="turtle_foo"/>
8557 <field name="not_required_product_id"/>
8558 <field name="turtle_description" widget="text"/>
8559 </list>
8560 </field>
8561 </form>`,
8562 });
8563
8564 // starting condition
8565 expect(".o_data_cell").toHaveCount(0);
8566
8567 const inputText1 = "relax";
8568 const inputText2 = "max";
8569 await contains(".o_field_x2many_list_row_add a").click();
8570 await contains('div[name="turtle_foo"] input').edit(inputText1, { confirm: false });
8571 await contains(".o_field_x2many_list_row_add a").click();
8572 await contains('div[name="turtle_foo"] input').edit(inputText2, { confirm: false });
8573 await contains(".o_field_x2many_list_row_add a").click();
8574
8575 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual([inputText1, inputText2, ""]);
8576
8577 expect(".ui-sortable-handle").toHaveCount(3);
8578
8579 // TODO JUM: PRHOOT the events
8580 const { drop, moveTo } = await contains("tbody tr:eq(1) .o_handle_cell").drag();
8581 await moveTo("tbody tr:eq(0)");
8582 await drop(document.body);
8583
8584 // empty line has been discarded on the drag and drop)
8585 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual([inputText2, inputText1]);
8586 });
8587
8588 test("one2many with several pages, onchange and default order", async () => {
8589 // This test reproduces a specific scenario where a one2many is displayed
8590 // over several pages, and has a default order such that a record that
8591 // would normally be on page 1 is actually on another page. Moreover,
8592 // there is an onchange on that one2many which converts all commands 4
8593 // (LINK_TO) into commands 1 (UPDATE), which is standard in the ORM.
8594 // This test ensures that the record displayed on page 2 is never fully
8595 // read.
8596
8597 Partner._records[0].turtles = [1, 2, 3];
8598 Turtle._records[0].partner_ids = [1];
8599 Partner._onChanges = {
8600 turtles: function (obj) {
8601 const res = obj.turtles.map((command) => {
8602 if (command[0] === 1) {
8603 // already an UPDATE command: do nothing
8604 return command;
8605 }
8606 // convert LINK_TO commands to UPDATE commands
8607 const id = command[1];
8608 const record = Turtle._records.find((record) => record.id === id);
8609 return [1, id, pick(record, "turtle_int", "turtle_foo", "partner_ids")];
8610 });
8611 obj.turtles = res;
8612 },
8613 };
8614 onRpc((args) => {
8615 const ids = args.method === "web_read" ? " [" + args.args[0] + "]" : "";
8616 expect.step(args.method + ids);
8617 });
8618 await mountView({
8619 type: "form",
8620 resModel: "partner",
8621 arch: `
8622 <form>
8623 <field name="turtles">
8624 <list editable="top" limit="2" default_order="turtle_foo">
8625 <field name="turtle_int"/>
8626 <field name="turtle_foo" class="foo"/>
8627 <field name="partner_ids" widget="many2many_tags"/>
8628 </list>
8629 </field>
8630 </form>`,
8631 resId: 1,
8632 });
8633
8634 expect(queryAllTexts(".o_data_cell.foo")).toEqual(["blip", "kawa"]);
8635
8636 // edit turtle_int field of first row
8637 await contains(".o_data_cell").click();
8638 await contains(".o_data_row .o_field_widget[name=turtle_int] input").edit(3, {
8639 confirm: false,
8640 });
8641 await contains(".o_form_view").click();
8642 expect(queryAllTexts(".o_data_cell.foo")).toEqual(["blip", "kawa"]);
8643
8644 expect.verifySteps([
8645 "get_views",
8646 "web_read [1]", // main record
8647 "onchange",
8648 // this test's purpose is to assert that this rpc isn't
8649 // done, but yet it is. Actually, it wasn't before because mockOnChange
8650 // returned [1] as command list, instead of [[6, false, [1]]], so basically
8651 // this value was ignored. Now that mockOnChange properly works, the value
8652 // is taken into account but the basicmodel doesn't care it concerns a
8653 // record of the second page, and does the read. I don't think we
8654 // introduced a regression here, this test was simply wrong...
8655 ]);
8656 });
8657
8658 test("one2many with several pages, onchange return command update on unknown record (readonly field)", async () => {
8659 Turtle._fields.turtle_int = fields.Integer({ readonly: true });
8660 Partner._onChanges = {
8661 foo: function (obj) {
8662 obj.turtles = [[1, 3, { turtle_int: 57, turtle_foo: "yop" }]];
8663 },
8664 };
8665 onRpc("web_save", ({ args }) => {
8666 expect(args[0]).toEqual([1]);
8667 // for unknownCommand, we should not send readonly fields
8668 expect(args[1]).toEqual({
8669 foo: "blip",
8670 turtles: [[1, 3, { turtle_foo: "yop" }]],
8671 });
8672 });
8673 await mountView({
8674 type: "form",
8675 resModel: "partner",
8676 arch: `
8677 <form>
8678 <field name="foo"/>
8679 <field name="turtles">
8680 <list editable="top" limit="1">
8681 <field name="turtle_int"/>
8682 <field name="turtle_foo"/>
8683 </list>
8684 </field>
8685 </form>`,
8686 resId: 1,
8687 });
8688
8689 await contains(".o_field_widget[name=foo] input").edit("blip", { confirm: false });
8690 await clickSave();
8691 });
8692
8693 test("new record, with one2many with more default values than limit", async () => {
8694 await mountView({
8695 type: "form",
8696 resModel: "partner",
8697 arch: `
8698 <form>
8699 <field name="turtles">
8700 <list limit="2">
8701 <field name="turtle_foo"/>
8702 </list>
8703 </field>
8704 </form>`,
8705 context: { default_turtles: [1, 2, 3] },
8706 });
8707 expect(queryAllTexts(".o_data_row")).toEqual(["yop", "blip"]);
8708
8709 await clickSave();
8710 expect(queryAllTexts(".o_data_row")).toEqual(["yop", "blip"]);
8711 });
8712
8713 test("add a new line after limit is reached should behave nicely", async () => {
8714 Partner._records[0].turtles = [1, 2, 3];
8715 Partner._onChanges = {
8716 turtles: function () {},
8717 };
8718
8719 await mountView({
8720 type: "form",
8721 resModel: "partner",
8722 arch: `
8723 <form>
8724 <field name="turtles">
8725 <list limit="3" editable="bottom">
8726 <field name="turtle_foo" required="1"/>
8727 </list>
8728 </field>
8729 </form>`,
8730 resId: 1,
8731 });
8732 await contains(".o_field_x2many_list_row_add a").click();
8733 expect(".o_data_row").toHaveCount(4);
8734
8735 await contains('div[name="turtle_foo"] .o_input').edit("a", { confirm: false });
8736 expect(".o_data_row").toHaveCount(4, {
8737 message: "should still have 4 data rows (the limit is increased to 4)",
8738 });
8739 });
8740
8741 test.tags("desktop");
8742 test("onchange in a one2many with non inline view on an existing record", async () => {
8743 Partner._fields.sequence = fields.Integer({ string: "Sequence", type: "integer" });
8744 Partner._records[0].sequence = 1;
8745 Partner._records[1].sequence = 2;
8746 Partner._onChanges = { sequence: function () {} };
8747
8748 PartnerType._fields.partner_ids = fields.One2many({
8749 string: "Partner",
8750 relation: "partner",
8751 });
8752 PartnerType._records[0].partner_ids = [1, 2];
8753 Partner._views = {
8754 list: `
8755 <list>
8756 <field name="sequence" widget="handle"/>
8757 <field name="name"/>
8758 </list>`,
8759 };
8760 onRpc((args) => {
8761 expect.step(args.method);
8762 });
8763 await mountView({
8764 type: "form",
8765 resModel: "partner.type",
8766 arch: `
8767 <form>
8768 <field name="partner_ids" widget="one2many"/>
8769 </form>`,
8770 resId: 12,
8771 });
8772 // swap 2 lines in the one2many
8773 await contains("tbody tr:eq(1) .o_handle_cell").dragAndDrop("tbody tr");
8774
8775 expect.verifySteps(["get_views", "get_views", "web_read", "onchange", "onchange"]);
8776 });
8777
8778 test.tags("desktop");
8779 test("onchange in a one2many with non inline view on a new record", async () => {
8780 Turtle._onChanges = {
8781 name: function (obj) {
8782 if (obj.name) {
8783 obj.turtle_int = 44;
8784 }
8785 },
8786 };
8787 Turtle._views = {
8788 list: `
8789 <list editable="bottom">
8790 <field name="name"/>
8791 <field name="turtle_int"/>
8792 </list>`,
8793 };
8794 onRpc((args) => {
8795 expect.step(args.method || args.route);
8796 });
8797 await mountView({
8798 type: "form",
8799 resModel: "partner",
8800 arch: `
8801 <form>
8802 <field name="turtles" widget="one2many"/>
8803 </form>`,
8804 });
8805
8806 // add a row and trigger the onchange
8807 await contains(".o_field_x2many_list_row_add a").click();
8808 await contains('.o_data_row div[name="name"] input').edit("a name", { confirm: "blur" });
8809
8810 expect(".o_field_cell[name=turtle_int]").toHaveText("44");
8811
8812 expect.verifySteps([
8813 "get_views", // load main form
8814 "get_views", // load sub list
8815 "onchange", // main record
8816 "onchange", // sub record
8817 "onchange", // edition of name of sub record
8818 ]);
8819 });
8820
8821 test.tags("desktop");
8822 test('add a line, edit it and "Save & New"', async () => {
8823 await mountView({
8824 type: "form",
8825 resModel: "partner",
8826 arch: `
8827 <form>
8828 <field name="p">
8829 <list>
8830 <field name="name" widget="char" class="do_not_remove_widget_char"/>
8831 </list>
8832 <form>
8833 <field name="name"/>
8834 </form>
8835 </field>
8836 </form>`,
8837 });
8838
8839 expect(".o_data_row").toHaveCount(0);
8840 // add a new record
8841 await contains(".o_field_x2many_list_row_add a").click();
8842 await contains(".modal .o_field_widget input").edit("new record", { confirm: false });
8843
8844 await contains(".modal .o_form_button_save").click();
8845
8846 expect(queryAllTexts(".o_data_row .o_data_cell")).toEqual(["new record"]);
8847
8848 // reopen freshly added record and edit it
8849 await contains(".o_data_row .o_data_cell").click();
8850 await contains(".modal .o_field_widget input").edit("new record edited", { confirm: false });
8851
8852 // save it, and choose to directly create another record
8853 await contains(".modal .modal-footer .btn-primary:eq(1)").click();
8854
8855 expect(".modal").toHaveCount(1);
8856 expect(".modal .o_field_widget").toHaveText("");
8857
8858 await contains(".modal .o_field_widget input").edit("another new record", { confirm: false });
8859 await contains(".modal .o_form_button_save").click();
8860
8861 expect(queryAllTexts(".o_data_row .o_data_cell")).toEqual([
8862 "new record edited",
8863 "another new record",
8864 ]);
8865 });
8866
8867 test.tags("desktop");
8868 test('add a line with a context depending on the parent record, created a second record with "Save & New"', async () => {
8869 await mountView({
8870 type: "form",
8871 resModel: "partner",
8872 arch: `
8873 <form>
8874 <field name="name"/>
8875 <field name="p" context="{'default_name': name}" >
8876 <list>
8877 <field name="name"/>
8878 </list>
8879 <form>
8880 <field name="name"/>
8881 </form>
8882 </field>
8883 </form>`,
8884 });
8885
8886 expect(".o_data_row").toHaveCount(0);
8887 expect(queryAllTexts("[name='p'] .o_data_row")).toEqual([]);
8888 await contains("[name='name'] input").edit("Jack", { confirm: "blur" });
8889
8890 await contains(".o_field_x2many_list_row_add a").click();
8891 expect(".modal [name='name'] input").toHaveValue("Jack");
8892
8893 await contains(".modal .o_form_button_save_new").click();
8894 expect(".modal [name='name'] input").toHaveValue("Jack");
8895 expect(queryAllTexts("[name='p'] .o_data_row")).toEqual(["Jack"]);
8896
8897 await contains(".modal .o_form_button_save").click();
8898 expect(queryAllTexts("[name='p'] .o_data_row")).toEqual(["Jack", "Jack"]);
8899 });
8900
8901 test("o2m add a line custom control create editable", async () => {
8902 await mountView({
8903 type: "form",
8904 resModel: "partner",
8905 arch: `
8906 <form>
8907 <field name="p">
8908 <list editable="bottom">
8909 <control>
8910 <create string="Add food" context="" />
8911 <create string="Add pizza" context="{'default_name': 'pizza'}"/>
8912 </control>
8913 <control>
8914 <create string="Add pasta" context="{'default_name': 'pasta'}"/>
8915 </control>
8916 <field name="name"/>
8917 </list>
8918 <form>
8919 <field name="name"/>
8920 </form>
8921 </field>
8922 </form>`,
8923 });
8924
8925 // new controls correctly added
8926 expect(".o_field_x2many_list_row_add").toHaveCount(1);
8927 expect(queryAllTexts(".o_field_x2many_list_row_add a")).toEqual([
8928 "Add food",
8929 "Add pizza",
8930 "Add pasta",
8931 ]);
8932
8933 // click add food
8934 // check it's empty
8935 await contains(".o_field_x2many_list_row_add a").click();
8936 expect(queryAllTexts(".o_data_cell")).toEqual([""]);
8937
8938 // click add pizza
8939 // press enter to save the record
8940 // check it's pizza
8941 await contains(".o_field_x2many_list_row_add a:eq(1)").click();
8942
8943 expect(
8944 '.o_field_widget[name="p"] .o_selected_row .o_field_widget[name="name"] input'
8945 ).toBeFocused();
8946
8947 await press("Enter");
8948 await animationFrame();
8949 expect(queryAllTexts(".o_data_cell")).toEqual(["", "pizza", ""]);
8950
8951 // click add pasta
8952 await contains(".o_field_x2many_list_row_add a:eq(2)").click();
8953 await clickSave();
8954 expect(queryAllTexts(".o_data_cell")).toEqual(["", "pizza", "", "pasta"]);
8955 });
8956
8957 test("o2m add a line custom control create non-editable", async () => {
8958 await mountView({
8959 type: "form",
8960 resModel: "partner",
8961 arch: `
8962 <form>
8963 <field name="p">
8964 <list>
8965 <control>
8966 <create string="Add food" context="" />
8967 <create string="Add pizza" context="{'default_name': 'pizza'}" />
8968 </control>
8969 <control>
8970 <create string="Add pasta" context="{'default_name': 'pasta'}" />
8971 </control>
8972 <field name="name"/>
8973 </list>
8974 <form>
8975 <field name="name"/>
8976 </form>
8977 </field>
8978 </form>`,
8979 });
8980
8981 // new controls correctly added
8982 expect(".o_field_x2many_list_row_add").toHaveCount(1);
8983 expect(queryAllTexts(".o_field_x2many_list_row_add a")).toEqual([
8984 "Add food",
8985 "Add pizza",
8986 "Add pasta",
8987 ]);
8988
8989 // click add food
8990 // check it's empty
8991 await contains(".o_field_x2many_list_row_add a").click();
8992 await contains(".modal .o_form_button_save").click();
8993 expect(queryAllTexts(".o_data_cell")).toEqual([""]);
8994
8995 // click add pizza
8996 // save the modal
8997 // check it's pizza
8998 await contains(".o_field_x2many_list_row_add a:eq(1)").click();
8999 await contains(".modal .o_form_button_save").click();
9000 expect(queryAllTexts(".o_data_cell")).toEqual(["", "pizza"]);
9001
9002 // click add pasta
9003 // save the whole record
9004 // check it's pizzapasta
9005 await contains(".o_field_x2many_list_row_add a:eq(2)").click();
9006 await contains(".modal .o_form_button_save").click();
9007 expect(queryAllTexts(".o_data_cell")).toEqual(["", "pizza", "pasta"]);
9008 });
9009
9010 test("o2m add an action button control", async () => {
9011 onRpc("do_something", (args) => {
9012 expect.step("do_something");
9013 expect(args.kwargs.context.parent_id).toBe(2);
9014 return true;
9015 });
9016 await mountView({
9017 type: "form",
9018 resModel: "partner",
9019 resId: 2,
9020 arch: `
9021 <form>
9022 <field name="p">
9023 <list>
9024 <control>
9025 <create string="Create" context="{}" />
9026 <button string="Action Button" name="do_something" class="btn-link" type="object" context="{'parent_id': parent.id}"/>
9027 </control>
9028 <field name="name"/>
9029 </list>
9030 </field>
9031 </form>`,
9032 });
9033
9034 expect(".o_field_x2many_list_row_add").toHaveText("CreateAction Button");
9035
9036 await contains(".o_field_x2many_list_row_add button").click();
9037 expect.verifySteps(["do_something"]);
9038 });
9039
9040 test("one2many list with custom control with invisible modifier", async () => {
9041 await mountView({
9042 type: "form",
9043 resModel: "partner",
9044 resId: 2,
9045 arch: `
9046 <form>
9047 <field name="bar"/>
9048 <field name="p">
9049 <list>
9050 <control>
9051 <create string="A" invisible="parent.bar"/>
9052 <create string="B" invisible="not parent.bar"/>
9053 <button string="C" name="do_something" type="object" invisible="parent.bar"/>
9054 <button string="D" name="do_something" type="object" invisible="not parent.bar"/>
9055 </control>
9056 <field name="name"/>
9057 </list>
9058 </field>
9059 </form>`,
9060 });
9061
9062 expect(".o_field_x2many_list_row_add a:contains(A)").toHaveCount(0);
9063 expect(".o_field_x2many_list_row_add a:contains(B)").toHaveCount(1);
9064 expect(".o_field_x2many_list_row_add button:contains(C)").toHaveCount(0);
9065 expect(".o_field_x2many_list_row_add button:contains(D)").toHaveCount(1);
9066 });
9067
9068 test("one2many list with custom control with invisible modifier using context", async () => {
9069 await mountView({
9070 type: "form",
9071 resModel: "partner",
9072 resId: 2,
9073 arch: `
9074 <form>
9075 <field name="bar"/>
9076 <field name="p">
9077 <list>
9078 <control>
9079 <create string="A" invisible="context.get('someKey')"/>
9080 <create string="B" invisible="not context.get('someKey')"/>
9081 <button string="C" name="do_something" type="object" invisible="context.get('someKey')"/>
9082 <button string="D" name="do_something" type="object" invisible="not context.get('someKey')"/>
9083 </control>
9084 <field name="name"/>
9085 </list>
9086 </field>
9087 </form>`,
9088 context: { someKey: true },
9089 });
9090
9091 expect(".o_field_x2many_list_row_add a:contains(A)").toHaveCount(0);
9092 expect(".o_field_x2many_list_row_add a:contains(B)").toHaveCount(1);
9093 expect(".o_field_x2many_list_row_add button:contains(C)").toHaveCount(0);
9094 expect(".o_field_x2many_list_row_add button:contains(D)").toHaveCount(1);
9095 });
9096
9097 test("one2many kanban with custom control with invisible modifier", async () => {
9098 await mountView({
9099 type: "form",
9100 resModel: "partner",
9101 resId: 2,
9102 arch: `
9103 <form>
9104 <field name="bar"/>
9105 <field name="p">
9106 <kanban>
9107 <control>
9108 <create string="A" invisible="parent.bar"/>
9109 <create string="B" invisible="not parent.bar"/>
9110 <button string="C" name="do_something" type="object" invisible="parent.bar"/>
9111 <button string="D" name="do_something" type="object" invisible="not parent.bar"/>
9112 </control>
9113 <templates>
9114 <t t-name="card">
9115 <field name="name"/>
9116 </t>
9117 </templates>
9118 </kanban>
9119 </field>
9120 </form>`,
9121 });
9122
9123 expect(".o_cp_buttons button:contains(A)").toHaveCount(0);
9124 expect(".o_cp_buttons button:contains(B)").toHaveCount(1);
9125 expect(".o_cp_buttons button:contains(C)").toHaveCount(0);
9126 expect(".o_cp_buttons button:contains(D)").toHaveCount(1);
9127 });
9128
9129 test("one2many kanban with custom control with invisible modifier using context", async () => {
9130 await mountView({
9131 type: "form",
9132 resModel: "partner",
9133 resId: 2,
9134 arch: `
9135 <form>
9136 <field name="bar"/>
9137 <field name="p">
9138 <kanban>
9139 <control>
9140 <create string="A" invisible="context.get('someKey')"/>
9141 <create string="B" invisible="not context.get('someKey')"/>
9142 <button string="C" name="do_something" type="object" invisible="context.get('someKey')"/>
9143 <button string="D" name="do_something" type="object" invisible="not context.get('someKey')"/>
9144 </control>
9145 <templates>
9146 <t t-name="card">
9147 <field name="name"/>
9148 </t>
9149 </templates>
9150 </kanban>
9151 </field>
9152 </form>`,
9153 context: { someKey: true },
9154 });
9155
9156 expect(".o_cp_buttons button:contains(A)").toHaveCount(0);
9157 expect(".o_cp_buttons button:contains(B)").toHaveCount(1);
9158 expect(".o_cp_buttons button:contains(C)").toHaveCount(0);
9159 expect(".o_cp_buttons button:contains(D)").toHaveCount(1);
9160 });
9161
9162 test("one2many list with delete control with invisible modifier", async () => {
9163 Partner._records[1].p = [1, 2];
9164 Partner._records[0].bar = false;
9165 await mountView({
9166 type: "form",
9167 resModel: "partner",
9168 resId: 2,
9169 arch: `
9170 <form>
9171 <field name="bar"/>
9172 <field class="first" name="p">
9173 <list>
9174 <control>
9175 <delete invisible="parent.bar and bar"/>
9176 </control>
9177 <field name="name"/>
9178 <field name="bar"/>
9179 </list>
9180 </field>
9181 <field class="second" name="p">
9182 <list>
9183 <control>
9184 <delete invisible="not parent.bar"/>
9185 </control>
9186 <field name="name"/>
9187 <field name="bar"/>
9188 </list>
9189 </field>
9190 </form>`,
9191 });
9192
9193 expect(".first .o_data_row").toHaveCount(2);
9194 expect(".first .o_data_row:eq(0) .o_list_record_remove button").toHaveCount(1);
9195 expect(".first .o_data_row:eq(1) .o_list_record_remove button").toHaveCount(0);
9196 await contains(".first .o_data_row:eq(1) td.o_list_record_remove").click();
9197 expect(".first .o_data_row").toHaveCount(2);
9198
9199 expect(".second .o_data_row").toHaveCount(2);
9200 expect(".second .o_data_row .o_list_record_remove button").toHaveCount(2);
9201 });
9202
9203 test("one2many kanban with delete control with invisible modifier", async () => {
9204 Partner._records[1].p = [1, 2];
9205 Partner._records[0].bar = false;
9206 await mountView({
9207 type: "form",
9208 resModel: "partner",
9209 resId: 2,
9210 arch: `
9211 <form>
9212 <field name="bar"/>
9213 <field name="p">
9214 <kanban>
9215 <control>
9216 <delete invisible="parent.bar and bar"/>
9217 </control>
9218 <templates>
9219 <t t-name="card">
9220 <field name="name"/>
9221 <field name="bar"/>
9222 </t>
9223 </templates>
9224 </kanban>
9225 </field>
9226 </form>`,
9227 });
9228
9229 await contains(".o_kanban_record:eq(0)").click();
9230 expect(".o_dialog .o_form_view").toHaveCount(1);
9231 expect(".o_dialog footer .o_btn_remove").toHaveCount(1);
9232
9233 await contains(".o_dialog footer .o_form_button_cancel").click();
9234 await contains(".o_kanban_record:eq(1)").click();
9235 expect(".o_dialog .o_form_view").toHaveCount(1);
9236 expect(".o_dialog footer .o_btn_remove").toHaveCount(0);
9237
9238 await contains(".o_dialog .o_form_view .o_field_widget[name=bar] input").click();
9239 expect(".o_dialog footer .o_btn_remove").toHaveCount(1);
9240 });
9241
9242 test("o2m button with parent in context", async () => {
9243 onRpc("test_button", (args) => {
9244 expect.step("test_button");
9245 expect(args.kwargs.context.parent_name).toBe("first record");
9246 return true;
9247 });
9248 await mountView({
9249 type: "form",
9250 resModel: "partner",
9251 resId: 1,
9252 arch: `
9253 <form>
9254 <field name="turtles">
9255 <list>
9256 <field name="display_name"/>
9257 <button string="Action Button" name="test_button" type="object" context="{'parent_name': parent.display_name}"/>
9258 </list>
9259 </field>
9260 </form>`,
9261 });
9262 await contains('button[name="test_button"]').click();
9263 expect.verifySteps(["test_button"]);
9264 });
9265
9266 test("o2m add a line custom control create align with handle", async () => {
9267 await mountView({
9268 type: "form",
9269 resModel: "partner",
9270 arch: `
9271 <form>
9272 <field name="p">
9273 <list>
9274 <field name="int_field" widget="handle"/>
9275 </list>
9276 </field>
9277 </form>`,
9278 });
9279
9280 // controls correctly added, at one column offset when handle is present
9281 expect(".o_list_table tr:eq(1) td").toHaveCount(2);
9282 expect(".o_list_table tr:eq(1) td:eq(0)").toHaveText("");
9283 expect(".o_list_table tr:eq(1) td:eq(1)").toHaveText("Add a line");
9284 });
9285
9286 test.tags("desktop");
9287 test("one2many form view with action button", async () => {
9288 // once the action button is clicked, the record is reloaded (via the
9289 // onClose handler, executed because the python method does not return
9290 // any action, or an ir.action.act_window_close) ; this test ensures that
9291 // it reloads the fields of the opened view (i.e. the form in this case).
9292 // See https://github.com/odoo/odoo/issues/24189
9293 mockService("action", {
9294 doActionButton(params) {
9295 for (const record of MockServer.env["partner"].browse(params.resIds)) {
9296 record.name = "new name";
9297 record.timmy = [12];
9298 }
9299 params.onClose();
9300 },
9301 });
9302
9303 Partner._records[0].p = [2];
9304 PartnerType._views = {
9305 list: `
9306 <list>
9307 <field name="name"/>
9308 </list>`,
9309 };
9310
9311 await mountView({
9312 type: "form",
9313 resModel: "partner",
9314 resId: 1,
9315 arch: `
9316 <form>
9317 <field name="p">
9318 <list>
9319 <field name="name"/>
9320 </list>
9321 <form>
9322 <button type="action" string="Set Timmy"/>
9323 <field name="timmy"/>
9324 </form>
9325 </field>
9326 </form>`,
9327 });
9328 expect(".o_data_row").toHaveCount(1);
9329 expect(".o_data_cell").toHaveText("second record");
9330
9331 // open one2many record in form view
9332 await contains(".o_data_cell").click();
9333 expect(".modal .o_form_view").toHaveCount(1);
9334 expect(".modal .o_form_view .o_data_row").toHaveCount(0);
9335
9336 // click on the action button
9337 await contains(".modal .o_form_editable button").click();
9338 expect(".modal .o_data_row").toHaveCount(1);
9339 expect(".modal .o_data_cell").toHaveText("gold");
9340
9341 // save the dialog
9342 await contains(".modal .modal-footer .btn-primary").click();
9343
9344 expect(".o_data_cell").toHaveText("new name");
9345 });
9346
9347 test.tags("desktop");
9348 test("onchange affecting inline unopened list view", async () => {
9349 let numUserOnchange = 0;
9350 Users._onChanges = {
9351 partner_ids: function (obj) {
9352 numUserOnchange++;
9353 },
9354 };
9355
9356 await mountView({
9357 type: "form",
9358 resModel: "res.users",
9359 arch: `
9360 <form>
9361 <sheet>
9362 <group>
9363 <field name="partner_ids">
9364 <form>
9365 <field name="turtles">
9366 <list editable="bottom">
9367 <field name="name"/>
9368 </list>
9369 </field>
9370 </form>
9371 <list>
9372 <field name="name"/>
9373 </list>
9374 </field>
9375 </group>
9376 </sheet>
9377 </form>`,
9378 resId: 17,
9379 });
9380
9381 // add a turtle on second partner
9382 await contains(".o_data_row:eq(1) .o_data_cell").click();
9383 await contains(".modal .o_field_x2many_list_row_add a").click();
9384 await contains(".modal .o_field_widget[name=name] input").edit("michelangelo", {
9385 confirm: false,
9386 });
9387 await contains(".modal .btn-primary").click();
9388 // open first partner so changes from previous action are applied
9389 await contains(".o_data_row .o_data_cell").click();
9390 await contains(".modal .btn-primary").click();
9391 await clickSave();
9392
9393 expect(numUserOnchange).toBe(1, {
9394 message: "there should 1 and only 1 onchange from closing the partner modal",
9395 });
9396
9397 await contains(".o_data_row .o_data_cell").click();
9398 expect(".modal .o_data_row").toHaveCount(1, { message: "only 1 turtle for first partner" });
9399 expect(".modal .o_data_cell").toHaveText("donatello");
9400 await contains(".modal .modal-footer .btn-primary").click(); // Close
9401
9402 await contains(".o_data_row:eq(1) .o_data_cell").click();
9403 expect(".modal .o_data_row").toHaveCount(1, { message: "only 1 turtle for second partner" });
9404 expect(".modal .o_data_cell").toHaveText("michelangelo");
9405 await contains(".modal .o_form_button_cancel").click();
9406 });
9407
9408 test("click on URL should not open the record", async () => {
9409 Partner._records[0].turtles = [1];
9410
9411 // avoid to open a new tab or the mail app
9412 const onClick = (ev) => {
9413 expect.step("link clicked");
9414 ev.preventDefault();
9415 };
9416 browser.addEventListener("click", onClick, { capture: true });
9417
9418 await mountView({
9419 type: "form",
9420 resModel: "partner",
9421 arch: `
9422 <form>
9423 <field name="turtles">
9424 <list>
9425 <field name="name" widget="email"/>
9426 <field name="turtle_foo" widget="url"/>
9427 </list>
9428 <form/>
9429 </field>
9430 </form>`,
9431 resId: 1,
9432 });
9433
9434 await contains(".o_email_cell a").click();
9435 expect(".modal").toHaveCount(0);
9436 expect.verifySteps(["link clicked"]);
9437
9438 await contains(".o_url_cell a").click();
9439 expect(".modal").toHaveCount(0);
9440 expect.verifySteps(["link clicked"]);
9441 });
9442
9443 test.tags("desktop");
9444 test("create and edit on m2o in o2m, and press ESCAPE", async () => {
9445 Partner._views = {
9446 form: `
9447 <form>
9448 <field name="name"/>
9449 </form>`,
9450 };
9451
9452 await mountView({
9453 type: "form",
9454 resModel: "partner",
9455 arch: `
9456 <form>
9457 <field name="turtles">
9458 <list editable="top">
9459 <field name="turtle_trululu"/>
9460 </list>
9461 </field>
9462 </form>`,
9463 });
9464
9465 await contains(".o_field_x2many_list_row_add a").click();
9466
9467 expect(".o_selected_row").toHaveCount(1);
9468
9469 await clickFieldDropdown("turtle_trululu");
9470 await contains("[name=turtle_trululu] input").edit("ABC", { confirm: false });
9471 await runAllTimers();
9472 await clickFieldDropdownItem("turtle_trululu", "Create and edit...");
9473
9474 expect(".modal .o_form_view").toHaveCount(1);
9475
9476 await press("Escape");
9477 await animationFrame();
9478
9479 expect(".modal .o_form_view").toHaveCount(0);
9480 expect(".o_selected_row").toHaveCount(1);
9481 expect(".o_selected_row [name=turtle_trululu] input").toBeFocused();
9482 });
9483
9484 test.tags("desktop");
9485 test("one2many add a line should not crash if orderedResIDs is not set on desktop", async () => {
9486 mockService("action", {
9487 doActionButton(args) {
9488 return Promise.reject();
9489 },
9490 });
9491
9492 Partner._records[0].turtles = [];
9493
9494 await mountView({
9495 type: "form",
9496 resModel: "partner",
9497 arch: `
9498 <form>
9499 <header>
9500 <button name="post" type="object" string="Validate" class="oe_highlight"/>
9501 </header>
9502 <field name="turtles">
9503 <list editable="bottom">
9504 <field name="turtle_foo"/>
9505 </list>
9506 </field>
9507 </form>`,
9508 });
9509
9510 await contains('button[name="post"]').click();
9511 await contains(".o_field_x2many_list_row_add a").click();
9512 expect(".o_data_row.o_selected_row").toHaveCount(1);
9513 });
9514
9515 test.tags("mobile");
9516 test("one2many add a line should not crash if orderedResIDs is not set on mobile", async () => {
9517 mockService("action", {
9518 doActionButton(args) {
9519 return Promise.reject();
9520 },
9521 });
9522
9523 Partner._records[0].turtles = [];
9524
9525 await mountView({
9526 type: "form",
9527 resModel: "partner",
9528 arch: `
9529 <form>
9530 <header>
9531 <button name="post" type="object" string="Validate" class="oe_highlight"/>
9532 </header>
9533 <field name="turtles">
9534 <list editable="bottom">
9535 <field name="turtle_foo"/>
9536 </list>
9537 </field>
9538 </form>`,
9539 });
9540
9541 await contains(`.o_cp_action_menus button:has(.fa-cog)`).click();
9542 await contains('button[name="post"]').click();
9543 await contains(".o_field_x2many_list_row_add a").click();
9544 expect(".o_data_row.o_selected_row").toHaveCount(1);
9545 });
9546
9547 test("one2many shortcut tab should not crash when there is no input widget", async () => {
9548 // create a one2many view which has no input (only 1 textarea in this case)
9549 await mountView({
9550 type: "form",
9551 resModel: "partner",
9552 arch: `
9553 <form>
9554 <field name="turtles">
9555 <list editable="bottom">
9556 <field name="turtle_foo" widget="text"/>
9557 </list>
9558 </field>
9559 </form>`,
9560 resId: 1,
9561 });
9562
9563 // add a row, fill it, then trigger the tab shortcut
9564 await contains(".o_field_x2many_list_row_add a").click();
9565 // This is not how it should happen but non trusted event listeners are called sooner than
9566 // trusted ones so the update is called after the list's tab listener in which case the field is
9567 // not dirty when we press tab, therefore we need to set it dirty through onChange before pressing tab
9568 // so in practice we could only run the following line but it wont work since the tab keydown event is not trusted
9569 // await contains("[name=turtle_foo] textarea").edit("ninja", { confirm: false });
9570 await contains("[name=turtle_foo] textarea").edit("ninja", { confirm: "blur" });
9571 await contains("[name=turtle_foo]:eq(2)").click();
9572
9573 expect("[name=turtle_foo] textarea").toBeFocused();
9574 await press("tab");
9575 await animationFrame();
9576
9577 expect(queryAllTexts(".o_field_text")).toEqual(["blip", "ninja", ""]);
9578 expect(".o_field_text textarea").toHaveCount(1);
9579 });
9580
9581 test("o2m add a line custom control create editable with 'tab'", async () => {
9582 onRpc("onchange", ({ kwargs }) => {
9583 expect.step("onchange");
9584 expect(kwargs.context.default_turtle_foo).toBe("soft");
9585 });
9586 await mountView({
9587 type: "form",
9588 resModel: "partner",
9589 arch: `
9590 <form>
9591 <group>
9592 <field name="turtles">
9593 <list editable="bottom">
9594 <control>
9595 <create string="Add soft shell turtle" context="{'default_turtle_foo': 'soft'}"/>
9596 </control>
9597 <field name="turtle_foo"/>
9598 </list>
9599 </field>
9600 </group>
9601 </form>`,
9602 resId: 1,
9603 });
9604 await contains(".o_data_row .o_data_cell").click();
9605 // This is not how it should happen but non trusted event listeners are called sooner than
9606 // trusted ones so the update is called after the list's tab listener in which case the field is
9607 // not dirty when we press tab, therefore we need to set it dirty through onChange before pressing tab
9608 // so in practice we could only run the following line but it wont work since the tab keydown event is not trusted
9609 // await contains("[name=turtle_foo] textarea").edit("Test", { confirm: false });
9610 await contains("[name=turtle_foo] input").edit("Test", { confirm: "blur" });
9611 await contains("[name=turtle_foo]").click();
9612 expect(".o_data_row").toHaveCount(1);
9613
9614 await press("Tab");
9615 await animationFrame();
9616 expect(".o_data_row").toHaveCount(2);
9617 expect.verifySteps(["onchange"]);
9618 });
9619
9620 test("one2many with onchange, required field, shortcut enter", async () => {
9621 Turtle._onChanges = {
9622 turtle_foo: function () {},
9623 };
9624
9625 let def;
9626 onRpc("onchange", () => def);
9627 onRpc((args) => {
9628 expect.step(args.method);
9629 });
9630 await mountView({
9631 type: "form",
9632 resModel: "partner",
9633 arch: `
9634 <form>
9635 <field name="turtles">
9636 <list editable="bottom">
9637 <field name="turtle_foo" required="1"/>
9638 </list>
9639 </field>
9640 </form>`,
9641 });
9642
9643 expect.verifySteps(["get_views", "onchange"]);
9644
9645 // add a new line
9646 await contains(".o_field_x2many_list_row_add a").click();
9647
9648 expect.verifySteps(["onchange"]);
9649
9650 // we want to add a delay to simulate an onchange
9651 def = new Deferred();
9652
9653 // write something in the field, edit will confirm with enter
9654 await contains("[name=turtle_foo] input").edit("hello");
9655
9656 // check that nothing changed before the onchange finished
9657 expect("[name=turtle_foo] input").toHaveValue("hello");
9658 expect(".o_data_row").toHaveCount(1);
9659
9660 expect.verifySteps(["onchange"]);
9661
9662 // unlock onchange
9663 def.resolve();
9664 await animationFrame();
9665
9666 // check the current line is added with the correct content and a new line is editable
9667 expect(".o_data_row").toHaveCount(2);
9668 expect(".o_data_row:eq(0) [name=turtle_foo]").toHaveText("hello");
9669 expect(".o_data_row:eq(1) [name=turtle_foo] input").toHaveValue("");
9670
9671 expect.verifySteps(["onchange"]);
9672 });
9673
9674 test("edit a field with a slow onchange in one2many", async () => {
9675 Turtle._onChanges = {
9676 turtle_foo: function () {},
9677 };
9678
9679 let def;
9680 onRpc("onchange", () => def);
9681 onRpc((args) => {
9682 expect.step(args.method);
9683 });
9684 await mountView({
9685 type: "form",
9686 resModel: "partner",
9687 arch: `
9688 <form>
9689 <field name="turtles">
9690 <list editable="bottom">
9691 <field name="turtle_foo"/>
9692 </list>
9693 </field>
9694 </form>`,
9695 });
9696
9697 expect.verifySteps(["get_views", "onchange"]);
9698
9699 // add a new line
9700 await contains(".o_field_x2many_list_row_add a").click();
9701
9702 expect.verifySteps(["onchange"]);
9703
9704 // we want to add a delay to simulate an onchange
9705 def = new Deferred();
9706
9707 // write something in the field
9708 await contains("[name=turtle_foo] input").edit("hello", { confirm: false });
9709 expect("[name=turtle_foo] input").toHaveValue("hello");
9710
9711 await contains(".o_form_view").click();
9712
9713 // check that nothing changed before the onchange finished
9714 expect("[name=turtle_foo] input").toHaveValue("hello");
9715
9716 expect.verifySteps(["onchange"]);
9717
9718 // unlock onchange
9719 def.resolve();
9720 await animationFrame();
9721
9722 // check the current line is added with the correct content
9723 expect(".o_data_row [name=turtle_foo]").toHaveText("hello");
9724 });
9725
9726 test("no deadlock when leaving a one2many line with uncommitted changes", async () => {
9727 // Before unselecting a o2m line, field widgets are asked to commit their changes (new values
9728 // that they wouldn't have sent to the model yet). This test is added alongside a bug fix
9729 // ensuring that we don't end up in a deadlock when a widget actually has some changes to
9730 // commit at that moment.
9731 onRpc((args) => {
9732 expect.step(args.method);
9733 });
9734 await mountView({
9735 type: "form",
9736 resModel: "partner",
9737 arch: `
9738 <form>
9739 <field name="turtles">
9740 <list editable="bottom">
9741 <field name="turtle_foo"/>
9742 </list>
9743 </field>
9744 </form>`,
9745 });
9746
9747 await contains(".o_field_x2many_list_row_add a").click();
9748
9749 await contains(".o_field_widget[name=turtles] input").edit("some foo value", {
9750 confirm: false,
9751 });
9752
9753 // click to add a second row to unselect the current one, then save
9754 await contains(".o_field_x2many_list_row_add a").click();
9755 await clickSave();
9756
9757 expect(".o_form_editable").toHaveCount(1);
9758 expect(".o_data_row:eq(0)").toHaveText("some foo value");
9759 expect.verifySteps([
9760 "get_views", // main form view
9761 "onchange", // main record
9762 "onchange", // line 1
9763 "onchange", // line 2
9764 "web_save",
9765 ]);
9766 });
9767
9768 test("one2many with extra field from server not in form", async () => {
9769 mockTimeZone(0);
9770 onRpc("web_save", (args) => {
9771 args.args[1].p[0][2].datetime = "2018-04-05 12:00:00";
9772 });
9773 await mountView({
9774 type: "form",
9775 resModel: "partner",
9776 arch: `
9777 <form>
9778 <field name="p">
9779 <list>
9780 <field name="datetime"/>
9781 <field name="name"/>
9782 </list>
9783 <form>
9784 <field name="name"/>
9785 </form>
9786 </field>
9787 </form>`,
9788 resId: 1,
9789 });
9790
9791 // Add a record in the list
9792 await contains(".o_field_x2many_list_row_add a").click();
9793 await contains(".modal div[name=name] input").edit("michelangelo", { confirm: false });
9794
9795 // Save the record in the modal (though it is still virtual)
9796 await contains(".modal .btn-primary").click();
9797
9798 expect(".o_data_row").toHaveCount(1);
9799 let cells = queryAll(".o_data_cell");
9800 expect(cells[0]).toHaveText("");
9801 expect(cells[1]).toHaveText("michelangelo");
9802
9803 // Save the whole thing
9804 await clickSave();
9805
9806 // Redo asserts in RO mode after saving
9807 expect(".o_data_row").toHaveCount(1);
9808 cells = queryAll(".o_data_cell");
9809 expect(cells[0]).toHaveText("Apr 5, 2018, 12:00 PM");
9810 expect(cells[1]).toHaveText("michelangelo");
9811 });
9812
9813 test.tags("desktop");
9814 test("one2many invisible depends on parent field", async () => {
9815 Partner._records[0].p = [2];
9816
9817 await mountView({
9818 type: "form",
9819 resModel: "partner",
9820 arch: `
9821 <form>
9822 <sheet>
9823 <group>
9824 <field name="product_id"/>
9825 </group>
9826 <notebook>
9827 <page string="Partner page">
9828 <field name="bar"/>
9829 <field name="p">
9830 <list>
9831 <field name="foo" column_invisible="parent.product_id"/>
9832 <field name="bar" column_invisible="not parent.bar"/>
9833 </list>
9834 </field>
9835 </page>
9836 </notebook>
9837 </sheet>
9838 </form>`,
9839 resId: 1,
9840 });
9841
9842 expect("th:not(.o_list_actions_header)").toHaveCount(2);
9843
9844 await selectFieldDropdownItem("product_id", "xphone");
9845
9846 expect("th:not(.o_list_actions_header)").toHaveCount(1, {
9847 message: "should be 1 column when the product_id is set",
9848 });
9849 await contains(".o_field_many2one[name=product_id] input").clear({ confirm: "blur" });
9850 expect("th:not(.o_list_actions_header)").toHaveCount(2, {
9851 message: "should be 2 columns in the one2many when product_id is not set",
9852 });
9853 await contains(".o_field_boolean[name=bar] input").click();
9854 expect("th:not(.o_list_actions_header)").toHaveCount(1, {
9855 message: "should be 1 column after the value change",
9856 });
9857 });
9858
9859 test.tags("desktop");
9860 test("column_invisible attrs on a button in a one2many list", async () => {
9861 Partner._records[0].p = [2];
9862 await mountView({
9863 type: "form",
9864 resModel: "partner",
9865 arch: `
9866 <form>
9867 <field name="product_id"/>
9868 <field name="p">
9869 <list>
9870 <field name="foo"/>
9871 <button name="abc" string="Do it" class="some_button" column_invisible="not parent.product_id"/>
9872 </list>
9873 </field>
9874 </form>`,
9875 resId: 1,
9876 });
9877 expect(".o_field_widget[name=product_id] input").toHaveValue("");
9878 expect(".o_list_table th").toHaveCount(2); // foo + trash bin
9879 expect(".some_button").toHaveCount(0);
9880 await selectFieldDropdownItem("product_id", "xphone");
9881
9882 expect(".o_field_widget[name=product_id] input").toHaveValue("xphone");
9883 expect(".o_list_table th").toHaveCount(3); // foo + button + trash bin
9884 expect(".some_button").toHaveCount(1);
9885 });
9886
9887 test.tags("desktop");
9888 test("column_invisible attrs on adjacent buttons", async () => {
9889 Partner._records[0].p = [2];
9890 await mountView({
9891 type: "form",
9892 resModel: "partner",
9893 arch: `
9894 <form>
9895 <field name="product_id"/>
9896 <field name="trululu"/>
9897 <field name="p">
9898 <list>
9899 <button name="abc1" string="Do it 1" class="some_button1"/>
9900 <button name="abc2" string="Do it 2" class="some_button2" column_invisible="parent.product_id"/>
9901 <field name="foo"/>
9902 <button name="abc3" string="Do it 3" class="some_button3" column_invisible="parent.product_id"/>
9903 <button name="abc4" string="Do it 4" class="some_button4" column_invisible="parent.trululu"/>
9904 </list>
9905 </field>
9906 </form>`,
9907 resId: 1,
9908 });
9909
9910 expect(".o_field_widget[name=product_id] input").toHaveValue("");
9911 expect(".o_field_widget[name=trululu] input").toHaveValue("aaa");
9912 expect(".o_list_table th").toHaveCount(4); // button group 1 + foo + button group 2 + trash bin
9913 expect(".some_button1").toHaveCount(1);
9914 expect(".some_button2").toHaveCount(1);
9915 expect(".some_button3").toHaveCount(1);
9916 expect(".some_button4").toHaveCount(0);
9917
9918 await selectFieldDropdownItem("product_id", "xphone");
9919
9920 expect(".o_field_widget[name=product_id] input").toHaveValue("xphone");
9921 expect(".o_field_widget[name=trululu] input").toHaveValue("aaa");
9922 expect(".o_list_table th").toHaveCount(3); // button group 1 + foo + trash bin
9923 expect(".some_button1").toHaveCount(1);
9924 expect(".some_button2").toHaveCount(0);
9925 expect(".some_button3").toHaveCount(0);
9926 expect(".some_button4").toHaveCount(0);
9927 });
9928
9929 test("field context is correctly passed to x2m subviews", async () => {
9930 await mountView({
9931 type: "form",
9932 resModel: "partner",
9933 arch: `
9934 <form>
9935 <field name="turtles" context="{'some_key': 1}">
9936 <kanban>
9937 <templates>
9938 <t t-name="card">
9939 <t t-if="context.some_key">
9940 <field name="turtle_foo"/>
9941 </t>
9942 </t>
9943 </templates>
9944 </kanban>
9945 </field>
9946 </form>`,
9947 resId: 1,
9948 });
9949
9950 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
9951 expect(".o_kanban_record span:contains('blip')").toHaveCount(1);
9952 });
9953
9954 test.tags("desktop");
9955 test("one2many kanban with widget handle", async () => {
9956 Partner._records[0].turtles = [1, 2, 3];
9957 onRpc("write", (args) => {
9958 expect(args.args[1]).toEqual({
9959 turtles: [
9960 [1, 2, { turtle_int: 0 }],
9961 [1, 3, { turtle_int: 1 }],
9962 [1, 1, { turtle_int: 2 }],
9963 ],
9964 });
9965 });
9966 await mountView({
9967 type: "form",
9968 resModel: "partner",
9969 arch: `
9970 <form>
9971 <field name="turtles">
9972 <kanban>
9973 <field name="turtle_int" widget="handle"/>
9974 <templates>
9975 <t t-name="card">
9976 <field name="turtle_foo"/>
9977 </t>
9978 </templates>
9979 </kanban>
9980 </field>
9981 </form>`,
9982 resId: 1,
9983 });
9984
9985 expect(
9986 queryAllTexts(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)")
9987 ).toEqual(["yop", "blip", "kawa"]);
9988
9989 // // should not work (form in mode "readonly")
9990 // await contains(".o_kanban_record:eq(0)").dragAndDrop(".o_kanban_record:eq(2)");
9991 // expect(
9992 // queryAllTexts(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)")).toEqual(
9993 // ["yop", "blip", "kawa"]
9994 // );
9995
9996 await contains(".o_kanban_record:eq(0)").dragAndDrop(".o_kanban_record:eq(2)");
9997
9998 expect(
9999 queryAllTexts(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)")
10000 ).toEqual(["blip", "kawa", "yop"]);
10001
10002 await clickSave();
10003 });
10004
10005 test("one2many editable list: edit and click on add a line", async () => {
10006 Turtle._onChanges = {
10007 turtle_int: function () {},
10008 };
10009 onRpc("onchange", (args) => {
10010 expect.step("onchange");
10011 });
10012 await mountView({
10013 type: "form",
10014 resModel: "partner",
10015 arch: `
10016 <form>
10017 <field name="turtles">
10018 <list editable="bottom"><field name="turtle_int"/></list>
10019 </field>
10020 </form>`,
10021 resId: 1,
10022 });
10023
10024 expect(".o_data_row").toHaveCount(1);
10025
10026 // edit first row
10027 await contains(".o_data_row .o_data_cell").click();
10028 expect(".o_data_row").toHaveClass("o_selected_row");
10029 await contains(".o_selected_row .o_field_widget[name=turtle_int] input").edit("44", {
10030 confirm: false,
10031 });
10032 expect.verifySteps([]);
10033 await contains(".o_field_x2many_list_row_add a").click();
10034 expect.verifySteps(["onchange", "onchange"]);
10035
10036 expect(".o_data_row").toHaveCount(2);
10037 expect(".o_data_cell:eq(0)").toHaveText("44");
10038 expect(".o_data_row:eq(1)").toHaveClass("o_selected_row");
10039 });
10040
10041 test("many2manys inside a one2many are fetched in batch after onchange", async () => {
10042 Partner._onChanges = {
10043 turtles: function (obj) {
10044 obj.turtles = [
10045 [4, 1],
10046 [4, 2],
10047 [
10048 1,
10049 1,
10050 {
10051 turtle_foo: "leonardo",
10052 partner_ids: [[4, 2]],
10053 },
10054 ],
10055 ];
10056 },
10057 };
10058 onRpc((args) => {
10059 expect.step(args.method || args.route);
10060 });
10061 await mountView({
10062 type: "form",
10063 resModel: "partner",
10064 arch: `
10065 <form>
10066 <field name="turtles">
10067 <list editable="bottom">
10068 <field name="turtle_foo"/>
10069 <field name="partner_ids" widget="many2many_tags"/>
10070 </list>
10071 </field>
10072 </form>`,
10073 });
10074
10075 expect(".o_data_row").toHaveCount(2);
10076 expect(queryAllTexts('.o_field_widget[name="partner_ids"]')).toEqual([
10077 "second record",
10078 "second record\naaa",
10079 ]);
10080
10081 expect.verifySteps(["get_views", "onchange"]);
10082 });
10083
10084 test("two one2many fields with same relation and _onChanges", async () => {
10085 // this test simulates the presence of two one2many fields with _onChanges, such that
10086 // changes to the first o2m are repercuted on the second one
10087 Partner._fields.turtles2 = fields.One2many({
10088 string: "Turtles 2",
10089 type: "one2many",
10090 relation: "turtle",
10091 relation_field: "turtle_trululu",
10092 });
10093 Partner._onChanges = {
10094 turtles: function (obj) {
10095 // replicate changes on turtles2
10096 if (obj.turtles.length) {
10097 const command = obj.turtles2 && obj.turtles2[0];
10098 if (command) {
10099 // second onchange (with ABC): there's already a create command
10100 obj.turtles2 = [[1, command[1], obj.turtles[0][2]]];
10101 } else {
10102 // first onchange (when adding the row): replicate the create command
10103 obj.turtles2 = [[0, false, obj.turtles[0][2]]];
10104 }
10105 }
10106 },
10107 turtles2: () => {}, // simulate an onchange on turtles2 as well
10108 };
10109
10110 await mountView({
10111 type: "form",
10112 resModel: "partner",
10113 arch: `
10114 <form>
10115 <field name="turtles">
10116 <list editable="bottom"><field name="name" required="1"/></list>
10117 </field>
10118 <field name="turtles2">
10119 <list editable="bottom"><field name="name" required="1"/></list>
10120 </field>
10121 </form>`,
10122 });
10123
10124 // trigger first onchange by adding a line in turtles field (should add a line in turtles2)
10125 await contains('.o_field_widget[name="turtles"] .o_field_x2many_list_row_add a').click();
10126 await contains('.o_field_widget[name="turtles"] .o_field_widget[name="name"] input').edit(
10127 "ABC",
10128 { confirm: "blur" }
10129 );
10130
10131 expect('.o_field_widget[name="turtles"] .o_data_row').toHaveCount(1, {
10132 message: "line of first o2m should have been created",
10133 });
10134 expect('.o_field_widget[name="turtles2"] .o_data_row').toHaveCount(1, {
10135 message: "line of second o2m should have been created",
10136 });
10137
10138 // add a line in turtles2
10139 await contains('.o_field_widget[name="turtles2"] .o_field_x2many_list_row_add a').click();
10140 await contains('.o_field_widget[name="turtles2"] .o_field_widget[name="name"] input').edit(
10141 "DEF",
10142 { confirm: false }
10143 );
10144
10145 expect('.o_field_widget[name="turtles"] .o_data_row').toHaveCount(1, {
10146 message: "we should still have 1 line in turtles",
10147 });
10148 expect('.o_field_widget[name="turtles2"] .o_data_row').toHaveCount(2);
10149 expect('.o_field_widget[name="turtles2"] .o_data_row:eq(1)').toHaveClass("o_selected_row");
10150
10151 await clickSave();
10152
10153 expect(queryAllTexts('.o_field_widget[name="turtles2"] .o_data_row')).toEqual(["ABC", "DEF"]);
10154 });
10155
10156 test.tags("desktop");
10157 test("one2many reset by onchange (of another field) while being edited", async () => {
10158 // In this test, we have a many2one and a one2many. The many2one has an onchange that
10159 // updates the value of the one2many. We set a new value to the many2one (name_create)
10160 // such that the onchange is delayed. During the name_create, we click to add a new row
10161 // to the one2many. After a while, we unlock the name_create, which triggers the onchange
10162 // and resets the one2many. At the end, we want the row to be in edition.
10163
10164 const def = new Deferred();
10165 Partner._onChanges = {
10166 trululu: () => {},
10167 };
10168 onRpc("name_create", () => def);
10169 await mountView({
10170 type: "form",
10171 resModel: "partner",
10172 arch: `
10173 <form>
10174 <field name="trululu"/>
10175 <field name="p">
10176 <list editable="top"><field name="product_id" required="1"/></list>
10177 </field>
10178 </form>`,
10179 });
10180
10181 // set a new value for trululu (will delay the onchange)
10182 await contains(".o_field_widget[name=trululu] input").edit("new value", { confirm: false });
10183 await runAllTimers();
10184 await clickFieldDropdownItem("trululu", `Create "new value"`);
10185
10186 // add a row in p
10187 await contains(".o_field_x2many_list_row_add a").click();
10188 expect(".o_data_row").toHaveCount(0);
10189
10190 // resolve the name_create to trigger the onchange, and the reset of p
10191 def.resolve();
10192 await animationFrame();
10193 expect(".o_data_row").toHaveCount(1);
10194 expect(".o_data_row").toHaveClass("o_selected_row");
10195 });
10196
10197 test("one2many with many2many_tags in list and list in form with a limit", async () => {
10198 // This test encodes a limitation of the current model architecture:
10199 // we have an nested x2manys, and the inner one is displayed as tags
10200 // in the list, and as a list in the form. As both the list and the
10201 // form will use the same Record datapoint, the config of their static
10202 // list will be the same. We obviously don't want to see the limit
10203 // applied on the tags (in the background) when opening the form. So
10204 // the stategy is to keep the initial config, and to ignore the
10205 // limit set on the list
10206 Partner._records[0].p = [1];
10207 Partner._records[0].turtles = [1, 2, 3];
10208
10209 await mountView({
10210 type: "form",
10211 resModel: "partner",
10212 arch: `
10213 <form>
10214 <field name="bar"/>
10215 <field name="p">
10216 <list>
10217 <field name="turtles" widget="many2many_tags"/>
10218 </list>
10219 <form>
10220 <field name="turtles">
10221 <list limit="2">
10222 <field name="name"/>
10223 </list>
10224 </field>
10225 </form>
10226 </field>
10227 </form>`,
10228 resId: 1,
10229 });
10230
10231 expect(".o_field_widget[name=p] .o_data_row").toHaveCount(1);
10232 expect(".o_data_row .o_field_many2many_tags .badge").toHaveCount(3);
10233
10234 await contains(".o_data_cell").click();
10235
10236 expect(".modal .o_form_view").toHaveCount(1);
10237 expect(".modal .o_field_widget[name=turtles] .o_data_row").toHaveCount(3);
10238 expect(".modal .o_field_x2many_list .o_pager").not.toHaveCount();
10239 });
10240
10241 test("one2many with many2many_tags in list and list in form, and onchange", async () => {
10242 Partner._onChanges = {
10243 bar: function (obj) {
10244 obj.p = [[0, 0, { turtles: [[0, 0, { name: "new turtle" }]] }]];
10245 },
10246 };
10247
10248 await mountView({
10249 type: "form",
10250 resModel: "partner",
10251 arch: `
10252 <form>
10253 <field name="bar"/>
10254 <field name="p">
10255 <list>
10256 <field name="turtles" widget="many2many_tags"/>
10257 </list>
10258 <form>
10259 <field name="turtles">
10260 <list editable="bottom">
10261 <field name="name"/>
10262 </list>
10263 </field>
10264 </form>
10265 </field>
10266 </form>`,
10267 });
10268
10269 expect(".o_field_widget[name=p] .o_data_row").toHaveCount(1);
10270 expect(".o_data_row .o_field_many2many_tags .badge").toHaveCount(1);
10271
10272 await contains(".o_data_row .o_data_cell").click();
10273
10274 expect(".modal .o_form_view").toHaveCount(1);
10275 expect(".modal .o_field_widget[name=turtles] .o_data_row").toHaveCount(1);
10276 expect(queryAllTexts(".modal .o_data_cell")).toEqual(["new turtle"]);
10277
10278 await contains(".modal .o_field_x2many_list_row_add a").click();
10279 expect(".modal .o_field_widget[name=turtles] .o_data_row").toHaveCount(2);
10280 expect(queryAllTexts(".modal .o_data_cell")).toEqual(["new turtle", ""]);
10281 expect(".modal .o_field_widget[name=turtles] .o_data_row:eq(1)").toHaveClass("o_selected_row");
10282 });
10283
10284 test("one2many with many2many_tags in list and list in form, and onchange (2)", async () => {
10285 Partner._onChanges = {
10286 bar: function (obj) {
10287 obj.p = [
10288 [
10289 0,
10290 0,
10291 {
10292 turtles: [
10293 [
10294 0,
10295 0,
10296 {
10297 display_name: "new turtle",
10298 },
10299 ],
10300 ],
10301 },
10302 ],
10303 ];
10304 },
10305 };
10306 Turtle._onChanges = {
10307 turtle_foo: function (obj) {
10308 obj.display_name = obj.turtle_foo;
10309 },
10310 };
10311
10312 await mountView({
10313 type: "form",
10314 resModel: "partner",
10315 arch: `
10316 <form>
10317 <field name="bar"/>
10318 <field name="p">
10319 <list>
10320 <field name="turtles" widget="many2many_tags"/>
10321 </list>
10322 <form>
10323 <field name="turtles">
10324 <list editable="bottom">
10325 <field name="turtle_foo" required="1"/>
10326 </list>
10327 </field>
10328 </form>
10329 </field>
10330 </form>`,
10331 });
10332
10333 expect(".o_field_widget[name=p] .o_data_row").toHaveCount(1);
10334
10335 await contains(".o_data_row .o_data_cell").click();
10336
10337 expect(".modal .o_form_view").toHaveCount(1);
10338
10339 await contains(".modal .o_field_x2many_list_row_add a").click();
10340 expect(".modal .o_field_widget[name=turtles] .o_data_row").toHaveCount(2);
10341
10342 await contains(".modal .o_selected_row input").edit("another one", { confirm: false });
10343 await contains(".modal .modal-footer .btn-primary").click();
10344
10345 expect(".modal").toHaveCount(0);
10346
10347 expect(".o_field_widget[name=p] .o_data_row").toHaveCount(1);
10348 expect(".o_data_row .o_field_many2many_tags .badge").toHaveCount(2);
10349 expect(queryAllTexts(".o_data_row .o_field_many2many_tags .o_tag_badge_text")).toEqual([
10350 "new turtle",
10351 "another one",
10352 ]);
10353 });
10354
10355 test("reorder one2many with many2many_tags in list and list in form", async () => {
10356 expect.assertions(3);
10357
10358 Partner._records[0].p = [2, 4];
10359 Partner._records[0].p = [1, 4];
10360
10361 Partner._views = {
10362 form: `
10363 <form>
10364 <field name="p">
10365 <list editable="top">
10366 <field name="int_field" widget="handle"/>
10367 <field name="name"/>
10368 </list>
10369 </field>
10370 </form>`,
10371 };
10372 await mountView({
10373 type: "form",
10374 resModel: "partner",
10375 arch: `
10376 <form>
10377 <field name="p">
10378 <list>
10379 <field name="name"/>
10380 <field name="p" widget="many2many_tags"/>
10381 </list>
10382 </field>
10383 </form>`,
10384 resId: 1,
10385 });
10386
10387 await contains(".o_data_cell").click();
10388 expect(".modal").toHaveCount(1);
10389 expect(queryAllTexts(".modal [name='name']")).toEqual(["aaa", "first record"]);
10390
10391 await contains(".modal tr:eq(2) .o_handle_cell").dragAndDrop(".modal tr:eq(1)");
10392 expect(queryAllTexts(".modal [name='name']")).toEqual(["first record", "aaa"]);
10393 });
10394
10395 test("nested one2many, onchange, no command value", async () => {
10396 // This test ensures that we always send all values to onchange rpcs for nested
10397 // one2manys, even if some field hasn't changed. In this particular test case,
10398 // a first onchange returns a value for the inner one2many, and a second onchange
10399 // removes it, thus restoring the field to its initial empty value. From this point,
10400 // the nested one2many value must still be sent to onchange rpcs (on the main record),
10401 // as it might be used to compute other fields (so the fact that the nested o2m is empty
10402 // must be explicit).
10403 expect.assertions(1);
10404
10405 Turtle._fields.o2m = fields.One2many({
10406 string: "o2m",
10407 relation: "partner",
10408 relation_field: "trululu",
10409 });
10410 Partner._onChanges.turtles = function (obj) {};
10411 Turtle._onChanges.turtle_bar = function (obj) {};
10412
10413 let step = 1;
10414 onRpc((args) => {
10415 if (step === 3 && args.method === "onchange" && args.model === "partner") {
10416 expect(args.args[1].turtles[0][2]).toEqual({
10417 o2m: [],
10418 turtle_bar: false,
10419 });
10420 }
10421 if (args.model === "turtle") {
10422 if (step === 2) {
10423 return {
10424 value: {
10425 o2m: [[0, false, { name: "default" }]],
10426 turtle_bar: true,
10427 },
10428 };
10429 }
10430 if (step === 3) {
10431 const virtualId = args.args[1].o2m[0][1];
10432 return {
10433 value: { o2m: [[2, virtualId]] },
10434 };
10435 }
10436 }
10437 });
10438 await mountView({
10439 type: "form",
10440 resModel: "partner",
10441 arch: `
10442 <form>
10443 <field name="turtles">
10444 <list editable="bottom">
10445 <field name="o2m"/>
10446 <field name="turtle_bar"/>
10447 </list>
10448 </field>
10449 </form>`,
10450 });
10451
10452 step = 2;
10453 await contains(".o_field_x2many_list_row_add a").click();
10454 step = 3;
10455 await contains(".o_data_row .o_field_boolean input").click();
10456 });
10457
10458 test("edition in list containing widget with decoration", async () => {
10459 // We use here a badge widget and check its decoration is properly managed
10460 // in this scenario (we need a widget with specific decoration handling)
10461 Partner._records[0].p = [1, 2];
10462 await mountView({
10463 type: "form",
10464 resModel: "partner",
10465 arch: `
10466 <form>
10467 <field name="p">
10468 <list editable="bottom">
10469 <field name="int_field"/>
10470 <field name="color" widget="badge" decoration-warning="int_field == 9"/>
10471 </list>
10472 </field>
10473 </form>`,
10474 resId: 1,
10475 });
10476
10477 expect(".o_data_row").toHaveCount(2);
10478 expect(".o_data_row:eq(1) .o_field_badge .badge").toHaveClass("text-bg-warning");
10479
10480 await contains(".o_data_row .o_data_cell").click();
10481 await contains(".o_selected_row .o_field_integer input").edit("44", { confirm: false });
10482
10483 expect(".o_data_row:eq(1) .o_field_badge .badge").toHaveClass("text-bg-warning");
10484 });
10485
10486 test("reordering embedded one2many with handle widget starting with same sequence", async () => {
10487 Turtle._records = [
10488 { id: 1, turtle_int: 1 },
10489 { id: 2, turtle_int: 1 },
10490 { id: 3, turtle_int: 1 },
10491 { id: 4, turtle_int: 2 },
10492 { id: 5, turtle_int: 3 },
10493 { id: 6, turtle_int: 4 },
10494 ];
10495 Partner._records[0].turtles = [1, 2, 3, 4, 5, 6];
10496
10497 await mountView({
10498 type: "form",
10499 resModel: "partner",
10500 arch: `
10501 <form>
10502 <field name="turtles">
10503 <list default_order="turtle_int">
10504 <field name="turtle_int" widget="handle"/>
10505 <field name="id"/>
10506 </list>
10507 </field>
10508 </form>`,
10509 resId: 1,
10510 });
10511
10512 expect(queryAllTexts(".o_data_cell:not(.o_handle_cell)")).toEqual([
10513 "1",
10514 "2",
10515 "3",
10516 "4",
10517 "5",
10518 "6",
10519 ]);
10520
10521 // Drag and drop the fourth line in first position
10522 await contains("tbody tr:eq(3) .o_handle_cell").dragAndDrop("tbody tr");
10523
10524 expect(queryAllTexts(".o_data_cell:not(.o_handle_cell)")).toEqual([
10525 "4",
10526 "1",
10527 "2",
10528 "3",
10529 "5",
10530 "6",
10531 ]);
10532
10533 await clickSave();
10534 expect(MockServer.env["turtle"].map((r) => pick(r, "id", "turtle_int"))).toEqual([
10535 { id: 1, turtle_int: 2 },
10536 { id: 2, turtle_int: 3 },
10537 { id: 3, turtle_int: 4 },
10538 { id: 4, turtle_int: 1 },
10539 { id: 5, turtle_int: 5 },
10540 { id: 6, turtle_int: 6 },
10541 ]);
10542 });
10543
10544 test("combine contexts on o2m field and create tags", async () => {
10545 expect.assertions(1);
10546 onRpc("turtle", "onchange", (args) => {
10547 expect(args.kwargs.context).toEqual(
10548 {
10549 allowed_company_ids: [1],
10550 default_turtle_foo: "soft",
10551 default_turtle_bar: true,
10552 default_turtle_int: 2,
10553 lang: "en",
10554 tz: "taht",
10555 uid: 7,
10556 },
10557 {
10558 message:
10559 "combined context should have the default_turtle_foo value from the <create>",
10560 }
10561 );
10562 });
10563 await mountView({
10564 type: "form",
10565 resModel: "partner",
10566 arch: `
10567 <form>
10568 <sheet>
10569 <field name="turtles" context="{'default_turtle_foo': 'hard', 'default_turtle_bar': True}">
10570 <list editable="bottom">
10571 <control>
10572 <create name="add_soft_shell_turtle" string="Add soft shell turtle" context="{'default_turtle_foo': 'soft', 'default_turtle_int': 2}"/>
10573 </control>
10574 <field name="turtle_foo"/>
10575 </list>
10576 </field>
10577 </sheet>
10578 </form>`,
10579 });
10580
10581 await contains(".o_field_x2many_list_row_add a").click();
10582 });
10583
10584 test("do not call read if name already known", async () => {
10585 Partner._fields.product_id = fields.Many2one({ relation: "product", default: 37 });
10586 Partner._onChanges = {
10587 trululu: function (obj) {
10588 obj.trululu = 1;
10589 },
10590 };
10591 onRpc((args) => {
10592 expect.step(args.method + " on " + args.model);
10593 });
10594 await mountView({
10595 type: "form",
10596 resModel: "partner",
10597 arch: `
10598 <form>
10599 <field name="trululu"/>
10600 <field name="product_id"/>
10601 </form>`,
10602 });
10603
10604 expect(".o_field_widget[name=trululu] input").toHaveValue("first record");
10605 expect(".o_field_widget[name=product_id] input").toHaveValue("xphone");
10606 expect.verifySteps(["get_views on partner", "onchange on partner"]);
10607 });
10608
10609 test("x2many default_order multiple fields", async () => {
10610 Partner._records = [
10611 { int_field: 10, id: 1, name: "record1" },
10612 { int_field: 12, id: 2, name: "record2" },
10613 { int_field: 11, id: 3, name: "record3" },
10614 { int_field: 12, id: 4, name: "record4" },
10615 { int_field: 10, id: 5, name: "record5" },
10616 { int_field: 10, id: 6, name: "record6" },
10617 { int_field: 11, id: 7, name: "record7" },
10618 ];
10619
10620 Partner._records[0].p = [1, 7, 4, 5, 2, 6, 3];
10621
10622 await mountView({
10623 type: "form",
10624 resModel: "partner",
10625 arch: `
10626 <form>
10627 <field name="p" >
10628 <list default_order="int_field,id">
10629 <field name="id"/>
10630 <field name="int_field"/>
10631 </list>
10632 </field>
10633 </form>`,
10634 resId: 1,
10635 });
10636 expect(queryAllTexts(".o_field_x2many_list .o_data_row .o_data_cell[name=id]")).toEqual([
10637 "1",
10638 "5",
10639 "6",
10640 "3",
10641 "7",
10642 "2",
10643 "4",
10644 ]);
10645 });
10646
10647 test("x2many default_order multiple fields with limit", async () => {
10648 Partner._records = [
10649 { int_field: 10, id: 1, name: "record1" },
10650 { int_field: 12, id: 2, name: "record2" },
10651 { int_field: 11, id: 3, name: "record3" },
10652 { int_field: 12, id: 4, name: "record4" },
10653 { int_field: 10, id: 5, name: "record5" },
10654 { int_field: 10, id: 6, name: "record6" },
10655 { int_field: 11, id: 7, name: "record7" },
10656 ];
10657
10658 Partner._records[0].p = [1, 7, 4, 5, 2, 6, 3];
10659
10660 await mountView({
10661 type: "form",
10662 resModel: "partner",
10663 arch: `
10664 <form>
10665 <field name="p" >
10666 <list default_order="int_field,id" limit="4">
10667 <field name="id"/>
10668 <field name="int_field"/>
10669 </list>
10670 </field>
10671 </form>`,
10672 resId: 1,
10673 });
10674 expect(queryAllTexts(".o_field_x2many_list .o_data_row .o_data_cell[name=id]")).toEqual([
10675 "1",
10676 "5",
10677 "6",
10678 "3",
10679 ]);
10680 });
10681
10682 test("one2many from a model that has been sorted", async () => {
10683 Partner._views = {
10684 list: `<list><field name="int_field"/></list>`,
10685 form: `
10686 <form>
10687 <field name="turtles">
10688 <list><field name="turtle_foo"/></list>
10689 </field>
10690 </form>`,
10691 };
10692 Partner._records[0].turtles = [3, 2];
10693
10694 await mountWithCleanup(WebClient);
10695 await getService("action").doAction({
10696 id: 1,
10697 name: "test",
10698 res_model: "partner",
10699 type: "ir.actions.act_window",
10700 views: [
10701 [false, "list"],
10702 [false, "form"],
10703 ],
10704 });
10705 expect(".o_list_view").toHaveCount(1);
10706 expect(queryAllTexts(".o_data_cell")).toEqual(["10", "9", "0"]);
10707
10708 await contains("th.o_column_sortable").click();
10709 expect(queryAllTexts(".o_data_cell")).toEqual(["0", "9", "10"]);
10710
10711 await contains(".o_data_row:eq(2) .o_data_cell").click();
10712 expect(".o_form_view").toHaveCount(1);
10713 expect(queryAllTexts(".o_data_cell")).toEqual(["kawa", "blip"], {
10714 message: "The o2m should not have been sorted.",
10715 });
10716 });
10717
10718 test("prevent the dialog in readonly x2many list view with option no_open True", async () => {
10719 await mountView({
10720 type: "form",
10721 resModel: "partner",
10722 arch: `
10723 <form>
10724 <sheet>
10725 <field name="turtles">
10726 <list editable="bottom" no_open="True">
10727 <field name="turtle_foo"/>
10728 </list>
10729 </field>
10730 </sheet>
10731 </form>`,
10732 resId: 1,
10733 });
10734 expect('.o_data_row:contains("blip")').toHaveCount(1, {
10735 message: "There should be one record in x2many list view",
10736 });
10737 await contains(".o_data_row .o_data_cell").click();
10738 expect(".modal").toHaveCount(0, {
10739 message: "There is should be no dialog open on click of readonly list row",
10740 });
10741 });
10742
10743 test("delete a record while adding another one in a multipage", async () => {
10744 // in a one2many with at least 2 pages, add a new line. Delete the line above it.
10745 // it should load the next line to display it on the page.
10746 Partner._records[0].turtles = [2, 3];
10747
10748 await mountView({
10749 type: "form",
10750 resModel: "partner",
10751 arch: `
10752 <form>
10753 <sheet>
10754 <group>
10755 <field name="turtles">
10756 <list editable="bottom" limit="1" decoration-muted="turtle_bar == False">
10757 <field name="turtle_foo"/>
10758 <field name="turtle_bar"/>
10759 </list>
10760 </field>
10761 </group>
10762 </sheet>
10763 </form>`,
10764 resId: 1,
10765 });
10766
10767 // add a line (virtual record)
10768 await contains(".o_field_x2many_list_row_add a").click();
10769 await contains(".o_field_widget[name=turtle_foo] input").edit("pi", { confirm: false });
10770 // delete the line above it
10771 await contains(".o_list_record_remove").click();
10772 // the next line should be displayed below the newly added one
10773 expect(".o_data_row").toHaveCount(2);
10774 expect(queryAllTexts(".o_data_cell")).toEqual(["pi", "", "kawa", ""], {
10775 message: "should display the correct records on page 1",
10776 });
10777 });
10778
10779 test("one2many, onchange, edition and multipage...", async () => {
10780 Partner._onChanges = {
10781 turtles: function (obj) {
10782 obj.turtles = [[5]].concat(obj.turtles);
10783 },
10784 };
10785
10786 Partner._records[0].turtles = [1, 2, 3];
10787 onRpc((args) => {
10788 expect.step(args.method + " " + args.model);
10789 });
10790 await mountView({
10791 type: "form",
10792 resModel: "partner",
10793 arch: `
10794 <form>
10795 <field name="turtles">
10796 <list editable="bottom" limit="2">
10797 <field name="turtle_foo"/>
10798 </list>
10799 </field>
10800 </form>`,
10801 resId: 1,
10802 });
10803 await contains(".o_field_x2many_list_row_add a").click();
10804 await contains(".o_field_widget[name=turtle_foo] input").edit("nora", { confirm: false });
10805 await contains(".o_field_x2many_list_row_add a").click();
10806
10807 expect.verifySteps([
10808 "get_views partner",
10809 "web_read partner",
10810 "onchange turtle",
10811 "onchange partner",
10812 "onchange partner",
10813 "onchange turtle",
10814 "onchange partner",
10815 ]);
10816 });
10817
10818 test("x2many multipage, onchange returning update commands with readonly field", async () => {
10819 expect.assertions(3);
10820
10821 Partner._records[0].turtles = [1, 2];
10822 Partner._onChanges = {
10823 foo: function (obj) {
10824 obj.turtles = [
10825 [1, 1, { name: "rec 1", turtle_foo: "new val 1" }],
10826 [1, 2, { name: "rec 2", turtle_foo: "new val 2" }],
10827 ];
10828 },
10829 };
10830 onRpc("web_save", ({ args }) => {
10831 expect(args[1]).toEqual({
10832 foo: "trigger onchange",
10833 turtles: [
10834 [1, 1, { name: "rec 1" }],
10835 [1, 2, { name: "rec 2" }],
10836 ],
10837 });
10838 });
10839 await mountView({
10840 type: "form",
10841 resModel: "partner",
10842 arch: `
10843 <form>
10844 <field name="foo"/>
10845 <field name="turtles">
10846 <list limit="1">
10847 <field name="name"/>
10848 <field name="turtle_foo" readonly="1"/>
10849 </list>
10850 </field>
10851 </form>`,
10852 resId: 1,
10853 });
10854
10855 expect(queryAllTexts(".o_data_cell")).toEqual(["leonardo", "yop"]);
10856
10857 await contains(".o_field_widget[name=foo] input").edit("trigger onchange", { confirm: "blur" });
10858 expect(queryAllTexts(".o_data_cell")).toEqual(["rec 1", "new val 1"]);
10859
10860 await clickSave();
10861 });
10862
10863 test("x2many multipage, onchange returning update commands with readonly field (2)", async () => {
10864 expect.assertions(3);
10865
10866 Partner._records[0].turtles = [1, 2];
10867 Partner._onChanges = {
10868 foo: function (obj) {
10869 obj.turtles = [
10870 [1, 1, { name: "rec 1", turtle_foo: "new val 1" }],
10871 [1, 2, { name: "rec 2", turtle_foo: "new val 2" }],
10872 ];
10873 },
10874 };
10875 onRpc("web_save", ({ args }) => {
10876 expect(args[1]).toEqual({
10877 foo: "trigger onchange",
10878 turtles: [
10879 [1, 1, { name: "rec 1" }],
10880 [1, 2, { name: "rec 2" }],
10881 ],
10882 });
10883 });
10884 await mountView({
10885 type: "form",
10886 resModel: "partner",
10887 arch: `
10888 <form>
10889 <field name="foo"/>
10890 <field name="turtles">
10891 <list limit="1">
10892 <field name="name" readonly="not context.get('some_key')"/>
10893 <field name="turtle_foo" readonly="context.get('some_key')"/>
10894 </list>
10895 </field>
10896 </form>`,
10897 resId: 1,
10898 context: { some_key: true },
10899 });
10900
10901 expect(queryAllTexts(".o_data_cell")).toEqual(["leonardo", "yop"]);
10902
10903 await contains(".o_field_widget[name=foo] input").edit("trigger onchange", { confirm: "blur" });
10904 expect(queryAllTexts(".o_data_cell")).toEqual(["rec 1", "new val 1"]);
10905
10906 await clickSave();
10907 });
10908
10909 test("x2many multipage, onchange returning update commands with readonly field (3)", async () => {
10910 expect.assertions(3);
10911
10912 Partner._records[0].turtles = [1, 2];
10913 Partner._onChanges = {
10914 foo: function (obj) {
10915 obj.turtles = [
10916 [1, 1, { name: "rec 1", turtle_foo: "new val 1" }],
10917 [1, 2, { name: "rec 2", turtle_foo: "new val 2" }],
10918 ];
10919 },
10920 };
10921 onRpc("web_save", ({ args }) => {
10922 expect(args[1]).toEqual({
10923 foo: "trigger onchange",
10924 turtles: [
10925 [1, 1, { name: "rec 1" }],
10926 // we can't evaluate the readonly expressions for the record of
10927 // second page, so we send both fields
10928 [1, 2, { name: "rec 2", turtle_foo: "new val 2" }],
10929 ],
10930 });
10931 });
10932 await mountView({
10933 type: "form",
10934 resModel: "partner",
10935 arch: `
10936 <form>
10937 <field name="foo"/>
10938 <field name="turtles">
10939 <list limit="1">
10940 <field name="name" readonly="not turtle_bar"/>
10941 <field name="turtle_foo" readonly="turtle_bar"/>
10942 <field name="turtle_bar" column_invisible="1"/>
10943 </list>
10944 </field>
10945 </form>`,
10946 resId: 1,
10947 context: { some_key: true },
10948 });
10949
10950 expect(queryAllTexts(".o_data_cell")).toEqual(["leonardo", "yop"]);
10951
10952 await contains(".o_field_widget[name=foo] input").edit("trigger onchange", { confirm: "blur" });
10953 expect(queryAllTexts(".o_data_cell")).toEqual(["rec 1", "new val 1"]);
10954
10955 await clickSave();
10956 });
10957
10958 test("onchange on unloaded record clearing posterious change", async () => {
10959 let numUserOnchange = 0;
10960 Users._onChanges = {
10961 partner_ids: function (obj) {
10962 numUserOnchange++;
10963 },
10964 };
10965
10966 await mountView({
10967 type: "form",
10968 resModel: "res.users",
10969 arch: `
10970 <form>
10971 <field name="partner_ids">
10972 <form>
10973 <field name="trululu"/>
10974 <field name="turtles">
10975 <list editable="bottom">
10976 <field name="name"/>
10977 </list>
10978 </field>
10979 </form>
10980 <list>
10981 <field name="name"/>
10982 </list>
10983 </field>
10984 </form>`,
10985 resId: 17,
10986 });
10987
10988 // open first partner and change turtle name
10989 await contains(".o_data_row .o_data_cell").click();
10990 await contains(".modal .o_data_row .o_data_cell").click();
10991 await contains(".modal .o_field_widget[name=name] input").edit("Donatello", { confirm: false });
10992 await contains(".modal .btn-primary").click();
10993
10994 await contains(".o_data_row:eq(1) .o_data_cell").click();
10995 await contains(".modal .o_field_x2many_list_row_add a").click();
10996 await contains(".modal .o_field_widget[name=name] input").edit("Michelangelo", {
10997 confirm: false,
10998 });
10999 await contains(".modal .btn-primary").click();
11000
11001 expect(numUserOnchange).toBe(2, {
11002 message: "there should be 2 and only 2 onchange from closing the partner modal",
11003 });
11004
11005 // check first record still has change
11006 await contains(".o_data_row .o_data_cell").click();
11007 expect(".modal .o_data_row").toHaveCount(1, { message: "only 1 turtle for first partner" });
11008 expect(".modal .o_data_cell").toHaveText("Donatello");
11009 await contains(".modal .o_form_button_cancel").click();
11010
11011 // check second record still has changes
11012 await contains(".o_data_row:eq(1) .o_data_cell").click();
11013 expect(".modal .o_data_row").toHaveCount(1, { message: "only 1 turtle for second partner" });
11014 expect(".modal .o_data_cell").toHaveText("Michelangelo");
11015 await contains(".modal .o_form_button_cancel").click();
11016
11017 // re-open, edit michelangelo row, click out -> row still there, in readonly
11018 await contains(".o_data_row:eq(1) .o_data_cell").click();
11019 await contains(".modal .o_data_row .o_data_cell").click();
11020 expect(".modal .o_selected_row").toHaveCount(1);
11021 await contains(".modal").click();
11022 expect(".modal .o_data_row").toHaveCount(1);
11023 expect(".modal .o_data_cell").toHaveText("Michelangelo");
11024 });
11025
11026 test("quickly switch between pages in one2many list", async () => {
11027 Partner._records[0].turtles = [1, 2, 3];
11028
11029 const readDefs = [null, new Deferred(), null];
11030 onRpc("web_read", async (args) => {
11031 const recordID = args.args[0][0];
11032 await readDefs[recordID - 1];
11033 });
11034 await mountView({
11035 type: "form",
11036 resModel: "partner",
11037 arch: `
11038 <form>
11039 <field name="turtles">
11040 <list limit="1">
11041 <field name="name"/>
11042 </list>
11043 </field>
11044 </form>`,
11045 resId: 1,
11046 });
11047
11048 expect(".o_data_cell").toHaveText("leonardo");
11049
11050 await contains(".o_field_widget[name=turtles] .o_pager_next").click();
11051 expect(".o_field_widget[name=turtles] .o_pager_next").not.toBeEnabled();
11052
11053 readDefs[1].resolve();
11054 await animationFrame();
11055 expect(".o_data_cell").toHaveText("donatello");
11056
11057 await contains(".o_field_widget[name=turtles] .o_pager_next").click();
11058 expect(" .o_data_cell").toHaveText("raphael");
11059 });
11060
11061 test("one2many column visiblity depends on onchange of parent field", async () => {
11062 Partner._records[0].p = [2];
11063 Partner._records[0].bar = false;
11064
11065 let triggerOnchange = false;
11066 Partner._onChanges.p = function (obj) {
11067 if (triggerOnchange) {
11068 obj.bar = true;
11069 }
11070 };
11071
11072 await mountView({
11073 type: "form",
11074 resModel: "partner",
11075 arch: `
11076 <form>
11077 <field name="bar"/>
11078 <field name="p">
11079 <list editable="bottom">
11080 <field name="foo"/>
11081 <field name="int_field" column_invisible="not parent.bar"/>
11082 </list>
11083 </field>
11084 </form>`,
11085 resId: 1,
11086 });
11087
11088 // bar is false so there should be 1 column
11089 expect(".o_list_renderer th:not(.o_list_actions_header)").toHaveCount(1);
11090 expect(".o_list_renderer .o_data_row").toHaveCount(1);
11091
11092 // add a new o2m record
11093 await contains(".o_field_x2many_list_row_add a").click();
11094 triggerOnchange = true;
11095 await contains(".o_field_one2many input").edit("New line", { confirm: false });
11096 await contains(".o_form_view").click();
11097
11098 expect(".o_list_renderer th:not(.o_list_actions_header)").toHaveCount(2);
11099 });
11100
11101 test.tags("desktop");
11102 test("one2many column_invisible on view not inline", async () => {
11103 Partner._records[0].p = [2];
11104 Partner._views = {
11105 list: `
11106 <list>
11107 <field name="foo" column_invisible="parent.product_id"/>
11108 <field name="bar" column_invisible="not parent.bar"/>
11109 </list>`,
11110 };
11111
11112 await mountView({
11113 type: "form",
11114 resModel: "partner",
11115 arch: `
11116 <form>
11117 <sheet>
11118 <group>
11119 <field name="product_id"/>
11120 </group>
11121 <notebook>
11122 <page string="Partner page">
11123 <field name="bar"/>
11124 <field name="p" widget="one2many"/>
11125 </page>
11126 </notebook>
11127 </sheet>
11128 </form>`,
11129 resId: 1,
11130 });
11131
11132 expect("th:not(.o_list_actions_header)").toHaveCount(2);
11133 await selectFieldDropdownItem("product_id", "xphone");
11134 expect("th:not(.o_list_actions_header)").toHaveCount(1, {
11135 message: "should be 1 column when the product_id is set",
11136 });
11137 await contains(".o_field_many2one[name=product_id] input").clear({ confirm: "blur" });
11138 expect("th:not(.o_list_actions_header)").toHaveCount(2, {
11139 message: "should be 2 columns in the one2many when product_id is not set",
11140 });
11141 await contains(".o_field_boolean[name=bar] input").click();
11142 expect("th:not(.o_list_actions_header)").toHaveCount(1, {
11143 message: "should be 1 column after the value change",
11144 });
11145 });
11146
11147 test.tags("desktop");
11148 test("one2many field in edit mode with optional fields and trash icon", async () => {
11149 Partner._records[0].p = [2];
11150 Partner._views = {
11151 list: `
11152 <list editable="top">
11153 <field name="foo" optional="show"/>
11154 <field name="bar" optional="hide"/>
11155 </list>`,
11156 };
11157 await mountView({
11158 type: "form",
11159 resModel: "partner",
11160 arch: `<form><field name="p"/></form>`,
11161 resId: 1,
11162 });
11163
11164 expect(".o_field_one2many table .o_optional_columns_dropdown .dropdown-toggle").toHaveCount(1);
11165
11166 // should have 2 columns 1 for foo and 1 for trash icon, dropdown is displayed
11167 // on trash icon cell, no separate cell created for trash icon and advanced field dropdown
11168 expect(".o_field_one2many th").toHaveCount(2, {
11169 message: "should be 2 th in the one2many edit mode",
11170 });
11171 expect(".o_field_one2many .o_data_row:first > td").toHaveCount(2, {
11172 message: "should be 2 cells in the one2many in edit mode",
11173 });
11174
11175 await contains(".o_optional_columns_dropdown .dropdown-toggle").click();
11176 expect(".o-dropdown--menu .dropdown-item").toHaveCount(2, {
11177 message: "dropdown have 2 advanced field foo with checked and bar with unchecked",
11178 });
11179 await contains(".o-dropdown--menu .dropdown-item:eq(1)").click();
11180 expect(".o_field_one2many th").toHaveCount(3, {
11181 message: "should be 3 th in the one2many after enabling bar column from advanced dropdown",
11182 });
11183
11184 await contains(".o-dropdown--menu .dropdown-item").click();
11185 expect(".o_field_one2many th").toHaveCount(2, {
11186 message: "should be 2 th in the one2many after disabling foo column from advanced dropdown",
11187 });
11188 expect(".o-dropdown--menu .dropdown-item").toHaveCount(2, {
11189 message: "dropdown is still open",
11190 });
11191
11192 await contains(".o_field_x2many_list_row_add a").click();
11193 expect(".o-dropdown--menu").toHaveCount(0, { message: "dropdown is closed" });
11194 expect(".o_field_one2many tr.o_selected_row").toHaveCount(1);
11195
11196 await contains(".o_optional_columns_dropdown .dropdown-toggle").click();
11197 await contains(".o-dropdown--menu .dropdown-item").click();
11198 expect(".o_field_one2many tr.o_selected_row").toHaveCount(1);
11199 expect(".o_field_one2many th").toHaveCount(3, {
11200 message:
11201 "should be 3 th in the one2many after re-enabling foo column from advanced dropdown",
11202 });
11203
11204 // optional columns must be preserved after save
11205 await clickSave();
11206 expect(".o_field_one2many th").toHaveCount(3, {
11207 message: "should have 3 th in the one2many after reloading whole form view",
11208 });
11209 });
11210
11211 test("x2many list sorted by many2one", async () => {
11212 Partner._records[0].p = [1, 2, 4];
11213
11214 await mountView({
11215 type: "form",
11216 resModel: "partner",
11217 resId: 1,
11218 arch: `
11219 <form>
11220 <field name="p">
11221 <list>
11222 <field name="id"/>
11223 <field name="trululu"/>
11224 </list>
11225 </field>
11226 </form>`,
11227 });
11228
11229 expect(queryAllTexts(".o_data_row .o_list_number")).toEqual(["1", "2", "4"], {
11230 message: "should have correct order initially",
11231 });
11232
11233 await contains(".o_list_renderer thead th:eq(1)").click();
11234
11235 expect(queryAllTexts(".o_data_row .o_list_number")).toEqual(["4", "1", "2"], {
11236 message: "should have correct order (ASC)",
11237 });
11238
11239 await contains(".o_list_renderer thead th:eq(1)").click();
11240
11241 expect(queryAllTexts(".o_data_row .o_list_number")).toEqual(["2", "1", "4"], {
11242 message: "should have correct order (DESC)",
11243 });
11244
11245 await contains(".o_list_renderer thead th:eq(1)").click();
11246
11247 expect(queryAllTexts(".o_data_row .o_list_number")).toEqual(["1", "2", "4"], {
11248 message: "should fall back to initial order",
11249 });
11250 });
11251
11252 test("one2many with extra field from server not in (inline) form", async () => {
11253 await mountView({
11254 type: "form",
11255 resModel: "partner",
11256 resId: 1,
11257 arch: `
11258 <form>
11259 <field name="p">
11260 <list>
11261 <field name="datetime"/>
11262 <field name="name"/>
11263 </list>
11264 <form>
11265 <field name="name"/>
11266 </form>
11267 </field>
11268 </form>`,
11269 });
11270
11271 // Add a record in the list
11272 await contains(".o_field_x2many_list_row_add a").click();
11273 await contains(".o_field_widget[name=name] input").edit("michelangelo", { confirm: false });
11274
11275 // Save the record in the modal (though it is still virtual)
11276 await contains(".modal .modal-footer .btn-primary").click();
11277 expect(".o_data_row").toHaveCount(1);
11278 });
11279
11280 test("one2many with extra X2many field from server not in inline form", async () => {
11281 await mountView({
11282 type: "form",
11283 resModel: "partner",
11284 resId: 1,
11285 arch: `
11286 <form>
11287 <field name="p">
11288 <list>
11289 <field name="turtles"/>
11290 <field name="name"/>
11291 </list>
11292 <form>
11293 <field name="name"/>
11294 </form>
11295 </field>
11296 </form>`,
11297 });
11298
11299 // Add a first record in the list
11300 await contains(".o_field_x2many_list_row_add a").click();
11301 await contains(".modal .o_field_widget[name=name] input").edit("first", { confirm: false });
11302
11303 // Save & New
11304 await contains(".modal .btn-primary:eq(1)").click();
11305 await contains(".modal .o_field_widget[name=name] input").edit("second", { confirm: false });
11306
11307 // Save & Close
11308 await contains(".modal .btn-primary").click();
11309
11310 expect(".o_data_row").toHaveCount(2);
11311 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["first", "second"]);
11312 });
11313
11314 test("when Navigating to a one2many with tabs, the button add a line receives the focus", async () => {
11315 await mountView({
11316 type: "form",
11317 resModel: "partner",
11318 arch: `
11319 <form>
11320 <sheet>
11321 <group>
11322 <field name="qux"/>
11323 </group>
11324 <notebook>
11325 <page string="Partner page">
11326 <field name="turtles">
11327 <list editable="bottom">
11328 <field name="turtle_foo"/>
11329 </list>
11330 </field>
11331 </page>
11332 </notebook>
11333 </sheet>
11334 </form>`,
11335 resId: 1,
11336 });
11337
11338 await contains("[name=qux] input").click();
11339 expect("[name=qux] input").toBeFocused();
11340 // next tabable element is notebook tab
11341 await press("Tab");
11342 // go inside one2many
11343 await press("Tab");
11344 await animationFrame();
11345 expect(".o_field_x2many_list_row_add a").toBeFocused();
11346 });
11347
11348 test("Navigate to a one2many with tab then tab again focus the next field", async () => {
11349 Partner._records[0].turtles = [];
11350
11351 await mountView({
11352 type: "form",
11353 resModel: "partner",
11354 arch: `
11355 <form>
11356 <sheet>
11357 <group>
11358 <field name="qux"/>
11359 </group>
11360 <notebook>
11361 <page string="Partner page">
11362 <field name="turtles">
11363 <list editable="bottom">
11364 <field name="turtle_foo"/>
11365 <field name="turtle_description"/>
11366 </list>
11367 </field>
11368 </page>
11369 </notebook>
11370 <group>
11371 <field name="foo"/>
11372 </group>
11373 </sheet>
11374 </form>`,
11375 resId: 1,
11376 });
11377
11378 await contains("[name=qux] input").click();
11379 expect("[name=qux] input").toBeFocused();
11380 // next tabable element is notebook tab
11381 await press("Tab");
11382 // go inside one2many
11383 await press("Tab");
11384 await animationFrame();
11385
11386 expect(".o_field_x2many_list_row_add a").toBeFocused();
11387 expect("[name=turtles] .o_selected_row").toHaveCount(0);
11388 // trigger Tab event and check that the default behavior can happen.
11389 expect(getNextFocusableElement()).toBe(queryOne("[name=foo] input"));
11390 await press("Tab");
11391 expect("[name=foo] input").toBeFocused();
11392 });
11393
11394 test("when Navigating to a one2many with tabs, not filling any field and hitting tab, no line is added and the next field is focused", async () => {
11395 Partner._records[0].turtles = [];
11396
11397 await mountView({
11398 type: "form",
11399 resModel: "partner",
11400 arch: `
11401 <form>
11402 <sheet>
11403 <group>
11404 <field name="qux"/>
11405 </group>
11406 <notebook>
11407 <page string="Partner page">
11408 <field name="turtles">
11409 <list editable="bottom">
11410 <field name="turtle_foo"/>
11411 <field name="turtle_description"/>
11412 </list>
11413 </field>
11414 </page>
11415 </notebook>
11416 <group>
11417 <field name="foo"/>
11418 </group>
11419 </sheet>
11420 </form>`,
11421 resId: 1,
11422 });
11423
11424 await contains("[name=qux] input").click();
11425 expect("[name=qux] input").toBeFocused();
11426 // next tabable element is notebook tab
11427 await press("Tab");
11428 // go inside one2many
11429 await press("Tab");
11430 await animationFrame();
11431
11432 expect(".o_field_x2many_list_row_add a").toBeFocused();
11433 expect("[name=turtles] .o_selected_row").toHaveCount(0);
11434
11435 await contains(".o_field_x2many_list_row_add a").click();
11436 expect("[name=turtle_foo] input").toBeFocused();
11437
11438 await press("Tab"); // go to turtle_description field
11439 await animationFrame();
11440 expect("[name=turtle_description] textarea").toBeFocused();
11441
11442 expect(getNextFocusableElement()).toBe(queryOne("[name=foo] input"));
11443 // trigger Tab event and check that the default behavior can happen.
11444 await press("Tab");
11445 expect("[name=foo] input").toBeFocused();
11446 });
11447
11448 test("when Navigating to a one2many with tabs, editing in a popup, the popup should receive the focus then give it back", async () => {
11449 Partner._records[0].turtles = [];
11450 await mountView({
11451 type: "form",
11452 resModel: "partner",
11453 arch: `
11454 <form>
11455 <sheet>
11456 <group>
11457 <field name="qux"/>
11458 </group>
11459 <notebook>
11460 <page string="Partner page">
11461 <field name="turtles">
11462 <list>
11463 <field name="turtle_foo"/>
11464 <field name="turtle_description"/>
11465 </list>
11466 <form>
11467 <group>
11468 <field name="turtle_foo"/>
11469 <field name="turtle_int"/>
11470 </group>
11471 </form>
11472 </field>
11473 </page>
11474 </notebook>
11475 <group>
11476 <field name="foo"/>
11477 </group>
11478 </sheet>
11479 </form>`,
11480 resId: 1,
11481 });
11482
11483 await contains("[name=qux] input").click();
11484 expect("[name=qux] input").toBeFocused();
11485 // next tabable element is notebook tab
11486 await press("Tab");
11487 // go inside one2many
11488 await press("Tab");
11489 await animationFrame();
11490 expect(".o_field_x2many_list_row_add a").toBeFocused();
11491
11492 await contains(".o_field_x2many_list_row_add a").click();
11493 expect(".modal [name=turtle_foo] input").toBeFocused();
11494
11495 await press("Escape");
11496 await animationFrame();
11497
11498 expect(".modal").toHaveCount(0);
11499 expect(".o_field_x2many_list_row_add a").toBeFocused();
11500 });
11501
11502 test.tags("desktop");
11503 test("when creating a new many2one on a x2many then discarding it immediately with ESCAPE, it should not crash", async () => {
11504 Partner._records[0].turtles = [];
11505 Partner._views = {
11506 form: `
11507 <form>
11508 <field name="foo"/>
11509 <field name="bar"/>
11510 </form>`,
11511 };
11512 await mountView({
11513 type: "form",
11514 resModel: "partner",
11515 arch: `
11516 <form>
11517 <field name="turtles">
11518 <list editable="top">
11519 <field name="turtle_foo"/>
11520 <field name="turtle_trululu"/>
11521 </list>
11522 </field>
11523 </form>`,
11524 resId: 1,
11525 });
11526
11527 // add a new line
11528 await contains(".o_field_x2many_list_row_add a").click();
11529
11530 expect(".o_selected_row").toHaveCount(1);
11531
11532 await clickFieldDropdown("turtle_trululu");
11533 await contains(".o_field_widget[name=turtle_trululu] input").edit("ABC", {
11534 confirm: false,
11535 });
11536 await runAllTimers();
11537
11538 // Discard input value
11539 press("Escape").then(() => {
11540 // ... then discard record
11541 press("Escape");
11542 });
11543 clickFieldDropdownItem("turtle_trululu", "Create and edit..."); // Open create modal
11544 await animationFrame();
11545 await animationFrame();
11546
11547 expect(".modal").toHaveCount(0);
11548 expect(".o_selected_row").toHaveCount(0);
11549 });
11550
11551 test.tags("desktop");
11552 test("navigating through an editable list with custom controls", async () => {
11553 await mountView({
11554 type: "form",
11555 resModel: "partner",
11556 arch: `
11557 <form>
11558 <field name="name"/>
11559 <field name="p">
11560 <list editable="bottom">
11561 <control>
11562 <create string="Custom 1" context="{'default_foo': '1'}"/>
11563 <create string="Custom 2" context="{'default_foo': '2'}"/>
11564 </control>
11565 <field name="foo"/>
11566 </list>
11567 </field>
11568 <field name="int_field"/>
11569 </form>`,
11570 });
11571
11572 expect("[name=name] input").toBeFocused();
11573
11574 expect("[name=p] .o_selected_row").toHaveCount(0);
11575
11576 // press tab to navigate to the list
11577 expect(getNextFocusableElement()).toBe(queryFirst(".o_field_x2many_list_row_add a"));
11578 await press("Tab");
11579
11580 expect(".o_field_x2many_list_row_add a:eq(0)").toBeFocused();
11581
11582 // press right to focus the second control
11583 await press("ArrowRight");
11584 await animationFrame();
11585
11586 expect(".o_field_x2many_list_row_add a:eq(1)").toBeFocused();
11587
11588 // press left to come back to first control
11589 await press("ArrowLeft");
11590 await animationFrame();
11591
11592 expect(".o_field_x2many_list_row_add a:eq(0)").toBeFocused();
11593 expect(getNextFocusableElement()).toBe(queryOne(".o_field_x2many_list_row_add a:eq(1)"));
11594 await press("Tab");
11595 expect(".o_field_x2many_list_row_add a:eq(1)").toBeFocused();
11596
11597 expect(getNextFocusableElement()).toBe(queryOne("[name=int_field] input"));
11598 await press("Tab");
11599 expect("[name=int_field] input").toBeFocused();
11600 });
11601
11602 test("be able to press a key on the keyboard when focusing a column header without crashing", async () => {
11603 await mountView({
11604 type: "form",
11605 resModel: "partner",
11606 arch: `
11607 <form>
11608 <field name="turtles">
11609 <list editable="bottom">
11610 <field name="turtle_int" />
11611 </list>
11612 </field>
11613 </form>`,
11614 resId: 1,
11615 });
11616 await contains(".o_data_row .o_data_cell").click();
11617 await contains(".o_list_renderer .o_column_sortable").click();
11618 await press("a");
11619 await animationFrame();
11620 expect(".o_data_row").toHaveCount(1);
11621 });
11622
11623 test("Navigate from an invalid but not dirty row", async () => {
11624 Partner._records[0].p = [2, 4];
11625 Partner._records[1].name = ""; // invalid record
11626
11627 await mountView({
11628 type: "form",
11629 resModel: "partner",
11630 arch: /* xml */ `
11631 <form>
11632 <field name="p">
11633 <list editable="bottom">
11634 <field name="name" required="1" />
11635 <field name="int_field" readonly="1" />
11636 </list>
11637 </field>
11638 </form>`,
11639 resId: 1,
11640 });
11641
11642 await contains(".o_data_cell").click(); // edit the first row
11643
11644 expect(".o_data_row.o_selected_row").toHaveCount(1);
11645 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row");
11646
11647 await press("Tab"); // navigate with "Tab" to the second row
11648 await animationFrame();
11649
11650 expect(".o_data_row.o_selected_row").toHaveCount(1);
11651 expect(".o_data_row:eq(1)").toHaveClass("o_selected_row");
11652 expect(".o_invalid_cell").toHaveCount(0);
11653
11654 await contains(".o_data_cell").click(); // come back on first row
11655
11656 expect(".o_data_row.o_selected_row").toHaveCount(1);
11657 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row");
11658 expect(".o_invalid_cell").toHaveCount(0);
11659
11660 await press("Enter"); // try to navigate with "Enter" to the second row
11661 await animationFrame();
11662
11663 expect(".o_data_row.o_selected_row").toHaveCount(1);
11664 expect(".o_data_row:eq(0)").toHaveClass("o_selected_row");
11665 expect(".o_invalid_cell").toHaveCount(1);
11666 });
11667
11668 test.tags("desktop");
11669 test("Check onchange with two consecutive one2one", async () => {
11670 Product._fields.product_partner_ids = fields.One2many({
11671 string: "User",
11672 relation: "partner",
11673 });
11674 Product._records[0].product_partner_ids = [1];
11675 Product._records[1].product_partner_ids = [2];
11676 Turtle._fields.product_ids = fields.One2many({
11677 string: "Product",
11678 relation: "product",
11679 });
11680 Turtle._fields.user_ids = fields.One2many({
11681 string: "Product",
11682 relation: "res.users",
11683 });
11684 Turtle._onChanges = {
11685 turtle_trululu: function (record) {
11686 record.product_ids = [[4, 37]];
11687 record.user_ids = [
11688 [4, 17],
11689 [4, 19],
11690 ];
11691 },
11692 };
11693
11694 await mountView({
11695 type: "form",
11696 resModel: "turtle",
11697 arch: `
11698 <form string="Turtles">
11699 <field string="Product" name="turtle_trululu"/>
11700 <field readonly="1" string="Related field" name="product_ids">
11701 <list>
11702 <field widget="many2many_tags" name="product_partner_ids"/>
11703 </list>
11704 </field>
11705 <field readonly="1" string="Second related field" name="user_ids">
11706 <list>
11707 <field widget="many2many_tags" name="partner_ids"/>
11708 </list>
11709 </field>
11710 </form>`,
11711 resId: 1,
11712 });
11713
11714 await clickFieldDropdown("turtle_trululu");
11715 await press("Enter");
11716 await animationFrame();
11717
11718 expect(
11719 queryAllTexts(
11720 '.o_field_many2many_tags[name="product_partner_ids"] .badge.o_tag_color_0 > .o_tag_badge_text'
11721 )
11722 ).toEqual(["first record"], {
11723 message: "should have the correct value in the many2many tag widget",
11724 });
11725 expect(
11726 queryAllTexts(
11727 '.o_field_many2many_tags[name="partner_ids"] .badge.o_tag_color_0 > .o_tag_badge_text'
11728 )
11729 ).toEqual(["first record", "second record"], {
11730 message: "should have the correct values in the many2many tag widget",
11731 });
11732 });
11733
11734 test("does not crash when you parse a tree arch containing another tree arch", async () => {
11735 await mountView({
11736 type: "form",
11737 resModel: "partner",
11738 arch: `
11739 <form>
11740 <field name="p">
11741 <list>
11742 <field name="turtles">
11743 <list>
11744 <field name="turtle_foo"/>
11745 </list>
11746 </field>
11747 </list>
11748 </field>
11749 </form>`,
11750 resId: 1,
11751 });
11752
11753 expect(".o_list_renderer").toHaveCount(1);
11754 });
11755 test("open a one2many record containing a one2many", async () => {
11756 Partner._views = {
11757 [["form", 5]]: /* xml */ `
11758 <form>
11759 <field name="p" context="{ 'form_view_ref': 1234 }">
11760 <list><field name="name" /></list>
11761 </field>
11762 </form>
11763 `,
11764 [["form", 1234]]: /* xml */ `
11765 <form>
11766 <field name="turtles" >
11767 <list>
11768 <field name="name" />
11769 </list>
11770 </field>
11771 </form>`,
11772 };
11773
11774 patchWithCleanup(browser.localStorage, {
11775 setItem(args) {
11776 if (["optional_fields", "debug_open_view"].some((word) => args.startsWith(word))) {
11777 expect.step(`setItem: ${args}`);
11778 }
11779 },
11780 getItem(args) {
11781 if (["optional_fields", "debug_open_view"].some((word) => args.startsWith(word))) {
11782 expect.step(`getItem: ${args}`);
11783 }
11784 return null;
11785 },
11786 });
11787
11788 const rec = Partner._records.find(({ id }) => id === 2);
11789 rec.p = [1];
11790 await mountView({
11791 type: "form",
11792 resModel: "partner",
11793 resId: 2,
11794 viewId: 5,
11795 });
11796
11797 expect.verifySteps([
11798 "getItem: optional_fields,partner,form,5,p,list,name",
11799 "getItem: debug_open_view,partner,form,5,p,list,name",
11800 ]);
11801
11802 await contains(".o_data_cell").click();
11803 expect(".modal .o_data_row").toHaveCount(1);
11804 expect.verifySteps([
11805 "getItem: optional_fields,partner,form,5,p,list,name",
11806 "getItem: debug_open_view,partner,form,5,p,list,name",
11807 "getItem: optional_fields,partner,form,5,turtles,list,name",
11808 "getItem: debug_open_view,partner,form,5,turtles,list,name",
11809 ]);
11810 });
11811
11812 test("open a one2many record with optional open record displayed", async () => {
11813 Partner._views = {
11814 [["form", false]]: `<form>
11815 <field name="p" context="{ 'form_view_ref': 1234 }">
11816 <list editable="bottom"><field name="name" /></list>
11817 </field>
11818 </form>`,
11819 [["form", 1234]]: `
11820 <form>
11821 <field name="name"/>
11822 </form>`,
11823 [["search", false]]: `<search/>`,
11824 };
11825 let firstLoad = true;
11826
11827 patchWithCleanup(localStorage, {
11828 getItem(key) {
11829 const value = super.getItem(...arguments);
11830 if (key.startsWith("debug_open_view")) {
11831 expect.step(["getItem", key, value]);
11832 }
11833 return value;
11834 },
11835 setItem(key, value) {
11836 if (key.startsWith("debug_open_view")) {
11837 expect.step(["setItem", key, value]);
11838 }
11839 super.setItem(...arguments);
11840 },
11841 });
11842 onRpc("get_views", ({ model, method, kwargs }) => {
11843 if (firstLoad) {
11844 firstLoad = false;
11845 } else {
11846 expect(kwargs.context.form_view_ref).toBe(1234);
11847 expect.step(`${model}.${method}`);
11848 }
11849 });
11850 serverState.debug = "1";
11851 const rec = Partner._records.find(({ id }) => id === 2);
11852 rec.p = [1];
11853
11854 await mountWithCleanup(WebClient);
11855 await getService("action").doAction({
11856 res_model: "partner",
11857 type: "ir.actions.act_window",
11858 views: [[false, "form"]],
11859 res_id: 2,
11860 });
11861
11862 const localStorageKey = "debug_open_view,partner,form,false,p,list,name";
11863 expect.verifySteps([["getItem", localStorageKey, null]]);
11864
11865 expect(`td.o_list_record_open_form_view`).toHaveCount(0);
11866 expect(".o_optional_columns_dropdown").toHaveCount(1);
11867 await contains(".o_optional_columns_dropdown button").click();
11868 expect(".o-dropdown-item:contains('View Button')").toHaveCount(1);
11869 await contains(".o-dropdown-item:contains('View Button')").click();
11870 expect.verifySteps([
11871 ["setItem", localStorageKey, true],
11872 ["getItem", localStorageKey, "true"],
11873 ]);
11874
11875 expect(`td.o_list_record_open_form_view`).toHaveCount(1, {
11876 message: "button to open form view should be present on each rows",
11877 });
11878
11879 await contains(`td.o_list_record_open_form_view`).click();
11880 expect.verifySteps(["partner.get_views"]);
11881 });
11882
11883 test("if there are less than 4 lines in a one2many, empty lines must be displayed to cover the difference.", async () => {
11884 await mountView({
11885 type: "form",
11886 resModel: "partner",
11887 arch: `
11888 <form>
11889 <field name="p">
11890 <list editable="bottom">
11891 <field name="name"/>
11892 </list>
11893 </field>
11894 </form>`,
11895 resId: 1,
11896 });
11897
11898 // Should only contain the "Add a line" line and 3 blank lines
11899 expect(".o_list_renderer tbody tr .o_data_row").toHaveCount(0);
11900 expect(".o_list_renderer tbody tr .o_field_x2many_list_row_add").toHaveCount(1);
11901 expect(".o_list_renderer tbody tr td:eq(0)").toHaveClass("o_field_x2many_list_row_add");
11902 expect(".o_list_renderer tbody tr").toHaveCount(4);
11903
11904 await contains(".o_field_x2many_list_row_add a").click();
11905 // Should only contain a new row, the "Add a line" line and 2 blank lines
11906 expect(".o_list_renderer tbody tr.o_data_row").toHaveCount(1);
11907 expect(".o_list_renderer tbody tr:eq(0)").toHaveClass("o_data_row");
11908 expect(".o_list_renderer tbody tr .o_field_x2many_list_row_add").toHaveCount(1);
11909 expect(".o_list_renderer tbody tr:eq(1) td").toHaveClass("o_field_x2many_list_row_add");
11910 expect(".o_list_renderer tbody tr").toHaveCount(4);
11911 });
11912
11913 test("one2many can delete a new record", async () => {
11914 onRpc("web_save", (args) => {
11915 expect.step("web_save"); // should not happen
11916 });
11917 await mountView({
11918 type: "form",
11919 resModel: "partner",
11920 arch: `
11921 <form>
11922 <field name="p">
11923 <kanban>
11924 <templates>
11925 <t t-name="card">
11926 <field name="foo"/>
11927 </t>
11928 </templates>
11929 </kanban>
11930 <form>
11931 <field name="foo" />
11932 </form>
11933 </field>
11934 </form>`,
11935 resId: 1,
11936 });
11937 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(0);
11938
11939 await contains(".o-kanban-button-new").click();
11940 await contains(".modal .o_form_button_save").click();
11941 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
11942
11943 await contains(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").click();
11944 expect(".modal .o_btn_remove").toHaveCount(1);
11945
11946 await contains(".modal .o_btn_remove").click();
11947 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(0);
11948
11949 await clickSave();
11950 expect.verifySteps([]);
11951 });
11952
11953 test("toggle boolean in o2m with the formView in edition", async () => {
11954 Partner._onChanges = {
11955 turtles: () => {},
11956 };
11957 Turtle._onChanges = {
11958 turtle_bar: () => {},
11959 };
11960 onRpc((args) => {
11961 expect.step(args.method + " " + args.model);
11962 });
11963 await mountView({
11964 type: "form",
11965 resModel: "partner",
11966 arch: `
11967 <form>
11968 <field name="turtles">
11969 <list>
11970 <field name="turtle_bar" widget="boolean_toggle"/>
11971 </list>
11972 </field>
11973 </form>`,
11974 resId: 1,
11975 });
11976 expect.verifySteps(["get_views partner", "web_read partner"]);
11977
11978 await contains(".o_boolean_toggle").click();
11979 expect.verifySteps(["onchange partner"]);
11980 });
11981
11982 test("Boolean toggle in x2many must not be editable if form is not editable", async () => {
11983 Turtle._views = {
11984 [["form", false]]: /* xml */ `
11985 <form>
11986 <field name="turtle_bar" widget="boolean_toggle"/>
11987 <field name="partner_ids">
11988 <list>
11989 <field name="bar" widget="boolean_toggle"/>
11990 </list>
11991 </field>
11992 </form>
11993 `,
11994 };
11995
11996 await mountView({
11997 type: "form",
11998 resModel: "partner",
11999 arch: `
12000 <form edit="0">
12001 <field name="turtles">
12002 <list>
12003 <field name="turtle_bar" widget="boolean_toggle"/>
12004 </list>
12005 </field>
12006 </form>`,
12007 resId: 1,
12008 });
12009
12010 expect(".o_form_renderer").toHaveClass("o_form_readonly");
12011 const booleanToggle = queryOne(
12012 "[name='turtles'] .o_data_row [name='turtle_bar'] .o_boolean_toggle input"
12013 );
12014 expect(booleanToggle).not.toBeEnabled({
12015 message: "The boolean toggle should be disabled when the form is readonly",
12016 });
12017
12018 await contains(".o_data_cell").click();
12019 expect(".modal-dialog").toHaveCount(1);
12020 expect(".o_form_renderer").toHaveClass("o_form_readonly");
12021 const booleanToggleInDialog = queryOne(".modal [name='turtle_bar'] input");
12022 expect(booleanToggleInDialog).not.toBeEnabled({
12023 message:
12024 "The boolean toggle in the form view dialog should be disabled when the main form is readonly",
12025 });
12026 expect(
12027 ".modal [name='partner_ids'] .o_data_row [name='bar'] .o_boolean_toggle input"
12028 ).not.toBeEnabled({
12029 message:
12030 "The boolean toggle in x2m in the form view dialog should be disabled when the main form is readonly",
12031 });
12032 });
12033
12034 test("create a new record with an x2m invisible", async () => {
12035 onRpc("onchange", (args) => {
12036 expect(args.args[3]).toEqual({
12037 display_name: {},
12038 p: {
12039 fields: {
12040 int_field: {},
12041 trululu: {
12042 fields: {
12043 display_name: {},
12044 },
12045 },
12046 },
12047 limit: 40,
12048 },
12049 });
12050 return {
12051 value: {
12052 p: [
12053 [
12054 0,
12055 false,
12056 {
12057 int_field: 4,
12058 trululu: { id: 1, name: "first record" },
12059 },
12060 ],
12061 ],
12062 },
12063 };
12064 });
12065 onRpc((args) => {
12066 expect.step(args.method);
12067 });
12068 onRpc("web_save", (args) => {
12069 const commands = args.args[1].p;
12070 expect(commands).toEqual([[0, commands[0][1], { int_field: 4, trululu: 1 }]]);
12071 expect(args.kwargs.specification).toEqual({
12072 display_name: {},
12073 p: {},
12074 });
12075 });
12076 await mountView({
12077 type: "form",
12078 resModel: "partner",
12079 arch: `
12080 <form>
12081 <field name="p" invisible="1">
12082 <list>
12083 <field name="int_field"/>
12084 <field name="trululu"/>
12085 </list>
12086 </field>
12087 </form>`,
12088 });
12089
12090 expect("[name='p']").toHaveCount(0);
12091 expect.verifySteps(["get_views", "onchange"]);
12092
12093 await contains(".o_form_button_save").click();
12094 expect.verifySteps(["web_save"]);
12095 });
12096
12097 test("edit a record with an x2m invisible", async () => {
12098 onRpc((args) => {
12099 expect.step(`${args.method} ${args.model}`);
12100 });
12101 onRpc("web_read", (args) => {
12102 expect(args.kwargs.specification).toEqual({
12103 display_name: {},
12104 foo: {},
12105 turtles: {},
12106 });
12107 });
12108 onRpc("web_save", (args) => {
12109 expect(args.args[1]).toEqual({
12110 foo: "plop",
12111 });
12112 expect(args.kwargs.specification).toEqual({
12113 display_name: {},
12114 foo: {},
12115 turtles: {},
12116 });
12117 });
12118 await mountView({
12119 type: "form",
12120 resModel: "partner",
12121 arch: `
12122 <form>
12123 <field name="foo"/>
12124 <field name="turtles" invisible="1">
12125 <list>
12126 <field name="turtle_foo"/>
12127 <field name="turtle_int"/>
12128 </list>
12129 </field>
12130 </form>`,
12131 resId: 1,
12132 });
12133
12134 expect("[name='p']").toHaveCount(0);
12135 expect.verifySteps(["get_views partner", "web_read partner"]);
12136
12137 await contains("[name='foo'] input").edit("plop", { confirm: false });
12138 await clickSave();
12139 expect.verifySteps(["web_save partner"]);
12140 });
12141
12142 test("can't select a record in a one2many", async () => {
12143 await mountView({
12144 type: "form",
12145 resModel: "partner",
12146 arch: `
12147 <form>
12148 <field name="turtles">
12149 <list>
12150 <field name="name"/>
12151 </list>
12152 </field>
12153 </form>`,
12154 resId: 1,
12155 });
12156 await contains(".o_data_row").click();
12157 expect(".o_data_row_selected").toHaveCount(0);
12158 });
12159
12160 test("save a record after creating and editing a new invalid record in a one2many", async () => {
12161 await mountView({
12162 type: "form",
12163 resModel: "partner",
12164 arch: `
12165 <form>
12166 <field name="p">
12167 <list editable="bottom">
12168 <field name="name" required="1"/>
12169 <field name="int_field"/>
12170 </list>
12171 </field>
12172 </form>`,
12173 resId: 1,
12174 });
12175
12176 await contains(".o_field_x2many_list_row_add a").click();
12177 await contains(".o_field_widget[name=int_field] input").edit("3", { confirm: false });
12178 await clickSave();
12179 expect(".o_data_row.o_selected_row").toHaveCount(1, {
12180 message: "line should not have been removed and should still be in edition",
12181 });
12182 expect(".o_field_widget[name=name]").toHaveClass("o_field_invalid");
12183 });
12184
12185 test("nested one2manys, multi page, onchange", async () => {
12186 Partner._records[2].int_field = 5;
12187 Partner._records[0].p = [2, 4]; // limit 1 -> record 4 will be on second page
12188 Partner._records[1].turtles = [1];
12189 Partner._records[2].turtles = [2];
12190 Turtle._records[0].turtle_int = 1;
12191 Turtle._records[1].turtle_int = 2;
12192
12193 Partner._onChanges.int_field = function (obj) {
12194 expect.step("onchange");
12195 obj.p = [[5]];
12196 obj.p.push([1, 2, { turtles: [[5], [1, 1, { turtle_int: obj.int_field }]] }]);
12197 obj.p.push([1, 4, { turtles: [[5], [1, 2, { turtle_int: obj.int_field }]] }]);
12198 };
12199
12200 await mountView({
12201 type: "form",
12202 resModel: "partner",
12203 arch: `
12204 <form>
12205 <field name="int_field"/>
12206 <field name="p">
12207 <list editable="bottom" limit="1" default_order="name">
12208 <field name="name" />
12209 <field name="int_field" />
12210 <field name="turtles">
12211 <list editable="bottom">
12212 <field name="turtle_int"/>
12213 </list>
12214 </field>
12215 </list>
12216 </field>
12217 </form>`,
12218 resId: 1,
12219 });
12220
12221 await contains(".o_field_widget[name=int_field] input").edit("5", { confirm: "blur" });
12222 expect.verifySteps(["onchange"]);
12223
12224 await clickSave();
12225
12226 expect(MockServer.env["partner"][0].int_field).toBe(5);
12227 expect(MockServer.env["turtle"][1].turtle_int).toBe(5);
12228 expect(MockServer.env["turtle"][0].turtle_int).toBe(5);
12229 });
12230
12231 test("multi page, command forget for record of second page", async () => {
12232 Partner._records[0].p = [1, 2, 4];
12233 Partner._onChanges = {
12234 int_field: function (obj) {
12235 obj.p = [[3, 4]];
12236 },
12237 };
12238 await mountView({
12239 type: "form",
12240 resModel: "partner",
12241 arch: `
12242 <form>
12243 <group>
12244 <field name="int_field"/>
12245 <field name="p">
12246 <list limit="2">
12247 <field name="name"/>
12248 </list>
12249 </field>
12250 </group>
12251 </form>`,
12252 resId: 1,
12253 });
12254
12255 expect("[name=int_field] input").toHaveValue("10");
12256 expect(".o_data_row").toHaveCount(2);
12257 expect(queryAllTexts(".o_data_cell")).toEqual(["first record", "second record"]);
12258
12259 // trigger the onchange
12260 await contains("[name=int_field] input").edit("16", { confirm: "blur" });
12261 expect(".o_data_row").toHaveCount(2);
12262 expect(queryAllTexts(".o_data_cell")).toEqual(["first record", "second record"]);
12263 expect(".o_x2m_control_panel .o_pager").toHaveCount(0);
12264 });
12265
12266 test.tags("desktop");
12267 test("multi page, command forget for record of second page on desktop", async () => {
12268 Partner._records[0].p = [1, 2, 4];
12269 Partner._onChanges = {
12270 int_field: function (obj) {
12271 obj.p = [[3, 4]];
12272 },
12273 };
12274 await mountView({
12275 type: "form",
12276 resModel: "partner",
12277 arch: `
12278 <form>
12279 <group>
12280 <field name="int_field"/>
12281 <field name="p">
12282 <list limit="2">
12283 <field name="name"/>
12284 </list>
12285 </field>
12286 </group>
12287 </form>`,
12288 resId: 1,
12289 });
12290
12291 expect(".o_x2m_control_panel .o_pager_counter").toHaveText("1-2 / 3");
12292
12293 // trigger the onchange
12294 await contains("[name=int_field] input").edit("16", { confirm: "blur" });
12295 expect(".o_x2m_control_panel .o_pager_counter").toHaveCount(0);
12296 });
12297
12298 test("new record, receive more create commands than limit", async () => {
12299 Partner._fields.sequence = fields.Integer();
12300 Partner._onChanges = {
12301 p: function (obj) {
12302 obj.p = [
12303 [0, 0, { sequence: 1, display_name: "Record 1" }],
12304 [0, 0, { sequence: 2, display_name: "Record 2" }],
12305 [0, 0, { sequence: 3, display_name: "Record 3" }],
12306 [0, 0, { sequence: 4, display_name: "Record 4" }],
12307 ];
12308 },
12309 };
12310 await mountView({
12311 type: "form",
12312 resModel: "partner",
12313 arch: `
12314 <form>
12315 <group>
12316 <field name="p">
12317 <list limit="2">
12318 <field name="sequence"/>
12319 <field name="display_name"/>
12320 </list>
12321 </field>
12322 </group>
12323 </form>`,
12324 });
12325
12326 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual([
12327 "Record 1",
12328 "Record 2",
12329 "Record 3",
12330 "Record 4",
12331 ]);
12332 expect(".o_x2m_control_panel .o_pager").toHaveCount(0);
12333 });
12334
12335 test("active actions are passed to o2m field", async () => {
12336 Partner._records[0].turtles = [1, 2, 3];
12337
12338 await mountView({
12339 type: "form",
12340 resModel: "partner",
12341 arch: /* xml */ `
12342 <form>
12343 <field name="turtles">
12344 <list editable="bottom" create="false" delete="false">
12345 <field name="name" />
12346 <field name="turtle_foo" />
12347 </list>
12348 </field>
12349 </form>`,
12350 resId: 1,
12351 });
12352
12353 expect(".o_data_row").toHaveCount(3);
12354 expect(".o_list_record_remove").toHaveCount(0);
12355
12356 await contains(".o_data_row:eq(2) .o_data_cell:eq(1)").click();
12357
12358 expect(".o_data_row:eq(2)").toHaveClass("o_selected_row");
12359
12360 await press("Enter");
12361 await animationFrame();
12362
12363 expect(".o_data_row").toHaveCount(3);
12364 expect(".o_list_record_remove").toHaveCount(0);
12365 expect(".o_data_row:first-child").toHaveClass("o_selected_row");
12366 });
12367
12368 test("kanban one2many in opened view form", async () => {
12369 Partner._records[0].p = [1];
12370 await mountView({
12371 type: "form",
12372 resModel: "partner",
12373 arch: /* xml */ `
12374 <form>
12375 <field name="p">
12376 <list>
12377 <field name="name"/>
12378 </list>
12379 <form>
12380 <field name="p">
12381 <kanban class="o-custom-class" can_open="0">
12382 <templates>
12383 <t t-name="card">
12384 <field name="name"/>
12385 </t>
12386 </templates>
12387 </kanban>
12388 </field>
12389 </form>
12390 </field>
12391 </form>`,
12392 resId: 1,
12393 });
12394 await contains(".o_data_row td[name=name]").click();
12395 expect(".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
12396 expect(".modal .o_field_x2many_kanban").toHaveClass("o-custom-class");
12397
12398 await contains(
12399 ".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)"
12400 ).click();
12401 expect(".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toBeFocused();
12402
12403 await press("ArrowUp");
12404 await animationFrame();
12405
12406 expect(".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
12407 });
12408
12409 test("kanban one2many in opened view form (with _view_ref)", async () => {
12410 Partner._views = {
12411 [["kanban", 1234]]: /* xml */ `
12412 <kanban class="o-custom-class" can_open="0">
12413 <templates>
12414 <t t-name="card">
12415 <field name="name"/>
12416 </t>
12417 </templates>
12418 </kanban>
12419 `,
12420 };
12421 Partner._records[0].p = [1];
12422 await mountView({
12423 type: "form",
12424 resModel: "partner",
12425 arch: /* xml */ `
12426 <form>
12427 <field name="p">
12428 <list>
12429 <field name="name"/>
12430 </list>
12431 <form>
12432 <field name="p" mode="kanban" context="{ 'kanban_view_ref': 1234 }" />
12433 </form>
12434 </field>
12435 </form>`,
12436 resId: 1,
12437 });
12438 await contains(".o_data_row td[name=name]").click();
12439 expect(".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
12440 expect(".modal .o_field_x2many_kanban").toHaveClass("o-custom-class");
12441
12442 await contains(
12443 ".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)"
12444 ).click();
12445 expect(".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toBeFocused();
12446
12447 await press("ArrowUp");
12448 await animationFrame();
12449
12450 expect(".modal .o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
12451 });
12452
12453 test("kanban one2many (with widget) in opened view form", async () => {
12454 Partner._records[0].p = [1];
12455 await mountView({
12456 type: "form",
12457 resModel: "partner",
12458 arch: /* xml */ `
12459 <form>
12460 <field name="p">
12461 <kanban>
12462 <templates>
12463 <t t-name="card">
12464 <field name="name" widget="char"/>
12465 </t>
12466 </templates>
12467 </kanban>
12468 <form>
12469 <field name="name"/>
12470 </form>
12471 </field>
12472 </form>`,
12473 resId: 1,
12474 });
12475
12476 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(1);
12477 expect(".o_kanban_record:eq(0)").toHaveText("first record");
12478
12479 await contains(".o_kanban_record").click();
12480 expect(".o_dialog .o_form_view .o_field_widget[name=name]").toHaveCount(1);
12481 expect(".o_dialog .o_form_view .o_field_widget[name=name] input").toHaveValue("first record");
12482 expect(".o_kanban_record:eq(0)").toHaveText("first record");
12483
12484 await contains(".o_dialog .o_form_view .o_field_widget[name=name] input").edit("test", {
12485 confirm: "blur",
12486 });
12487 expect(".o_kanban_record:eq(0)").toHaveText("test");
12488 });
12489
12490 test.tags("desktop");
12491 test("list one2many in opened view form", async () => {
12492 Partner._records[0].p = [1];
12493 await mountView({
12494 type: "form",
12495 resModel: "partner",
12496 arch: /* xml */ `
12497 <form>
12498 <field name="p">
12499 <list>
12500 <field name="name"/>
12501 </list>
12502 <form>
12503 <field name="p">
12504 <list editable="bottom" class="o-custom-class">
12505 <field name="name"/>
12506 </list>
12507 </field>
12508 </form>
12509 </field>
12510 </form>`,
12511 resId: 1,
12512 });
12513 await contains(".o_data_row td[name=name]").click();
12514 expect(".modal .o_data_row td[name=name]").toHaveCount(1);
12515 expect(".modal .o_field_x2many_list").toHaveClass("o-custom-class");
12516
12517 await contains(".modal thead th[data-name=name]").click();
12518 expect(".modal thead th[data-name=name]").toBeFocused();
12519
12520 await press("ArrowUp");
12521 await animationFrame();
12522
12523 expect(".modal .o_data_row td[name=name]").toHaveCount(1);
12524 });
12525
12526 test.tags("desktop");
12527 test("list one2many in opened view form (with _view_ref)", async () => {
12528 Partner._views = {
12529 [["list", 1234]]: /* xml */ `
12530 <list editable="bottom" class="o-custom-class">
12531 <field name="name"/>
12532 </list>
12533 `,
12534 };
12535 Partner._records[0].p = [1];
12536 await mountView({
12537 type: "form",
12538 resModel: "partner",
12539 arch: /* xml */ `
12540 <form>
12541 <field name="p">
12542 <list>
12543 <field name="name"/>
12544 </list>
12545 <form>
12546 <field name="p" mode="list" context="{ 'list_view_ref': 1234 }" />
12547 </form>
12548 </field>
12549 </form>`,
12550 resId: 1,
12551 });
12552 await contains(".o_data_row td[name=name]").click();
12553 expect(".modal .o_data_row td[name=name]").toHaveCount(1);
12554 expect(".modal .o_field_x2many_list").toHaveClass("o-custom-class");
12555
12556 await contains(".modal thead th[data-name=name]").click();
12557 expect(".modal thead th[data-name=name]").toBeFocused();
12558
12559 await press("ArrowUp");
12560 await animationFrame();
12561
12562 expect(".modal .o_data_row td[name=name]").toHaveCount(1);
12563 });
12564
12565 test.tags("desktop");
12566 test("one2many, form view dialog with custom footer", async () => {
12567 Partner._records[0].p = [1];
12568
12569 await mountView({
12570 type: "form",
12571 resModel: "partner",
12572 arch: `
12573 <form>
12574 <field name="p">
12575 <list>
12576 <field name="name"/>
12577 </list>
12578 <form>
12579 <field name="name"/>
12580 <footer>
12581 <span class="my_span">Hello</span>
12582 </footer>
12583 </form>
12584 </field>
12585 </form>`,
12586 resId: 1,
12587 });
12588
12589 await contains(".o_data_row td[name=name]").click();
12590 expect(".modal-footer .my_span").toHaveCount(1);
12591
12592 await contains(".modal-header .btn-close").click();
12593 expect(".modal").toHaveCount(0);
12594
12595 // open it again
12596 await contains(".o_data_row td[name=name]").click();
12597 expect(".modal-footer button").toHaveCount(0);
12598 expect(".modal-footer .my_span").toHaveCount(1);
12599 });
12600
12601 test.tags("desktop");
12602 test("one2many, form view dialog with added custom footer (replace='0')", async () => {
12603 Partner._records[0].p = [1];
12604
12605 await mountView({
12606 type: "form",
12607 resModel: "partner",
12608 arch: `
12609 <form>
12610 <field name="p">
12611 <list>
12612 <field name="name"/>
12613 </list>
12614 <form>
12615 <field name="name"/>
12616 <footer replace="0">
12617 <button class="btn btn-primary my_button">Hello</button>
12618 </footer>
12619 </form>
12620 </field>
12621 </form>`,
12622 resId: 1,
12623 });
12624
12625 await contains(".o_data_row td[name=name]").click();
12626 expect(".modal-footer .my_button").toHaveCount(1);
12627 expect(".modal-footer button").toHaveCount(3);
12628
12629 await contains(".modal-header .btn-close").click();
12630 expect(".modal").toHaveCount(0);
12631
12632 // open it again
12633 await contains(".o_data_row td[name=name]").click();
12634 expect(".modal-footer .my_button").toHaveCount(1);
12635 expect(".modal-footer button").toHaveCount(3);
12636 });
12637
12638 test('Add a line, click on "Save & New" with an invalid form', async () => {
12639 mockService("notification", {
12640 add: (message, params) => {
12641 expect.step(params.type);
12642 expect(message).toBe("Missing required fields");
12643 },
12644 });
12645 await mountView({
12646 type: "form",
12647 resModel: "partner",
12648 arch: `
12649 <form>
12650 <field name="p">
12651 <list>
12652 <field name="name"/>
12653 </list>
12654 <form>
12655 <field name="name" required="1"/>
12656 </form>
12657 </field>
12658 </form>`,
12659 });
12660
12661 expect(".o_data_row").toHaveCount(0);
12662 // Add a new record
12663 await contains(".o_field_x2many_list_row_add a").click();
12664 expect(".o_dialog .o_form_view").toHaveCount(1);
12665
12666 // Click on "Save & New" with an invalid form
12667 await contains(".o_dialog .o_form_button_save_new").click();
12668 expect(".o_dialog .o_form_view").toHaveCount(1);
12669 expect.verifySteps(["danger"]);
12670
12671 // Check that no buttons are disabled
12672 expect(".o_dialog .o_form_button_save_new").toBeEnabled();
12673 expect(".o_dialog .o_form_button_cancel").toBeEnabled();
12674 });
12675
12676 test("field in list but not in fetched form", async () => {
12677 Partner._fields.o2m = fields.One2many({
12678 relation: "partner.type",
12679 relation_field: "p_id",
12680 });
12681 PartnerType._onChanges = {
12682 name: (rec) => {
12683 if (rec.name === "changed") {
12684 rec.color = 5;
12685 }
12686 },
12687 };
12688
12689 PartnerType._fields.p_id = fields.Many2one({ relation: "partner" });
12690 PartnerType._views = { form: `<form><field name="name" /></form>` };
12691 onRpc((args) => {
12692 expect.step(`${args.method}: ${args.model}`);
12693 });
12694 await mountView({
12695 type: "form",
12696 resModel: "partner",
12697 arch: `
12698 <form>
12699 <field name="o2m">
12700 <list>
12701 <field name="name"/>
12702 <field name="color" />
12703 </list>
12704 </field>
12705 </form>`,
12706 });
12707
12708 expect.verifySteps(["get_views: partner", "onchange: partner"]);
12709 await contains(".o_field_x2many_list_row_add a").click();
12710 expect.verifySteps(["get_views: partner.type", "onchange: partner.type"]);
12711 await contains(".modal .o_field_widget[name='name'] input").edit("changed", {
12712 confirm: "blur",
12713 });
12714 expect.verifySteps(["onchange: partner.type"]);
12715 await contains(".modal .o_form_button_save").click();
12716 expect(".o_data_row").toHaveText("changed 5");
12717 await contains(".o_form_button_save").click();
12718 expect.verifySteps(["web_save: partner"]);
12719 expect(".o_data_row").toHaveText("changed 5");
12720 });
12721
12722 test("pressing tab before an onchange is resolved", async () => {
12723 const onchangeGetPromise = new Deferred();
12724
12725 Partner._onChanges = {
12726 name: (obj) => {
12727 obj.name = "test";
12728 },
12729 };
12730 onRpc("product", "onchange", async (args) => {
12731 if (args.args[2] === "name") {
12732 await onchangeGetPromise;
12733 }
12734 });
12735 await mountView({
12736 type: "form",
12737 resModel: "partner",
12738 arch: `
12739 <form>
12740 <field name="p">
12741 <list editable="bottom" >
12742 <field name="name"/>
12743 </list>
12744 </field>
12745 </form>`,
12746 resId: 1,
12747 });
12748
12749 await contains(".o_field_x2many_list_row_add a").click();
12750 // This is not how it should happen but non trusted event listeners are called sooner than
12751 // trusted ones so the update is called after the list's tab listener in which case the field is
12752 // not dirty when we press tab, therefore we need to set it dirty through onChange before pressing tab
12753 // so in practice we could only run the following line but it wont work since the tab keydown event is not trusted
12754 // await contains(".o_field_widget[name='name'] input").edit("gold", { confirm: false });
12755 await contains(".o_field_widget[name='name'] input").edit("gold", { confirm: "blur" });
12756 await contains(".o_data_cell[name='name']").click(); // focus the input again
12757
12758 await press("Tab");
12759 onchangeGetPromise.resolve();
12760 await animationFrame();
12761
12762 expect(".o_data_row").toHaveCount(2);
12763 });
12764
12765 test("add a row to an x2many and ask canBeRemoved twice", async () => {
12766 // This test simulates that the view is asked twice to save its changes because the user
12767 // is leaving. Before the corresponding fix, the changes in the x2many field weren't
12768 // removed after the save, and as a consequence they were saved twice (i.e. the row was
12769 // created twice).
12770
12771 const def = new Deferred();
12772 Partner._views = {
12773 list: `<list><field name="int_field"/></list>`,
12774 form: `
12775 <form>
12776 <field name="p">
12777 <list editable="bottom">
12778 <field name="name"/>
12779 </list>
12780 </field>
12781 </form>`,
12782 };
12783
12784 onRpc("web_save", (args) => {
12785 expect.step("web_save");
12786 expect(args.args[1]).toEqual({
12787 p: [[0, args.args[1].p[0][1], { name: "a name" }]],
12788 });
12789 });
12790 onRpc("web_search_read", () => def);
12791
12792 const actions = [
12793 {
12794 id: 1,
12795 name: "test",
12796 res_model: "partner",
12797 res_id: 1,
12798 type: "ir.actions.act_window",
12799 views: [[false, "form"]],
12800 },
12801 {
12802 id: 2,
12803 name: "another action",
12804 res_model: "partner",
12805 type: "ir.actions.act_window",
12806 views: [[false, "list"]],
12807 },
12808 ];
12809
12810 await mountWithCleanup(WebClient);
12811 await getService("action").doAction(actions[0]);
12812 expect(".o_form_view").toHaveCount(1);
12813
12814 // add a row in the x2many
12815 await contains(".o_field_x2many_list_row_add a").click();
12816 await contains(".o_field_widget[name=name] input").edit("a name", { confirm: false });
12817 expect(".o_data_row").toHaveCount(1);
12818
12819 getService("action").doAction(actions[1]);
12820 await animationFrame();
12821 getService("action").doAction(actions[1]);
12822 await animationFrame();
12823 expect.verifySteps(["web_save"]);
12824
12825 def.resolve();
12826 await animationFrame();
12827 expect(".o_list_view").toHaveCount(1);
12828 expect.verifySteps([]);
12829 });
12830
12831 test("one2many: save a record before the onchange is complete in a form dialog", async () => {
12832 Turtle._onChanges = {
12833 name: function () {},
12834 };
12835
12836 Turtle._views = {
12837 form: `
12838 <form>
12839 <field name="name"/>
12840 </form>`,
12841 };
12842
12843 const def = new Deferred();
12844 onRpc("onchange", async (args) => {
12845 if (args.args[2].length === 1 && args.args[2][0] === "name") {
12846 await def;
12847 }
12848 });
12849 await mountView({
12850 type: "form",
12851 resModel: "partner",
12852 resId: 1,
12853 arch: `
12854 <form>
12855 <field name="turtles">
12856 <list>
12857 <field name="name" required="1"/>
12858 </list>
12859 </field>
12860 </form>`,
12861 });
12862 await contains(".o_field_x2many_list_row_add a").click();
12863 expect(".modal").toHaveCount(1);
12864
12865 await contains(".o_field_widget[name=name] input").edit("new name", { confirm: false });
12866 await contains(".modal .o_form_button_save").click();
12867 expect(".modal").toHaveCount(1);
12868
12869 def.resolve();
12870 await animationFrame();
12871 expect(".modal").toHaveCount(0);
12872 expect(".o_data_row").toHaveCount(2);
12873 expect(queryAllTexts(".o_data_row [name='name']")).toEqual(["donatello", "new name"]);
12874 });
12875
12876 test("onchange create a record in an invisible x2many", async () => {
12877 Partner._onChanges = {
12878 foo: function () {},
12879 };
12880 Partner._records[0].p = [2];
12881 onRpc("onchange", () => ({
12882 value: {
12883 p: [
12884 [
12885 1,
12886 2,
12887 {
12888 name: "plop",
12889 p: [[0, false, {}]],
12890 },
12891 ],
12892 ],
12893 },
12894 }));
12895 await mountView({
12896 type: "form",
12897 resModel: "partner",
12898 resId: 1,
12899 arch: `
12900 <form>
12901 <field name="foo"/>
12902 <field name="p">
12903 <list>
12904 <field name="name" required="1"/>
12905 <field name="p" invisible="1"/>
12906 </list>
12907 </field>
12908 </form>`,
12909 });
12910 expect(queryAllTexts(".o_data_row")).toEqual(["second record"]);
12911
12912 await contains(".o_field_widget[name=foo] input").edit("new foo value", { confirm: "blur" });
12913 expect(queryAllTexts(".o_data_row")).toEqual(["plop"]);
12914 });
12915
12916 test("forget command for nested x2manys in form, not in list", async () => {
12917 expect.assertions(8);
12918
12919 Partner._records[0].p = [1, 2];
12920 Partner._records[1].turtles = [2];
12921 Partner._onChanges = {
12922 int_field: function (obj) {
12923 obj.p = [
12924 [
12925 1,
12926 1,
12927 {
12928 foo: "new foo value (1)",
12929 turtles: [
12930 [
12931 1,
12932 2,
12933 {
12934 turtle_foo: "new turtle foo value (1)",
12935 partner_ids: [[3, 4]],
12936 },
12937 ],
12938 ],
12939 },
12940 ],
12941 [
12942 1,
12943 2,
12944 {
12945 foo: "new foo value (2)",
12946 turtles: [
12947 [
12948 1,
12949 2,
12950 {
12951 turtle_foo: "new turtle foo value (2)",
12952 partner_ids: [[3, 2]],
12953 },
12954 ],
12955 ],
12956 },
12957 ],
12958 ];
12959 },
12960 };
12961 onRpc("web_save", (args) => {
12962 expect(args.args[1]).toEqual({
12963 int_field: 16,
12964 p: [
12965 [
12966 1,
12967 1,
12968 {
12969 foo: "new foo value (1)",
12970 turtles: [
12971 [
12972 1,
12973 2,
12974 {
12975 turtle_foo: "new turtle foo value (1)",
12976 partner_ids: [[3, 4]],
12977 },
12978 ],
12979 ],
12980 },
12981 ],
12982 [
12983 1,
12984 2,
12985 {
12986 foo: "new foo value (2)",
12987 turtles: [
12988 [
12989 1,
12990 2,
12991 {
12992 turtle_foo: "new turtle foo value (2)",
12993 partner_ids: [[3, 2]],
12994 },
12995 ],
12996 ],
12997 },
12998 ],
12999 ],
13000 });
13001 });
13002 await mountView({
13003 type: "form",
13004 resModel: "partner",
13005 arch: `
13006 <form>
13007 <group>
13008 <field name="int_field"/>
13009 <field name="p">
13010 <list>
13011 <field name="foo"/>
13012 </list>
13013 <form>
13014 <field name="turtles">
13015 <list editable="bottom">
13016 <field name="turtle_foo"/>
13017 <field name="partner_ids" widget="many2many_tags"/>
13018 </list>
13019 </field>
13020 </form>
13021 </field>
13022 </group>
13023 </form>`,
13024 resId: 1,
13025 });
13026
13027 expect("[name=int_field] input").toHaveValue("10");
13028
13029 // trigger the onchange
13030 await contains("[name=int_field] input").edit("16", { confirm: "blur" });
13031 expect("[name=foo]:eq(0)").toHaveText("new foo value (1)");
13032 expect("[name=foo]:eq(1)").toHaveText("new foo value (2)");
13033
13034 // open the second x2many record
13035 await contains(".o_data_row:eq(1) td").click();
13036 expect(".o_dialog .o_data_row").toHaveCount(1);
13037 expect(".o_dialog .o_data_cell[name=turtle_foo]").toHaveText("new turtle foo value (2)");
13038 expect(".o_dialog .o_data_cell[name=partner_ids] .o_tag").toHaveCount(1);
13039 expect(".o_dialog .o_data_cell[name=partner_ids] .o_tag").toHaveText("aaa");
13040
13041 await contains(".o_dialog .o_form_button_save").click();
13042 await clickSave();
13043 });
13044
13045 test("modifiers based on x2many", async () => {
13046 await mountView({
13047 type: "form",
13048 resModel: "partner",
13049 arch: `
13050 <form>
13051 <field name="p" >
13052 <list editable="bottom">
13053 <field name="foo"/>
13054 </list>
13055 </field>
13056 <field name="name" readonly="p"/>
13057 <field name="int_field" required="p"/>
13058 <button name="abc" string="Do it" class="my_button" invisible="not p"/>
13059 </form>`,
13060 resId: 1,
13061 });
13062 expect("button.my_button").toHaveCount(0);
13063 expect("[name='name'].o_readonly_modifier").toHaveCount(0);
13064 expect("[name='int_field'].o_required_modifier").toHaveCount(0);
13065
13066 await contains(".o_field_x2many_list_row_add a").click();
13067 await contains("[name='foo'] input").edit("Test", { confirm: false });
13068 expect("button.my_button").toHaveCount(1);
13069 expect("[name='name'].o_readonly_modifier").toHaveCount(1);
13070 expect("[name='int_field'].o_required_modifier").toHaveCount(1);
13071
13072 await contains("button.fa-trash-o").click();
13073 expect("button.my_button").toHaveCount(0);
13074 expect("[name='name'].o_readonly_modifier").toHaveCount(0);
13075 expect("[name='int_field'].o_required_modifier").toHaveCount(0);
13076 });
13077
13078 test.tags("desktop");
13079 test("add record in nested x2many with context depending on parent", async () => {
13080 expect.assertions(1);
13081
13082 Partner._records[0].p = [1];
13083 onRpc("turtle", "web_read", (args) => {
13084 expect(args.kwargs.context).toEqual({
13085 allowed_company_ids: [1],
13086 bin_size: true,
13087 lang: "en",
13088 tz: "taht",
13089 uid: 7,
13090 x: 10,
13091 y: 2,
13092 });
13093 });
13094 await mountView({
13095 type: "form",
13096 resModel: "partner",
13097 arch: `
13098 <form>
13099 <field name="int_field"/>
13100 <field name="p">
13101 <list editable="top">
13102 <field name="turtles" widget="many2many_tags" context="{'x': parent.int_field, 'y': 2}"/>
13103 </list>
13104 </field>
13105 </form>`,
13106 resId: 1,
13107 });
13108
13109 await contains(".o_data_cell").click();
13110 await contains("div[name=turtles] .o-autocomplete.dropdown input").click();
13111 await contains(".o-autocomplete--dropdown-menu li a").click();
13112 });
13113
13114 test("one2many with default_order on id, but id not in view", async () => {
13115 Partner._records[0].turtles = [1, 2, 3];
13116 onRpc((args) => {
13117 expect.step(args.method);
13118 });
13119 onRpc("web_save", (args) => {
13120 expect(args.args[1].turtles).toEqual([
13121 [1, 3, { turtle_int: 0 }],
13122 [1, 1, { turtle_int: 1 }],
13123 [1, 2, { turtle_int: 2 }],
13124 ]);
13125 });
13126 await mountView({
13127 type: "form",
13128 resModel: "partner",
13129 arch: `
13130 <form>
13131 <field name="turtles">
13132 <list editable="top" default_order="turtle_int,id">
13133 <field name="turtle_int" widget="handle"/>
13134 <field name="turtle_foo"/>
13135 </list>
13136 </field>
13137 </form>`,
13138 resId: 1,
13139 });
13140
13141 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["yop", "blip", "kawa"]);
13142
13143 // drag the third record to top of the list
13144 await contains("tbody tr:eq(2) .o_handle_cell").dragAndDrop("tbody tr");
13145 await clickSave();
13146
13147 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["kawa", "yop", "blip"]);
13148 expect.verifySteps(["get_views", "web_read", "web_save"]);
13149 });
13150
13151 test("one2many causes an onchange on the parent which fails", async () => {
13152 Partner._onChanges = {
13153 turtles: function () {},
13154 };
13155 onRpc("partner", "onchange", () => {
13156 throw makeServerError();
13157 });
13158 await mountView({
13159 type: "form",
13160 resModel: "partner",
13161 arch: `
13162 <form>
13163 <field name="turtles">
13164 <list editable="top">
13165 <field name="turtle_foo"/>
13166 </list>
13167 </field>
13168 </form>`,
13169 resId: 1,
13170 });
13171
13172 await contains(".o_data_cell").click();
13173 expect(".o_field_widget[name='turtle_foo'] input").toHaveValue("blip");
13174
13175 // onchange on parent record fails
13176 expect.errors(1);
13177 await contains(".o_field_widget[name='turtle_foo'] input").edit("new value", {
13178 confirm: "blur",
13179 });
13180 await animationFrame();
13181 expect.verifyErrors(["RPC_ERROR"]);
13182 expect(".o_data_cell[name='turtle_foo']").toHaveText("blip");
13183 expect(".o_error_dialog").toHaveCount(1);
13184 });
13185
13186 test.tags("desktop");
13187 test("one2many custom which can be edited in dialog or on the line", async () => {
13188 const customState = reactive({ isEditable: false });
13189 class CustomX2manyField extends X2ManyField {
13190 setup() {
13191 super.setup();
13192 this.canOpenRecord = true;
13193 this.customState = useState(customState);
13194 }
13195
13196 get rendererProps() {
13197 const props = super.rendererProps;
13198 props.editable = this.customState.isEditable;
13199 return props;
13200 }
13201 }
13202
13203 const customX2ManyField = {
13204 ...x2ManyField,
13205 component: CustomX2manyField,
13206 };
13207 registry.category("fields").add("custom", customX2ManyField);
13208
13209 await mountView({
13210 type: "form",
13211 resModel: "partner",
13212 arch: `
13213 <form>
13214 <field name="turtles" widget="custom">
13215 <list editable="top">
13216 <field name="turtle_foo"/>
13217 </list>
13218 <form>
13219 <field name="name" />
13220 </form>
13221 </field>
13222 </form>`,
13223 resId: 1,
13224 });
13225 expect(".o_form_status_indicator_buttons.invisible").toHaveCount(1, {
13226 message: "form view is not dirty",
13227 });
13228
13229 await contains(".o_data_cell").click();
13230 expect(".modal").toHaveCount(1);
13231
13232 customState.isEditable = true;
13233 await contains(".modal .btn-close").click();
13234 expect(".o_form_status_indicator_buttons.invisible").toHaveCount(1, {
13235 message: "form view is not dirty",
13236 });
13237
13238 await contains(".o_data_cell").click();
13239 await contains("[name='turtle_foo'] input").edit("new value", { confirm: false });
13240 expect(".o_form_status_indicator_buttons:not(.invisible)").toHaveCount(1, {
13241 message: "form view is dirty",
13242 });
13243 });
13244
13245 test("x2many kanban with float field in form (non inline) but not in kanban", async () => {
13246 // In this test, the form view contains an extra float field and isn't inline. When we open
13247 // a record, we add the form fields to the list of activeFields, and we load the
13248 // corresponding data (for that record only). Afterwards, we force a re-rendering of the
13249 // x2many kanban to ensure that the other record can still be rendered. Before the fix coming
13250 // with this test, it wasn't the case, because those records had extra activeFields, but no
13251 // entry in data for those fields.
13252 Partner._records[0].turtles = [2, 3];
13253 Turtle._views = {
13254 form: `
13255 <form>
13256 <field name="name"/>
13257 <field name="turtle_qux"/>
13258 </form>`,
13259 };
13260
13261 await mountView({
13262 type: "form",
13263 resModel: "partner",
13264 arch: `
13265 <form>
13266 <field name="bar"/>
13267 <field name="turtles" invisible="not bar">
13268 <kanban>
13269 <templates>
13270 <t t-name="card">
13271 <field name="name"/>
13272 </t>
13273 </templates>
13274 </kanban>
13275 </field>
13276 </form>`,
13277 resId: 1,
13278 });
13279
13280 expect(".o_field_widget[name=turtles]").toHaveCount(1);
13281 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(2);
13282
13283 // open the first record
13284 await contains(".o_kanban_record").click();
13285 expect(".o_dialog").toHaveCount(1);
13286 expect(".o_dialog .o_field_widget[name=turtle_qux]").toHaveCount(1);
13287
13288 // close the dialog
13289 await contains(".o_dialog .o_form_button_save").click();
13290 expect(".o_dialog").toHaveCount(0);
13291
13292 // toggle bar to make the x2many invisible
13293 await contains(".o_field_widget[name=bar] input").click();
13294 expect(".o_field_widget[name=turtles]").toHaveCount(0);
13295
13296 // toggle bar again to make the x2many visible and force kanban cards to re-render
13297 await contains(".o_field_widget[name=bar] input").click();
13298 expect(".o_field_widget[name=turtles]").toHaveCount(1);
13299 expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(2);
13300 });
13301
13302 test("onchange on x2many returning an update command with only readonly fields", async () => {
13303 Partner._records[0].turtles = [2];
13304 Turtle._fields.name = fields.Char({ readonly: true });
13305 Partner._onChanges = {
13306 bar: (obj) => {
13307 obj.turtles = [[1, 2, { name: "onchange name" }]];
13308 },
13309 };
13310 onRpc((args) => {
13311 expect.step(args.method);
13312 });
13313 onRpc("web_save", (args) => {
13314 expect(args.args[1]).toEqual({ bar: false }); // should not contain turtles
13315 });
13316 await mountView({
13317 type: "form",
13318 resModel: "partner",
13319 arch: `
13320 <form>
13321 <field name="bar"/>
13322 <field name="turtles">
13323 <list><field name="name"/></list>
13324 </field>
13325 </form>`,
13326 resId: 1,
13327 });
13328
13329 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(1);
13330 expect(".o_data_cell").toHaveText("donatello");
13331
13332 await contains(".o_field_widget[name=bar] input").click();
13333 expect(".o_data_cell").toHaveText("onchange name");
13334
13335 await clickSave();
13336 expect(".o_data_cell").toHaveText("donatello");
13337 expect.verifySteps(["get_views", "web_read", "onchange", "web_save"]);
13338 });
13339
13340 test("onchange on x2many returning a create command with only readonly fields", async () => {
13341 Turtle._fields.name = fields.Char({ readonly: true });
13342 Partner._onChanges = {
13343 bar: (obj) => {
13344 obj.turtles = [[0, false, { name: "onchange name" }]];
13345 },
13346 };
13347 onRpc((args) => {
13348 expect.step(args.method);
13349 });
13350 onRpc("web_save", (args) => {
13351 expect(args.args[1]).toEqual({
13352 bar: false,
13353 turtles: [[0, args.args[1].turtles[0][1], {}]],
13354 });
13355 });
13356 await mountView({
13357 type: "form",
13358 resModel: "partner",
13359 arch: `
13360 <form>
13361 <field name="bar"/>
13362 <field name="turtles">
13363 <list><field name="name"/></list>
13364 </field>
13365 </form>`,
13366 resId: 1,
13367 });
13368
13369 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(1);
13370 expect(".o_data_cell").toHaveText("donatello");
13371
13372 await contains(".o_field_widget[name=bar] input").click();
13373 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(2);
13374 expect(".o_data_cell:eq(1)").toHaveText("onchange name");
13375
13376 await clickSave();
13377 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(2);
13378 expect.verifySteps(["get_views", "web_read", "onchange", "web_save"]);
13379 });
13380
13381 test("onchange on x2many add and delete x2m record, returning to initial state", async () => {
13382 Turtle._fields.name = fields.Char({ readonly: true });
13383 Partner._onChanges = {
13384 turtles: function () {},
13385 };
13386
13387 let onchangeCount = 0;
13388 onRpc((args) => {
13389 expect.step(args.method);
13390 });
13391 onRpc("onchange", (args) => {
13392 if (onchangeCount === 1) {
13393 // partner turtles onchange for the new x2m record
13394 expect(args.model).toBe("partner");
13395 expect(Object.keys(args.args[1])).toEqual(["turtles"]);
13396 expect(args.args[1].turtles[0][0]).toBe(0);
13397 expect(args.args[2]).toEqual(["turtles"]);
13398 } else if (onchangeCount === 2) {
13399 // x2m record removed, empty list of commands expected
13400 expect(args.model).toBe("partner");
13401 expect(Object.keys(args.args[1])).toEqual(["turtles"]);
13402 expect(args.args[1].turtles).toEqual([]);
13403 expect(args.args[2]).toEqual(["turtles"]);
13404 }
13405 onchangeCount++;
13406 });
13407 await mountView({
13408 type: "form",
13409 resModel: "partner",
13410 arch: `
13411 <form>
13412 <field name="turtles">
13413 <list editable="bottom">
13414 <field name="name"/>
13415 </list>
13416 </field>
13417 </form>`,
13418 resId: 1,
13419 });
13420
13421 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(1);
13422 expect(".o_data_cell").toHaveText("donatello");
13423
13424 await contains(".o_field_x2many_list_row_add a").click();
13425 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(2);
13426 await contains(".o_list_record_remove:eq(1)").click();
13427 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(1);
13428
13429 await clickSave();
13430 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(1);
13431 expect.verifySteps(["get_views", "web_read", "onchange", "onchange", "onchange"]);
13432 });
13433
13434 test.tags("desktop");
13435 test("expand record in dialog", async () => {
13436 Turtle._views["form, false"] = `<form><field name="name"/></form>`;
13437 mockService("action", {
13438 doAction(actionRequest) {
13439 expect.step([
13440 actionRequest.res_id,
13441 actionRequest.res_model,
13442 actionRequest.type,
13443 actionRequest.views,
13444 ]);
13445 },
13446 });
13447 await mountView({
13448 type: "form",
13449 resModel: "partner",
13450 arch: `<form><field name="turtles"><list><field name="name"/></list></field></form>`,
13451 resId: 1,
13452 });
13453 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(1);
13454 expect(".o_data_cell").toHaveText("donatello");
13455 await contains(queryFirst(".o_field_widget[name=turtles] .o_data_cell")).click();
13456 expect(".o_dialog .o_form_view").toHaveCount(1);
13457 expect(".o_dialog .modal-header .o_expand_button").toHaveCount(1);
13458 await contains(".o_dialog .modal-header .btn-close").click();
13459 await contains(".o_field_widget[name=turtles] .o_field_x2many_list_row_add a").click();
13460 expect(".o_dialog .o_form_view").toHaveCount(1);
13461 expect(".o_dialog .modal-header .o_expand_button").toHaveCount(0);
13462 await contains("[name='name'] input").edit("new turtle");
13463 await contains(".o_dialog .o_form_button_save").click();
13464 expect(".o_field_widget[name=turtles] .o_data_row").toHaveCount(2);
13465 await contains(".o_field_widget[name=turtles] .o_data_cell:last").click();
13466 expect(".o_dialog .o_form_view").toHaveCount(1);
13467 expect(".o_dialog .modal-header .o_expand_button").toHaveCount(0);
13468 await contains(".o_dialog .modal-header .btn-close").click();
13469 await clickSave();
13470 await contains(".o_field_widget[name=turtles] .o_data_cell:last").click();
13471 expect(".o_dialog .o_form_view").toHaveCount(1);
13472 expect(".o_dialog .modal-header .o_expand_button").toHaveCount(1);
13473 await contains(".o_dialog .modal-header .o_expand_button").click();
13474 expect.verifySteps([[4, "turtle", "ir.actions.act_window", [[false, "form"]]]]);
13475 });
13476
13477 test("one2many kanban: add button kanban's card only with no control", async () => {
13478 Partner._fields.control = fields.One2many({
13479 string: "one2many field",
13480 relation: "partner",
13481 relation_field: "trululu",
13482 });
13483 Partner._records[0].p = [4];
13484 Partner._records[0].control = [4];
13485
13486 await mountView({
13487 type: "form",
13488 resModel: "partner",
13489 arch: `
13490 <form>
13491 <field name="p">
13492 <kanban>
13493 <templates>
13494 <t t-name="card">
13495 <field name="name"/>
13496 </t>
13497 </templates>
13498 </kanban>
13499 </field>
13500 <field name="control">
13501 <kanban>
13502 <control>
13503 <create string="Add Custom" class="myCustomClass" />
13504 </control>
13505 <templates>
13506 <t t-name="card">
13507 <field name="name"/>
13508 </t>
13509 </templates>
13510 </kanban>
13511 </field>
13512 </form>`,
13513 resId: 1,
13514 });
13515
13516 expect("[name='p'] .o_x2m_control_panel .o-kanban-button-new").toHaveCount(0);
13517 expect("[name='p'] .o_kanban_renderer .o-kanban-button-new").toHaveCount(1);
13518
13519 expect("[name='control'] .o_x2m_control_panel .o-kanban-button-new").toHaveCount(0);
13520 expect("[name='control'] .o_kanban_renderer .o-kanban-button-new").toHaveCount(0);
13521 expect("[name='control'] .myCustomClass").toHaveText("Add Custom");
13522 });
13523
13524 test("edit o2m with default_order on a field not in view", async () => {
13525 Partner._records[0].turtles = [1, 2, 3];
13526 await mountView({
13527 type: "form",
13528 resModel: "partner",
13529 arch: `
13530 <form>
13531 <field name="turtles">
13532 <list default_order="turtle_int">
13533 <field name="turtle_foo"/>
13534 <field name="turtle_bar"/>
13535 </list>
13536 <form>
13537 <field name="turtle_foo"/>
13538 </form>
13539 </field>
13540 </form>`,
13541 resId: 1,
13542 });
13543 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["yop", "blip", "kawa"]);
13544
13545 await contains(".o_data_row:eq(1) .o_data_cell").click();
13546 await contains(".modal .o_field_widget[name=turtle_foo] input").edit("blip2");
13547 await contains(".modal-footer .o_form_button_save").click();
13548 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["yop", "blip2", "kawa"]);
13549 });
13550
13551 test("edit o2m with default_order on a field not in view (2)", async () => {
13552 Partner._records[0].turtles = [1, 2, 3];
13553 await mountView({
13554 type: "form",
13555 resModel: "partner",
13556 arch: `
13557 <form>
13558 <field name="turtles">
13559 <list default_order="turtle_foo,turtle_int">
13560 <field name="turtle_foo"/>
13561 <field name="turtle_bar"/>
13562 </list>
13563 <form>
13564 <field name="turtle_foo"/>
13565 </form>
13566 </field>
13567 </form>`,
13568 resId: 1,
13569 });
13570 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blip", "kawa", "yop"]);
13571
13572 await contains(".o_data_row:eq(1) .o_data_cell").click();
13573 await contains(".modal .o_field_widget[name=turtle_foo] input").edit("kawa2");
13574 await contains(".modal-footer .o_form_button_save").click();
13575 expect(queryAllTexts(".o_data_cell.o_list_char")).toEqual(["blip", "kawa2", "yop"]);
13576 });
13577
13578 test("one2many list with aggregates in first column", async () => {
13579 Partner._records[0].turtles = [1, 2, 3];
13580
13581 await mountView({
13582 type: "form",
13583 resModel: "partner",
13584 arch: `
13585 <form>
13586 <field name="turtles">
13587 <list>
13588 <field name="turtle_int" sum="My sum"/>
13589 <field name="display_name"/>
13590 </list>
13591 </field>
13592 </form>`,
13593 resId: 1,
13594 });
13595
13596 expect(queryAllTexts(".o_data_cell")).toEqual([
13597 "0",
13598 "leonardo",
13599 "9",
13600 "donatello",
13601 "21",
13602 "raphael",
13603 ]);
13604 expect(`tfoot td:first`).toHaveText("30");
13605 });
13606
13607 test.tags("desktop");
13608 test("one2many list with monetary aggregates and different currencies", async () => {
13609 class Currency extends models.Model {
13610 _name = "res.currency";
13611
13612 name = fields.Char();
13613 symbol = fields.Char();
13614 position = fields.Selection({
13615 selection: [
13616 ["after", "A"],
13617 ["before", "B"],
13618 ],
13619 });
13620 inverse_rate = fields.Float();
13621
13622 _records = [
13623 { id: 1, name: "USD", symbol: "$", position: "before", inverse_rate: 1 },
13624 { id: 2, name: "EUR", symbol: "€", position: "after", inverse_rate: 0.5 },
13625 ];
13626 }
13627 defineModels([Currency]);
13628
13629 Turtle._fields.amount = fields.Monetary({ currency_field: "currency", default: 100 });
13630 Turtle._fields.currency = fields.Many2one({ relation: "res.currency", default: 1 });
13631 Turtle._records[2].currency = 2;
13632 Partner._records[0].turtles = [1, 2, 3];
13633
13634 await mountView({
13635 type: "form",
13636 resModel: "partner",
13637 arch: `
13638 <form>
13639 <field name="turtles">
13640 <list>
13641 <field name="amount" sum="My sum"/>
13642 <field name="currency"/>
13643 </list>
13644 </field>
13645 </form>`,
13646 resId: 1,
13647 });
13648
13649 expect(queryAllTexts(".o_data_cell.o_list_number")).toEqual([
13650 "$ 100.00",
13651 "$ 100.00",
13652 "100.00 €",
13653 ]);
13654 expect(`tfoot`).toHaveText("$ 250.00?");
13655 await contains("tfoot span sup").hover();
13656 expect(".o_multi_currency_popover").toHaveCount(1);
13657 expect(".o_multi_currency_popover").toHaveText("500.00 € at $ 0.50");
13658 });