1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
|
odoo.define('web.field_many_to_one_tests', function (require) {
"use strict";
var BasicModel = require('web.BasicModel');
var FormView = require('web.FormView');
var ListView = require('web.ListView');
var relationalFields = require('web.relational_fields');
var StandaloneFieldManagerMixin = require('web.StandaloneFieldManagerMixin');
var testUtils = require('web.test_utils');
var Widget = require('web.Widget');
const cpHelpers = testUtils.controlPanel;
var createView = testUtils.createView;
QUnit.module('fields', {}, function () {
QUnit.module('relational_fields', {
beforeEach: function () {
this.data = {
partner: {
fields: {
display_name: { string: "Displayed name", type: "char" },
foo: { string: "Foo", type: "char", default: "My little Foo Value" },
bar: { string: "Bar", type: "boolean", default: true },
int_field: { string: "int_field", type: "integer", sortable: true },
p: { string: "one2many field", type: "one2many", relation: 'partner', relation_field: 'trululu' },
turtles: { string: "one2many turtle field", type: "one2many", relation: 'turtle', relation_field: 'turtle_trululu' },
trululu: { string: "Trululu", type: "many2one", relation: 'partner' },
timmy: { string: "pokemon", type: "many2many", relation: 'partner_type' },
product_id: { string: "Product", type: "many2one", relation: 'product' },
color: {
type: "selection",
selection: [['red', "Red"], ['black', "Black"]],
default: 'red',
string: "Color",
},
date: { string: "Some Date", type: "date" },
datetime: { string: "Datetime Field", type: 'datetime' },
user_id: { string: "User", type: 'many2one', relation: 'user' },
reference: {
string: "Reference Field", type: 'reference', selection: [
["product", "Product"], ["partner_type", "Partner Type"], ["partner", "Partner"]]
},
},
records: [{
id: 1,
display_name: "first record",
bar: true,
foo: "yop",
int_field: 10,
p: [],
turtles: [2],
timmy: [],
trululu: 4,
user_id: 17,
reference: 'product,37',
}, {
id: 2,
display_name: "second record",
bar: true,
foo: "blip",
int_field: 9,
p: [],
timmy: [],
trululu: 1,
product_id: 37,
date: "2017-01-25",
datetime: "2016-12-12 10:55:05",
user_id: 17,
}, {
id: 4,
display_name: "aaa",
bar: false,
}],
onchanges: {},
},
product: {
fields: {
name: { string: "Product Name", type: "char" }
},
records: [{
id: 37,
display_name: "xphone",
}, {
id: 41,
display_name: "xpad",
}]
},
partner_type: {
fields: {
display_name: { string: "Partner Type", type: "char" },
name: { string: "Partner Type", type: "char" },
color: { string: "Color index", type: "integer" },
},
records: [
{ id: 12, display_name: "gold", color: 2 },
{ id: 14, display_name: "silver", color: 5 },
]
},
turtle: {
fields: {
display_name: { string: "Displayed name", type: "char" },
turtle_foo: { string: "Foo", type: "char" },
turtle_bar: { string: "Bar", type: "boolean", default: true },
turtle_int: { string: "int", type: "integer", sortable: true },
turtle_trululu: { string: "Trululu", type: "many2one", relation: 'partner' },
turtle_ref: {
string: "Reference", type: 'reference', selection: [
["product", "Product"], ["partner", "Partner"]]
},
product_id: { string: "Product", type: "many2one", relation: 'product', required: true },
partner_ids: { string: "Partner", type: "many2many", relation: 'partner' },
},
records: [{
id: 1,
display_name: "leonardo",
turtle_bar: true,
turtle_foo: "yop",
partner_ids: [],
}, {
id: 2,
display_name: "donatello",
turtle_bar: true,
turtle_foo: "blip",
turtle_int: 9,
partner_ids: [2, 4],
}, {
id: 3,
display_name: "raphael",
product_id: 37,
turtle_bar: false,
turtle_foo: "kawa",
turtle_int: 21,
partner_ids: [],
turtle_ref: 'product,37',
}],
onchanges: {},
},
user: {
fields: {
name: { string: "Name", type: "char" },
partner_ids: { string: "one2many partners field", type: "one2many", relation: 'partner', relation_field: 'user_id' },
},
records: [{
id: 17,
name: "Aline",
partner_ids: [1, 2],
}, {
id: 19,
name: "Christine",
}]
},
};
},
}, function () {
QUnit.module('FieldMany2One');
QUnit.test('many2ones in form views', async function (assert) {
assert.expect(5);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="trululu" string="custom label"/>' +
'</group>' +
'</sheet>' +
'</form>',
archs: {
'partner,false,form': '<form string="Partners"><field name="display_name"/></form>',
},
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'get_formview_action') {
assert.deepEqual(args.args[0], [4], "should call get_formview_action with correct id");
return Promise.resolve({
res_id: 17,
type: 'ir.actions.act_window',
target: 'current',
res_model: 'res.partner'
});
}
if (args.method === 'get_formview_id') {
assert.deepEqual(args.args[0], [4], "should call get_formview_id with correct id");
return Promise.resolve(false);
}
return this._super(route, args);
},
});
testUtils.mock.intercept(form, 'do_action', function (event) {
assert.strictEqual(event.data.action.res_id, 17,
"should do a do_action with correct parameters");
});
assert.strictEqual(form.$('a.o_form_uri:contains(aaa)').length, 1,
"should contain a link");
await testUtils.dom.click(form.$('a.o_form_uri'));
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_external_button'));
assert.strictEqual($('.modal .modal-title').text().trim(), 'Open: custom label',
"dialog title should display the custom string label");
// TODO: test that we can edit the record in the dialog, and that
// the value is correctly updated on close
form.destroy();
});
QUnit.test('editing a many2one, but not changing anything', async function (assert) {
assert.expect(2);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="trululu"/>' +
'</sheet>' +
'</form>',
archs: {
'partner,false,form': '<form string="Partners"><field name="display_name"/></form>',
},
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'get_formview_id') {
assert.deepEqual(args.args[0], [4], "should call get_formview_id with correct id");
return Promise.resolve(false);
}
return this._super(route, args);
},
viewOptions: {
ids: [1, 2],
},
});
await testUtils.form.clickEdit(form);
// click on the external button (should do an RPC)
await testUtils.dom.click(form.$('.o_external_button'));
// save and close modal
await testUtils.dom.click($('.modal .modal-footer .btn-primary:first'));
// save form
await testUtils.form.clickSave(form);
// click next on pager
await testUtils.dom.click(form.el.querySelector('.o_pager .o_pager_next'));
// this checks that the view did not ask for confirmation that the
// record is dirty
assert.strictEqual(form.el.querySelector('.o_pager').innerText.trim(), '2 / 2',
'pager should be at second page');
form.destroy();
});
QUnit.test('context in many2one and default get', async function (assert) {
assert.expect(1);
this.data.partner.fields.int_field.default = 14;
this.data.partner.fields.trululu.default = 2;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="int_field"/>' +
'<field name="trululu" context="{\'blip\':int_field}" options=\'{"always_reload": True}\'/>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'name_get') {
assert.strictEqual(args.kwargs.context.blip, 14,
'context should have been properly sent to the nameget rpc');
}
return this._super(route, args);
},
});
form.destroy();
});
QUnit.test('editing a many2one (with form view opened with external button)', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="trululu"/>' +
'</sheet>' +
'</form>',
archs: {
'partner,false,form': '<form string="Partners"><field name="foo"/></form>',
},
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'get_formview_id') {
return Promise.resolve(false);
}
return this._super(route, args);
},
viewOptions: {
ids: [1, 2],
},
});
await testUtils.form.clickEdit(form);
// click on the external button (should do an RPC)
await testUtils.dom.click(form.$('.o_external_button'));
await testUtils.fields.editInput($('.modal input[name="foo"]'), 'brandon');
// save and close modal
await testUtils.dom.click($('.modal .modal-footer .btn-primary:first'));
// save form
await testUtils.form.clickSave(form);
// click next on pager
await testUtils.dom.click(form.el.querySelector('.o_pager .o_pager_next'));
// this checks that the view did not ask for confirmation that the
// record is dirty
assert.strictEqual(form.el.querySelector('.o_pager').innerText.trim(), '2 / 2',
'pager should be at second page');
form.destroy();
});
QUnit.test('many2ones in form views with show_address', async function (assert) {
assert.expect(4);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field ' +
'name="trululu" ' +
'string="custom label" ' +
'context="{\'show_address\': 1}" ' +
'options="{\'always_reload\': True}"' +
'/>' +
'</group>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'name_get') {
return this._super(route, args).then(function (result) {
result[0][1] += '\nStreet\nCity ZIP';
return result;
});
}
return this._super(route, args);
},
res_id: 1,
});
assert.strictEqual(form.$('a.o_form_uri').html(), '<span>aaa</span><br><span>Street</span><br><span>City ZIP</span>',
"input should have a multi-line content in readonly due to show_address");
await testUtils.form.clickEdit(form);
assert.containsOnce(form, 'button.o_external_button:visible',
"should have an open record button");
testUtils.dom.click(form.$('input.o_input'));
assert.containsOnce(form, 'button.o_external_button:visible',
"should still have an open record button");
form.$('input.o_input').trigger('focusout');
assert.strictEqual($('.modal button:contains(Create and edit)').length, 0,
"there should not be a quick create modal");
form.destroy();
});
QUnit.test('show_address works in a view embedded in a view of another type', async function (assert) {
assert.expect(1);
this.data.turtle.records[1].turtle_trululu = 2;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="display_name"/>' +
'<field name="turtles"/>' +
'</form>',
res_id: 1,
archs: {
"turtle,false,form": '<form string="T">' +
'<field name="display_name"/>' +
'<field name="turtle_trululu" context="{\'show_address\': 1}" options="{\'always_reload\': True}"/>' +
'</form>',
"turtle,false,list": '<tree editable="bottom">' +
'<field name="display_name"/>' +
'</tree>',
},
mockRPC: function (route, args) {
if (args.method === 'name_get') {
return this._super(route, args).then(function (result) {
if (args.model === 'partner' && args.kwargs.context.show_address) {
result[0][1] += '\nrue morgue\nparis 75013';
}
return result;
});
}
return this._super(route, args);
},
});
// click the turtle field, opens a modal with the turtle form view
await testUtils.dom.click(form.$('.o_data_row:first td.o_data_cell'));
assert.strictEqual($('[name="turtle_trululu"]').text(), "second recordrue morgueparis 75013",
"The partner's address should be displayed");
form.destroy();
});
QUnit.test('many2one data is reloaded if there is a context to take into account', async function (assert) {
assert.expect(1);
this.data.turtle.records[1].turtle_trululu = 2;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="display_name"/>' +
'<field name="turtles"/>' +
'</form>',
res_id: 1,
archs: {
"turtle,false,form": '<form string="T">' +
'<field name="display_name"/>' +
'<field name="turtle_trululu" context="{\'show_address\': 1}" options="{\'always_reload\': True}"/>' +
'</form>',
"turtle,false,list": '<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="turtle_trululu"/>' +
'</tree>',
},
mockRPC: function (route, args) {
if (args.method === 'name_get') {
return this._super(route, args).then(function (result) {
if (args.model === 'partner' && args.kwargs.context.show_address) {
result[0][1] += '\nrue morgue\nparis 75013';
}
return result;
});
}
return this._super(route, args);
},
});
// click the turtle field, opens a modal with the turtle form view
await testUtils.dom.click(form.$('.o_data_row:first'));
assert.strictEqual($('.modal [name=turtle_trululu]').text(), "second recordrue morgueparis 75013",
"The partner's address should be displayed");
form.destroy();
});
QUnit.test('many2ones in form views with search more', async function (assert) {
assert.expect(3);
this.data.partner.records.push({
id: 5,
display_name: "Partner 4",
}, {
id: 6,
display_name: "Partner 5",
}, {
id: 7,
display_name: "Partner 6",
}, {
id: 8,
display_name: "Partner 7",
}, {
id: 9,
display_name: "Partner 8",
}, {
id: 10,
display_name: "Partner 9",
});
this.data.partner.fields.datetime.searchable = true;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="trululu"/>' +
'</group>' +
'</sheet>' +
'</form>',
archs: {
'partner,false,list': '<tree><field name="display_name"/></tree>',
'partner,false,search': '<search><field name="datetime"/></search>',
},
res_id: 1,
});
await testUtils.form.clickEdit(form);
await testUtils.fields.many2one.clickOpenDropdown('trululu');
await testUtils.fields.many2one.clickItem('trululu', 'Search');
assert.strictEqual($('tr.o_data_row').length, 9, "should display 9 records");
await cpHelpers.toggleFilterMenu('.modal');
await cpHelpers.toggleAddCustomFilter('.modal');
assert.strictEqual(document.querySelector('.modal .o_generator_menu_field').value, 'datetime',
"datetime field should be selected");
await cpHelpers.applyFilter('.modal');
assert.strictEqual($('tr.o_data_row').length, 0, "should display 0 records");
form.destroy();
});
QUnit.test('onchanges on many2ones trigger when editing record in form view', async function (assert) {
assert.expect(10);
this.data.partner.onchanges.user_id = function () { };
this.data.user.fields.other_field = { string: "Other Field", type: "char" };
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="user_id"/>' +
'</group>' +
'</sheet>' +
'</form>',
archs: {
'user,false,form': '<form string="Users"><field name="other_field"/></form>',
},
res_id: 1,
mockRPC: function (route, args) {
assert.step(args.method);
if (args.method === 'get_formview_id') {
return Promise.resolve(false);
}
if (args.method === 'onchange') {
assert.strictEqual(args.args[1].user_id, 17,
"onchange is triggered with correct user_id");
}
return this._super(route, args);
},
});
// open the many2one in form view and change something
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_external_button'));
await testUtils.fields.editInput($('.modal-body input[name="other_field"]'), 'wood');
// save the modal and make sure an onchange is triggered
await testUtils.dom.click($('.modal .modal-footer .btn-primary').first());
assert.verifySteps(['read', 'get_formview_id', 'load_views', 'read', 'write', 'read', 'onchange']);
// save the main record, and check that no extra rpcs are done (record
// is not dirty, only a related record was modified)
await testUtils.form.clickSave(form);
assert.verifySteps([]);
form.destroy();
});
QUnit.test("many2one doesn't trigger field_change when being emptied", async function (assert) {
assert.expect(2);
const list = await createView({
arch: `
<tree multi_edit="1">
<field name="trululu"/>
</tree>`,
data: this.data,
model: 'partner',
View: ListView,
});
// Select two records
await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_list_record_selector input'));
await testUtils.dom.click(list.$('.o_data_row:eq(1) .o_list_record_selector input'));
await testUtils.dom.click(list.$('.o_data_row:first() .o_data_cell:first()'));
const $input = list.$('.o_field_widget[name=trululu] input');
await testUtils.fields.editInput($input, "");
await testUtils.dom.triggerEvents($input, ['keyup']);
assert.containsNone(document.body, '.modal',
"No save should be triggered when removing value");
await testUtils.fields.many2one.clickHighlightedItem('trululu');
assert.containsOnce(document.body, '.modal',
"Saving should be triggered when selecting a value");
await testUtils.dom.click($('.modal .btn-primary'));
list.destroy();
});
QUnit.test("focus tracking on a many2one in a list", async function (assert) {
assert.expect(4);
const list = await createView({
arch: '<tree editable="top"><field name="trululu"/></tree>',
archs: {
'partner,false,form': '<form string="Partners"><field name="foo"/></form>',
},
data: this.data,
model: 'partner',
View: ListView,
});
// Select two records
await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_list_record_selector input'));
await testUtils.dom.click(list.$('.o_data_row:eq(1) .o_list_record_selector input'));
await testUtils.dom.click(list.$('.o_data_row:first() .o_data_cell:first()'));
const input = list.$('.o_data_row:first() .o_data_cell:first() input')[0];
assert.strictEqual(document.activeElement, input, "Input should be focused when activated");
await testUtils.fields.many2one.createAndEdit('trululu', "ABC");
// At this point, if the focus is correctly registered by the m2o, there
// should be only one modal (the "Create" one) and none for saving changes.
assert.containsOnce(document.body, '.modal', "There should be only one modal");
await testUtils.dom.click($('.modal .btn:not(.btn-primary)'));
assert.strictEqual(document.activeElement, input, "Input should be focused after dialog closes");
assert.strictEqual(input.value, "", "Input should be empty after discard");
list.destroy();
});
QUnit.test('many2one fields with option "no_open"', async function (assert) {
assert.expect(3);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="trululu" options="{"no_open": True}" />' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 1,
});
assert.containsOnce(form, 'span.o_field_widget[name=trululu]',
"should be displayed inside a span (sanity check)");
assert.containsNone(form, 'span.o_form_uri', "should not have an anchor");
await testUtils.form.clickEdit(form);
assert.containsNone(form, '.o_field_widget[name=trululu] .o_external_button', "should not have the button to open the record");
form.destroy();
});
QUnit.test('empty many2one field', async function (assert) {
assert.expect(4);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: `<form string="Partners">
<sheet>
<group>
<field name="trululu"/>
</group>
</sheet>
</form>`,
viewOptions: {
mode: 'edit',
},
});
const $dropdown = form.$('.o_field_many2one input').autocomplete('widget');
await testUtils.fields.many2one.clickOpenDropdown('trululu');
assert.containsNone($dropdown, 'li.o_m2o_dropdown_option',
'autocomplete should not contains dropdown options');
assert.containsOnce($dropdown, 'li.o_m2o_start_typing',
'autocomplete should contains start typing option');
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one[name="trululu"] input'),
'abc', 'keydown');
await testUtils.nextTick();
assert.containsN($dropdown, 'li.o_m2o_dropdown_option', 2,
'autocomplete should contains 2 dropdown options');
assert.containsNone($dropdown, 'li.o_m2o_start_typing',
'autocomplete should not contains start typing option');
form.destroy();
});
QUnit.test('empty many2one field with node options', async function (assert) {
assert.expect(2);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: `<form string="Partners">
<sheet>
<group>
<field name="trululu" options="{'no_create_edit': 1}"/>
<field name="product_id" options="{'no_create_edit': 1, 'no_quick_create': 1}"/>
</group>
</sheet>
</form>`,
viewOptions: {
mode: 'edit',
},
});
const $dropdownTrululu = form.$('.o_field_many2one[name="trululu"] input').autocomplete('widget');
const $dropdownProduct = form.$('.o_field_many2one[name="product_id"] input').autocomplete('widget');
await testUtils.fields.many2one.clickOpenDropdown('trululu');
assert.containsOnce($dropdownTrululu, 'li.o_m2o_start_typing',
'autocomplete should contains start typing option');
await testUtils.fields.many2one.clickOpenDropdown('product_id');
assert.containsNone($dropdownProduct, 'li.o_m2o_start_typing',
'autocomplete should contains start typing option');
form.destroy();
});
QUnit.test('many2one in edit mode', async function (assert) {
assert.expect(17);
// create 10 partners to have the 'Search More' option in the autocomplete dropdown
for (var i = 0; i < 10; i++) {
var id = 20 + i;
this.data.partner.records.push({ id: id, display_name: "Partner " + id });
}
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="trululu"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 1,
archs: {
'partner,false,list': '<tree string="Partners"><field name="display_name"/></tree>',
'partner,false,search': '<search string="Partners">' +
'<field name="display_name" string="Name"/>' +
'</search>',
},
mockRPC: function (route, args) {
if (route === '/web/dataset/call_kw/partner/write') {
assert.strictEqual(args.args[1].trululu, 20, "should write the correct id");
}
return this._super.apply(this, arguments);
},
});
// the SelectCreateDialog requests the session, so intercept its custom
// event to specify a fake session to prevent it from crashing
testUtils.mock.intercept(form, 'get_session', function (event) {
event.data.callback({ user_context: {} });
});
await testUtils.form.clickEdit(form);
var $dropdown = form.$('.o_field_many2one input').autocomplete('widget');
await testUtils.fields.many2one.clickOpenDropdown('trululu');
assert.ok($dropdown.is(':visible'),
'clicking on the m2o input should open the dropdown if it is not open yet');
assert.strictEqual($dropdown.find('li:not(.o_m2o_dropdown_option)').length, 7,
'autocomplete should contains 8 suggestions');
assert.strictEqual($dropdown.find('li.o_m2o_dropdown_option').length, 1,
'autocomplete should contain "Search More"');
assert.containsNone($dropdown, 'li.o_m2o_start_typing',
'autocomplete should not contains start typing option if value is available');
await testUtils.fields.many2one.clickOpenDropdown('trululu');
assert.ok(!$dropdown.is(':visible'),
'clicking on the m2o input should close the dropdown if it is open');
// change the value of the m2o with a suggestion of the dropdown
await testUtils.fields.many2one.clickOpenDropdown('trululu');
await testUtils.fields.many2one.clickHighlightedItem('trululu');
assert.ok(!$dropdown.is(':visible'), 'clicking on a value should close the dropdown');
assert.strictEqual(form.$('.o_field_many2one input').val(), 'first record',
'value of the m2o should have been correctly updated');
// change the value of the m2o with a record in the 'Search More' modal
await testUtils.fields.many2one.clickOpenDropdown('trululu');
// click on 'Search More' (mouseenter required by ui-autocomplete)
await testUtils.fields.many2one.clickItem('trululu', 'Search');
assert.ok($('.modal .o_list_view').length, "should have opened a list view in a modal");
assert.ok(!$('.modal .o_list_view .o_list_record_selector').length,
"there should be no record selector in the list view");
assert.ok(!$('.modal .modal-footer .o_select_button').length,
"there should be no 'Select' button in the footer");
assert.ok($('.modal tbody tr').length > 10, "list should contain more than 10 records");
await cpHelpers.editSearch('.modal', "P");
await cpHelpers.validateSearch('.modal');
assert.strictEqual($('.modal tbody tr').length, 10,
"list should be restricted to records containing a P (10 records)");
// choose a record
await testUtils.dom.click($('.modal tbody tr:contains(Partner 20)'));
assert.ok(!$('.modal').length, "should have closed the modal");
assert.ok(!$dropdown.is(':visible'), 'should have closed the dropdown');
assert.strictEqual(form.$('.o_field_many2one input').val(), 'Partner 20',
'value of the m2o should have been correctly updated');
// save
await testUtils.form.clickSave(form);
assert.strictEqual(form.$('a.o_form_uri').text(), 'Partner 20',
"should display correct value after save");
form.destroy();
});
QUnit.test('many2one in non edit mode', async function (assert) {
assert.expect(3);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="trululu"/>' +
'</form>',
res_id: 1,
});
assert.containsOnce(form, 'a.o_form_uri',
"should display 1 m2o link in form");
assert.hasAttrValue(form.$('a.o_form_uri'), 'href', "#id=4&model=partner",
"href should contain id and model");
// Remove value from many2one and then save, there should not have href with id and model on m2o anchor
await testUtils.form.clickEdit(form);
form.$('.o_field_many2one input').val('').trigger('keyup').trigger('focusout');
await testUtils.form.clickSave(form);
assert.hasAttrValue(form.$('a.o_form_uri'), 'href', "#",
"href should have #");
form.destroy();
});
QUnit.test('many2one with co-model whose name field is a many2one', async function (assert) {
assert.expect(4);
this.data.product.fields.name = {
string: 'User Name',
type: 'many2one',
relation: 'user',
};
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="product_id"/></form>',
archs: {
'product,false,form': '<form><field name="name"/></form>',
},
});
await testUtils.fields.many2one.createAndEdit('product_id', "ABC");
assert.containsOnce(document.body, '.modal .o_form_view');
// quick create 'new value'
await testUtils.fields.many2one.searchAndClickItem('name', {search: 'new value'});
assert.strictEqual($('.modal .o_field_many2one input').val(), 'new value');
await testUtils.dom.click($('.modal .modal-footer .btn-primary')); // save in modal
assert.containsNone(document.body, '.modal .o_form_view');
assert.strictEqual(form.$('.o_field_many2one input').val(), 'new value');
form.destroy();
});
QUnit.test('many2one searches with correct value', async function (assert) {
assert.expect(6);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="trululu"/>' +
'</sheet>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'name_search') {
assert.step('search: ' + args.kwargs.name);
}
return this._super.apply(this, arguments);
},
viewOptions: {
mode: 'edit',
},
});
assert.strictEqual(form.$('.o_field_many2one input').val(), 'aaa',
"should be initially set to 'aaa'");
await testUtils.dom.click(form.$('.o_field_many2one input'));
// unset the many2one -> should search again with ''
form.$('.o_field_many2one input').val('').trigger('keydown');
await testUtils.nextTick();
form.$('.o_field_many2one input').val('p').trigger('keydown').trigger('keyup');
await testUtils.nextTick();
// close and re-open the dropdown -> should search with 'p' again
await testUtils.dom.click(form.$('.o_field_many2one input'));
await testUtils.dom.click(form.$('.o_field_many2one input'));
assert.verifySteps(['search: ', 'search: ', 'search: p', 'search: p']);
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
form.destroy();
});
QUnit.test('many2one search with trailing and leading spaces', async function (assert) {
assert.expect(10);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: `<form><field name="trululu"/></form>`,
mockRPC: function (route, args) {
if (args.method === 'name_search') {
assert.step('search: ' + args.kwargs.name);
}
return this._super.apply(this, arguments);
},
});
const $dropdown = form.$('.o_field_many2one input').autocomplete('widget');
await testUtils.fields.many2one.clickOpenDropdown('trululu');
assert.isVisible($dropdown);
assert.containsN($dropdown, 'li:not(.o_m2o_dropdown_option)', 4,
'autocomplete should contains 4 suggestions');
// search with leading spaces
form.$('.o_field_many2one input').val(' first').trigger('keydown').trigger('keyup');
await testUtils.nextTick();
assert.containsOnce($dropdown, 'li:not(.o_m2o_dropdown_option)',
'autocomplete should contains 1 suggestion');
// search with trailing spaces
form.$('.o_field_many2one input').val('first ').trigger('keydown').trigger('keyup');
await testUtils.nextTick();
assert.containsOnce($dropdown, 'li:not(.o_m2o_dropdown_option)',
'autocomplete should contains 1 suggestion');
// search with leading and trailing spaces
form.$('.o_field_many2one input').val(' first ').trigger('keydown').trigger('keyup');
await testUtils.nextTick();
assert.containsOnce($dropdown, 'li:not(.o_m2o_dropdown_option)',
'autocomplete should contains 1 suggestion');
assert.verifySteps(['search: ', 'search: first', 'search: first', 'search: first']);
form.destroy();
});
QUnit.test('many2one field with option always_reload', async function (assert) {
assert.expect(4);
var count = 0;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="trululu" options="{\'always_reload\': True}"/>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (args.method === 'name_get') {
count++;
return Promise.resolve([[1, "first record\nand some address"]]);
}
return this._super(route, args);
},
});
assert.strictEqual(count, 1, "an extra name_get should have been done");
assert.ok(form.$('a:contains(and some address)').length,
"should display additional result");
await testUtils.form.clickEdit(form);
assert.strictEqual(form.$('.o_field_widget[name=trululu] input').val(), "first record",
"actual field value should be displayed to be edited");
await testUtils.form.clickSave(form);
assert.ok(form.$('a:contains(and some address)').length,
"should still display additional result");
form.destroy();
});
QUnit.test('many2one field and list navigation', async function (assert) {
assert.expect(3);
var list = await createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree editable="bottom"><field name="trululu"/></tree>',
});
// edit first input, to trigger autocomplete
await testUtils.dom.click(list.$('.o_data_row .o_data_cell').first());
await testUtils.fields.editInput(list.$('.o_data_cell input'), '');
// press keydown, to select first choice
await testUtils.fields.triggerKeydown(list.$('.o_data_cell input').focus(), 'down');
// we now check that the dropdown is open (and that the focus did not go
// to the next line)
var $dropdown = list.$('.o_field_many2one input').autocomplete('widget');
assert.ok($dropdown.is(':visible'), "dropdown should be visible");
assert.hasClass(list.$('.o_data_row:eq(0)'),'o_selected_row',
'first data row should still be selected');
assert.doesNotHaveClass(list.$('.o_data_row:eq(1)'), 'o_selected_row',
'second data row should not be selected');
list.destroy();
});
QUnit.test('standalone many2one field', async function (assert) {
assert.expect(4);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var fixture = $('#qunit-fixture');
var self = this;
var model = await testUtils.createModel({
Model: BasicModel,
data: this.data,
});
var record;
model.makeRecord('coucou', [{
name: 'partner_id',
relation: 'partner',
type: 'many2one',
value: [1, 'first partner'],
}]).then(function (recordID) {
record = model.get(recordID);
});
await testUtils.nextTick();
// create a new widget that uses the StandaloneFieldManagerMixin
var StandaloneWidget = Widget.extend(StandaloneFieldManagerMixin, {
init: function (parent) {
this._super.apply(this, arguments);
StandaloneFieldManagerMixin.init.call(this, parent);
},
});
var parent = new StandaloneWidget(model);
model.setParent(parent);
await testUtils.mock.addMockEnvironment(parent, {
data: self.data,
mockRPC: function (route, args) {
assert.step(args.method);
return this._super.apply(this, arguments);
},
});
var relField = new relationalFields.FieldMany2One(parent, 'partner_id', record, {
mode: 'edit',
noOpen: true,
});
relField.appendTo(fixture);
await testUtils.nextTick();
await testUtils.fields.editInput($('input.o_input'), 'xyzzrot');
await testUtils.fields.many2one.clickItem('partner_id', 'Create');
assert.containsNone(relField, '.o_external_button',
"should not have the button to open the record");
assert.verifySteps(['name_search', 'name_create']);
parent.destroy();
model.destroy();
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
});
// QUnit.test('onchange on a many2one to a different model', async function (assert) {
// This test is commented because the mock server does not give the correct response.
// It should return a couple [id, display_name], but I don't know the logic used
// by the server, so it's hard to emulate it correctly
// assert.expect(2);
// this.data.partner.records[0].product_id = 41;
// this.data.partner.onchanges = {
// foo: function(obj) {
// obj.product_id = 37;
// },
// };
// var form = await createView({
// View: FormView,
// model: 'partner',
// data: this.data,
// arch: '<form>' +
// '<field name="foo"/>' +
// '<field name="product_id"/>' +
// '</form>',
// res_id: 1,
// });
// await testUtils.form.clickEdit(form);
// assert.strictEqual(form.$('input').eq(1).val(), 'xpad', "initial product_id val should be xpad");
// testUtils.fields.editInput(form.$('input').eq(0), "let us trigger an onchange");
// assert.strictEqual(form.$('input').eq(1).val(), 'xphone', "onchange should have been applied");
// });
QUnit.test('form: quick create then save directly', async function (assert) {
assert.expect(5);
var prom = testUtils.makeTestPromise();
var newRecordID;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="trululu"/>' +
'</form>',
mockRPC: function (route, args) {
var result = this._super.apply(this, arguments);
if (args.method === 'name_create') {
assert.step('name_create');
return prom.then(_.constant(result)).then(function (nameGet) {
newRecordID = nameGet[0];
return nameGet;
});
}
if (args.method === 'create') {
assert.step('create');
assert.strictEqual(args.args[0].trululu, newRecordID,
"should create with the correct m2o id");
}
return result;
},
});
await testUtils.fields.many2one.searchAndClickItem('trululu', {search: 'b'});
await testUtils.form.clickSave(form);
assert.verifySteps(['name_create'],
"should wait for the name_create before creating the record");
await prom.resolve();
await testUtils.nextTick();
assert.verifySteps(['create']);
form.destroy();
});
QUnit.test('form: quick create for field that returns false after name_create call', async function (assert) {
assert.expect(3);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="trululu"/></form>',
mockRPC: function (route, args) {
const result = this._super.apply(this, arguments);
if (args.method === 'name_create') {
assert.step('name_create');
// Resolve the name_create call to false. This is possible if
// _rec_name for the model of the field is unassigned.
return Promise.resolve(false);
}
return result;
},
});
await testUtils.fields.many2one.searchAndClickItem('trululu', { search: 'beam' });
assert.verifySteps(['name_create'], 'attempt to name_create');
assert.strictEqual(form.$(".o_input_dropdown input").val(), "",
"the input should contain no text after search and click")
form.destroy();
});
QUnit.test('list: quick create then save directly', async function (assert) {
assert.expect(8);
var prom = testUtils.makeTestPromise();
var newRecordID;
var list = await createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree editable="top">' +
'<field name="trululu"/>' +
'</tree>',
mockRPC: function (route, args) {
var result = this._super.apply(this, arguments);
if (args.method === 'name_create') {
assert.step('name_create');
return prom.then(_.constant(result)).then(function (nameGet) {
newRecordID = nameGet[0];
return nameGet;
});
}
if (args.method === 'create') {
assert.step('create');
assert.strictEqual(args.args[0].trululu, newRecordID,
"should create with the correct m2o id");
}
return result;
},
});
await testUtils.dom.click(list.$buttons.find('.o_list_button_add'));
await testUtils.fields.many2one.searchAndClickItem('trululu', {search:'b'});
list.$buttons.find('.o_list_button_add').show();
testUtils.dom.click(list.$buttons.find('.o_list_button_add'));
assert.verifySteps(['name_create'],
"should wait for the name_create before creating the record");
assert.containsN(list, '.o_data_row', 4,
"should wait for the name_create before adding the new row");
await prom.resolve();
await testUtils.nextTick();
assert.verifySteps(['create']);
assert.strictEqual(list.$('.o_data_row:nth(1) .o_data_cell').text(), 'b',
"created row should have the correct m2o value");
assert.containsN(list, '.o_data_row', 5, "should have added the fifth row");
list.destroy();
});
QUnit.test('list in form: quick create then save directly', async function (assert) {
assert.expect(6);
var prom = testUtils.makeTestPromise();
var newRecordID;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
var result = this._super.apply(this, arguments);
if (args.method === 'name_create') {
assert.step('name_create');
return prom.then(_.constant(result)).then(function (nameGet) {
newRecordID = nameGet[0];
return nameGet;
});
}
if (args.method === 'create') {
assert.step('create');
assert.strictEqual(args.args[0].p[0][2].trululu, newRecordID,
"should create with the correct m2o id");
}
return result;
},
});
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
await testUtils.fields.many2one.searchAndClickItem('trululu', {search: 'b'});
await testUtils.form.clickSave(form);
assert.verifySteps(['name_create'],
"should wait for the name_create before creating the record");
await prom.resolve();
await testUtils.nextTick();
assert.verifySteps(['create']);
assert.strictEqual(form.$('.o_data_row:first .o_data_cell').text(), 'b',
"first row should have the correct m2o value");
form.destroy();
});
QUnit.test('list in form: quick create then add a new line directly', async function (assert) {
// required many2one inside a one2many list: directly after quick creating
// a new many2one value (before the name_create returns), click on add an item:
// at this moment, the many2one has still no value, and as it is required,
// the row is discarded if a saveLine is requested. However, it should
// wait for the name_create to return before trying to save the line.
assert.expect(8);
this.data.partner.onchanges = {
trululu: function () { },
};
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var prom = testUtils.makeTestPromise();
var newRecordID;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="trululu" required="1"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
var result = this._super.apply(this, arguments);
if (args.method === 'name_create') {
return prom.then(_.constant(result)).then(function (nameGet) {
newRecordID = nameGet[0];
return nameGet;
});
}
if (args.method === 'create') {
assert.deepEqual(args.args[0].p[0][2].trululu, newRecordID);
}
return result;
},
});
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one input'),
'b', 'keydown');
await testUtils.fields.many2one.clickHighlightedItem('trululu');
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
assert.containsOnce(form, '.o_data_row',
"there should still be only one row");
assert.hasClass(form.$('.o_data_row'),'o_selected_row',
"the row should still be in edition");
await prom.resolve();
await testUtils.nextTick();
assert.strictEqual(form.$('.o_data_row:first .o_data_cell').text(), 'b',
"first row should have the correct m2o value");
assert.containsN(form, '.o_data_row', 2,
"there should now be 2 rows");
assert.hasClass(form.$('.o_data_row:nth(1)'),'o_selected_row',
"the second row should be in edition");
await testUtils.form.clickSave(form);
assert.containsOnce(form, '.o_data_row',
"there should be 1 row saved (the second one was empty and invalid)");
assert.strictEqual(form.$('.o_data_row .o_data_cell').text(), 'b',
"should have the correct m2o value");
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
form.destroy();
});
QUnit.test('list in form: create with one2many with many2one', async function (assert) {
assert.expect(1);
this.data.partner.fields.p.default = [[0, 0, { display_name: 'new record', p: [] }]];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'name_get') {
throw new Error('Nameget should not be called');
}
return this._super.apply(this, arguments);
},
});
assert.strictEqual($('td.o_data_cell:first').text(), 'new record',
"should have created the new record in the o2m with the correct name");
form.destroy();
});
QUnit.test('list in form: create with one2many with many2one (version 2)', async function (assert) {
// This test simulates the exact same scenario as the previous one,
// except that the value for the many2one is explicitely set to false,
// which is stupid, but this happens, so we have to handle it
assert.expect(1);
this.data.partner.fields.p.default = [
[0, 0, { display_name: 'new record', trululu: false, p: [] }]
];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'name_get') {
throw new Error('Nameget should not be called');
}
return this._super.apply(this, arguments);
},
});
assert.strictEqual($('td.o_data_cell:first').text(), 'new record',
"should have created the new record in the o2m with the correct name");
form.destroy();
});
QUnit.test('item not dropped on discard with empty required field (default_get)', async function (assert) {
// This test simulates discarding a record that has been created with
// one of its required field that is empty. When we discard the changes
// on this empty field, it should not assume that this record should be
// abandonned, since it has been added (even though it is a new record).
assert.expect(8);
this.data.partner.fields.p.default = [
[0, 0, { display_name: 'new record', trululu: false, p: [] }]
];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu" required="1"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
});
assert.strictEqual($('tr.o_data_row').length, 1,
"should have created the new record in the o2m");
assert.strictEqual($('td.o_data_cell').first().text(), "new record",
"should have the correct displayed name");
var requiredElement = $('td.o_data_cell.o_required_modifier');
assert.strictEqual(requiredElement.length, 1,
"should have a required field on this record");
assert.strictEqual(requiredElement.text(), "",
"should have empty string in the required field on this record");
testUtils.dom.click(requiredElement);
// discard by clicking on body
testUtils.dom.click($('body'));
assert.strictEqual($('tr.o_data_row').length, 1,
"should still have the record in the o2m");
assert.strictEqual($('td.o_data_cell').first().text(), "new record",
"should still have the correct displayed name");
// update selector of required field element
requiredElement = $('td.o_data_cell.o_required_modifier');
assert.strictEqual(requiredElement.length, 1,
"should still have the required field on this record");
assert.strictEqual(requiredElement.text(), "",
"should still have empty string in the required field on this record");
form.destroy();
});
QUnit.test('list in form: name_get with unique ids (default_get)', async function (assert) {
assert.expect(1);
this.data.partner.records[0].display_name = "MyTrululu";
this.data.partner.fields.p.default = [
[0, 0, { trululu: 1, p: [] }],
[0, 0, { trululu: 1, p: [] }]
];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'name_get') {
throw new Error('should not call name_get');
}
return this._super.apply(this, arguments);
},
});
assert.strictEqual(form.$('td.o_data_cell').text(), "MyTrululuMyTrululu",
"both records should have the correct display_name for trululu field");
form.destroy();
});
QUnit.test('list in form: show name of many2one fields in multi-page (default_get)', async function (assert) {
assert.expect(4);
this.data.partner.fields.p.default = [
[0, 0, { display_name: 'record1', trululu: 1, p: [] }],
[0, 0, { display_name: 'record2', trululu: 2, p: [] }]
];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom" limit="1">' +
'<field name="display_name"/>' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
});
assert.strictEqual(form.$('td.o_data_cell').first().text(),
"record1", "should show display_name of 1st record");
assert.strictEqual(form.$('td.o_data_cell').first().next().text(),
"first record", "should show display_name of trululu of 1st record");
await testUtils.dom.click(form.$('button.o_pager_next'));
assert.strictEqual(form.$('td.o_data_cell').first().text(),
"record2", "should show display_name of 2nd record");
assert.strictEqual(form.$('td.o_data_cell').first().next().text(),
"second record", "should show display_name of trululu of 2nd record");
form.destroy();
});
QUnit.test('list in form: item not dropped on discard with empty required field (onchange in default_get)', async function (assert) {
// variant of the test "list in form: discard newly added element with
// empty required field (default_get)", in which the `default_get`
// performs an `onchange` at the same time. This `onchange` may create
// some records, which should not be abandoned on discard, similarly
// to records created directly by `default_get`
assert.expect(7);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
this.data.partner.fields.product_id.default = 37;
this.data.partner.onchanges = {
product_id: function (obj) {
if (obj.product_id === 37) {
obj.p = [[0, 0, { display_name: "entry", trululu: false }]];
}
},
};
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="product_id"/>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu" required="1"/>' +
'</tree>' +
'</field>' +
'</form>',
});
// check that there is a record in the editable list with empty string as required field
assert.containsOnce(form, '.o_data_row',
"should have a row in the editable list");
assert.strictEqual($('td.o_data_cell').first().text(), "entry",
"should have the correct displayed name");
var requiredField = $('td.o_data_cell.o_required_modifier');
assert.strictEqual(requiredField.length, 1,
"should have a required field on this record");
assert.strictEqual(requiredField.text(), "",
"should have empty string in the required field on this record");
// click on empty required field in editable list record
testUtils.dom.click(requiredField);
// click off so that the required field still stay empty
testUtils.dom.click($('body'));
// record should not be dropped
assert.containsOnce(form, '.o_data_row',
"should not have dropped record in the editable list");
assert.strictEqual($('td.o_data_cell').first().text(), "entry",
"should still have the correct displayed name");
assert.strictEqual($('td.o_data_cell.o_required_modifier').text(), "",
"should still have empty string in the required field");
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
form.destroy();
});
QUnit.test('list in form: item not dropped on discard with empty required field (onchange on list after default_get)', async function (assert) {
// discarding a record from an `onchange` in a `default_get` should not
// abandon the record. This should not be the case for following
// `onchange`, except if an onchange make some changes on the list:
// in particular, if an onchange make changes on the list such that
// a record is added, this record should not be dropped on discard
assert.expect(8);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
this.data.partner.onchanges = {
product_id: function (obj) {
if (obj.product_id === 37) {
obj.p = [[0, 0, { display_name: "entry", trululu: false }]];
}
},
};
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="product_id"/>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu" required="1"/>' +
'</tree>' +
'</field>' +
'</form>',
});
// check no record in list
assert.containsNone(form, '.o_data_row',
"should have no row in the editable list");
// select product_id to force on_change in editable list
await testUtils.dom.click(form.$('.o_field_widget[name="product_id"] .o_input'));
await testUtils.dom.click($('.ui-menu-item').first());
// check that there is a record in the editable list with empty string as required field
assert.containsOnce(form, '.o_data_row',
"should have a row in the editable list");
assert.strictEqual($('td.o_data_cell').first().text(), "entry",
"should have the correct displayed name");
var requiredField = $('td.o_data_cell.o_required_modifier');
assert.strictEqual(requiredField.length, 1,
"should have a required field on this record");
assert.strictEqual(requiredField.text(), "",
"should have empty string in the required field on this record");
// click on empty required field in editable list record
await testUtils.dom.click(requiredField);
// click off so that the required field still stay empty
await testUtils.dom.click($('body'));
// record should not be dropped
assert.containsOnce(form, '.o_data_row',
"should not have dropped record in the editable list");
assert.strictEqual($('td.o_data_cell').first().text(), "entry",
"should still have the correct displayed name");
assert.strictEqual($('td.o_data_cell.o_required_modifier').text(), "",
"should still have empty string in the required field");
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
form.destroy();
});
QUnit.test('item dropped on discard with empty required field with "Add an item" (invalid on "ADD")', async function (assert) {
// when a record in a list is added with "Add an item", it should
// always be dropped on discard if some required field are empty
// at the record creation.
assert.expect(6);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu" required="1"/>' +
'</tree>' +
'</field>' +
'</form>',
});
// Click on "Add an item"
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
var charField = form.$('.o_field_widget.o_field_char[name="display_name"]');
var requiredField = form.$('.o_field_widget.o_required_modifier[name="trululu"]');
charField.val("some text");
assert.strictEqual(charField.length, 1,
"should have a char field 'display_name' on this record");
assert.doesNotHaveClass(charField, 'o_required_modifier',
"the char field should not be required on this record");
assert.strictEqual(charField.val(), "some text",
"should have entered text in the char field on this record");
assert.strictEqual(requiredField.length, 1,
"should have a required field 'trululu' on this record");
assert.strictEqual(requiredField.val().trim(), "",
"should have empty string in the required field on this record");
// click on empty required field in editable list record
await testUtils.dom.click(requiredField);
// click off so that the required field still stay empty
await testUtils.dom.click($('body'));
// record should be dropped
assert.containsNone(form, '.o_data_row',
"should have dropped record in the editable list");
form.destroy();
});
QUnit.test('item not dropped on discard with empty required field with "Add an item" (invalid on "UPDATE")', async function (assert) {
// when a record in a list is added with "Add an item", it should
// be temporarily added to the list when it is valid (e.g. required
// fields are non-empty). If the record is updated so that the required
// field is empty, and it is discarded, then the record should not be
// dropped.
assert.expect(8);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="trululu" required="1"/>' +
'</tree>' +
'</field>' +
'</form>',
});
assert.containsNone(form, '.o_data_row',
"should initially not have any record in the list");
// Click on "Add an item"
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
assert.containsOnce(form, '.o_data_row',
"should have a temporary record in the list");
var $inputEditMode = form.$('.o_field_widget.o_required_modifier[name="trululu"] input');
assert.strictEqual($inputEditMode.length, 1,
"should have a required field 'trululu' on this record");
assert.strictEqual($inputEditMode.val(), "",
"should have empty string in the required field on this record");
// add something to required field and leave edit mode of the record
await testUtils.dom.click($inputEditMode);
await testUtils.dom.click($('li.ui-menu-item').first());
await testUtils.dom.click($('body'));
var $inputReadonlyMode = form.$('.o_data_cell.o_required_modifier');
assert.containsOnce(form, '.o_data_row',
"should not have dropped valid record when leaving edit mode");
assert.strictEqual($inputReadonlyMode.text(), "first record",
"should have put some content in the required field on this record");
// remove the required field and leave edit mode of the record
await testUtils.dom.click($('.o_data_row'));
assert.containsOnce(form, '.o_data_row',
"should not have dropped record in the list on discard (invalid on UPDATE)");
assert.strictEqual($inputReadonlyMode.text(), "first record",
"should keep previous valid required field content on this record");
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
form.destroy();
});
QUnit.test('list in form: default_get with x2many create', async function (assert) {
assert.expect(3);
this.data.partner.fields.timmy.default = [
[0, 0, { display_name: 'brandon is the new timmy', name: 'brandon' }]
];
var displayName = 'brandon is the new timmy';
this.data.partner.onchanges.timmy = function (obj) {
obj.int_field = obj.timmy.length;
};
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="timmy">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'</tree>' +
'</field>' +
'<field name="int_field"/>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'create') {
assert.deepEqual(args.args[0], {
int_field: 2,
timmy: [
[6, false, []],
// LPE TODO 1 taskid-2261084: remove this entire comment including code snippet
// when the change in behavior has been thoroughly tested.
// We can't distinguish a value coming from a default_get
// from one coming from the onchange, and so we can either store and
// send it all the time, or never.
// [0, args.args[0].timmy[1][1], { display_name: displayName, name: 'brandon' }],
[0, args.args[0].timmy[1][1], { display_name: displayName }],
],
}, "should send the correct values to create");
}
return this._super.apply(this, arguments);
},
});
assert.strictEqual($('td.o_data_cell:first').text(), 'brandon is the new timmy',
"should have created the new record in the m2m with the correct name");
assert.strictEqual($('input.o_field_integer').val(), '1',
"should have called and executed the onchange properly");
// edit the subrecord and save
displayName = 'new value';
await testUtils.dom.click(form.$('.o_data_cell'));
await testUtils.fields.editInput(form.$('.o_data_cell input'), displayName);
await testUtils.form.clickSave(form);
form.destroy();
});
QUnit.test('list in form: default_get with x2many create and onchange', async function (assert) {
assert.expect(1);
this.data.partner.fields.turtles.default = [[6, 0, [2, 3]]];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="turtles">' +
'<tree editable="bottom">' +
'<field name="turtle_foo"/>' +
'</tree>' +
'</field>' +
'<field name="int_field"/>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (args.method === 'create') {
assert.deepEqual(args.args[0].turtles, [
[4, 2, false],
[4, 3, false],
], 'should send proper commands to create method');
}
return this._super.apply(this, arguments);
},
});
await testUtils.form.clickSave(form);
form.destroy();
});
QUnit.test('list in form: call button in sub view', async function (assert) {
assert.expect(11);
this.data.partner.records[0].p = [2];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<sheet>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="product_id"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (route === '/web/dataset/call_kw/product/get_formview_id') {
return Promise.resolve(false);
}
return this._super.apply(this, arguments);
},
intercepts: {
execute_action: function (event) {
assert.strictEqual(event.data.env.model, 'product',
'should call with correct model in env');
assert.strictEqual(event.data.env.currentID, 37,
'should call with correct currentID in env');
assert.deepEqual(event.data.env.resIDs, [37],
'should call with correct resIDs in env');
assert.step(event.data.action_data.name);
},
},
archs: {
'product,false,form': '<form string="Partners">' +
'<header>' +
'<button name="action" type="action" string="Just do it !"/>' +
'<button name="object" type="object" string="Just don\'t do it !"/>' +
'<field name="display_name"/>' +
'</header>' +
'</form>',
},
});
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('td.o_data_cell:first'));
await testUtils.dom.click(form.$('.o_external_button'));
await testUtils.dom.click($('button:contains("Just do it !")'));
assert.verifySteps(['action']);
await testUtils.dom.click($('button:contains("Just don\'t do it !")'));
assert.verifySteps([]); // the second button is disabled, it can't be clicked
await testUtils.dom.click($('.modal .btn-secondary:contains(Discard)'));
await testUtils.dom.click(form.$('.o_external_button'));
await testUtils.dom.click($('button:contains("Just don\'t do it !")'));
assert.verifySteps(['object']);
form.destroy();
});
QUnit.test('X2Many sequence list in modal', async function (assert) {
assert.expect(5);
this.data.partner.fields.sequence = { string: 'Sequence', type: 'integer' };
this.data.partner.records[0].sequence = 1;
this.data.partner.records[1].sequence = 2;
this.data.partner.onchanges = {
sequence: function (obj) {
if (obj.id === 2) {
obj.sequence = 1;
assert.step('onchange sequence');
}
},
};
this.data.product.fields.turtle_ids = { string: 'Turtles', type: 'one2many', relation: 'turtle' };
this.data.product.records[0].turtle_ids = [1];
this.data.turtle.fields.partner_types_ids = { string: "Partner", type: "one2many", relation: 'partner' };
this.data.turtle.fields.type_id = { string: "Partner Type", type: "many2one", relation: 'partner_type' };
this.data.partner_type.fields.partner_ids = { string: "Partner", type: "one2many", relation: 'partner' };
this.data.partner_type.records[0].partner_ids = [1, 2];
var form = await createView({
View: FormView,
model: 'product',
data: this.data,
arch: '<form>' +
'<field name="name"/>' +
'<field name="turtle_ids" widget="one2many">' +
'<tree string="Turtles" editable="bottom">' +
'<field name="type_id"/>' +
'</tree>' +
'</field>' +
'</form>',
archs: {
'partner_type,false,form': '<form><field name="partner_ids"/></form>',
'partner,false,list': '<tree string="Vendors">' +
'<field name="display_name"/>' +
'<field name="sequence" widget="handle"/>' +
'</tree>',
},
res_id: 37,
mockRPC: function (route, args) {
if (route === '/web/dataset/call_kw/product/read') {
return Promise.resolve([{ id: 37, name: 'xphone', display_name: 'leonardo', turtle_ids: [1] }]);
}
if (route === '/web/dataset/call_kw/turtle/read') {
return Promise.resolve([{ id: 1, type_id: [12, 'gold'] }]);
}
if (route === '/web/dataset/call_kw/partner_type/get_formview_id') {
return Promise.resolve(false);
}
if (route === '/web/dataset/call_kw/partner_type/read') {
return Promise.resolve([{ id: 12, partner_ids: [1, 2], display_name: 'gold' }]);
}
if (route === '/web/dataset/call_kw/partner_type/write') {
assert.step('partner_type write');
}
return this._super.apply(this, arguments);
},
});
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_data_cell'));
await testUtils.dom.click(form.$('.o_external_button'));
var $modal = $('.modal');
assert.equal($modal.length, 1,
'There should be 1 modal opened');
var $handles = $modal.find('.ui-sortable-handle');
assert.equal($handles.length, 2,
'There should be 2 sequence handlers');
await testUtils.dom.dragAndDrop($handles.eq(1),
$modal.find('tbody tr').first(), { position: 'top' });
// Saving the modal and then the original model
await testUtils.dom.click($modal.find('.modal-footer .btn-primary'));
await testUtils.form.clickSave(form);
assert.verifySteps(['onchange sequence', 'partner_type write']);
form.destroy();
});
QUnit.test('autocompletion in a many2one, in form view with a domain', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="product_id"/>' +
'</form>',
res_id: 1,
viewOptions: {
domain: [['trululu', '=', 4]]
},
mockRPC: function (route, args) {
if (args.method === 'name_search') {
assert.deepEqual(args.kwargs.args, [], "should not have a domain");
}
return this._super(route, args);
}
});
await testUtils.form.clickEdit(form);
testUtils.dom.click(form.$('.o_field_widget[name=product_id] input'));
form.destroy();
});
QUnit.test('autocompletion in a many2one, in form view with a date field', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="bar"/>' +
'<field name="date"/>' +
'<field name="trululu" domain="[(\'bar\',\'=\',True)]"/>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (args.method === 'name_search') {
assert.deepEqual(args.kwargs.args, [["bar", "=", true]], "should not have a domain");
}
return this._super(route, args);
},
});
await testUtils.form.clickEdit(form);
testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
form.destroy();
});
QUnit.test('creating record with many2one with option always_reload', async function (assert) {
assert.expect(2);
this.data.partner.fields.trululu.default = 1;
this.data.partner.onchanges = {
trululu: function (obj) {
obj.trululu = 2; //[2, "second record"];
},
};
var count = 0;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="trululu" options="{\'always_reload\': True}"/>' +
'</form>',
mockRPC: function (route, args) {
count++;
if (args.method === 'name_get' && args.args[0] === 2) {
return Promise.resolve([[2, "hello world\nso much noise"]]);
}
return this._super(route, args);
},
});
assert.strictEqual(count, 2, "should have done 2 rpcs (onchange and name_get)");
assert.strictEqual(form.$('.o_field_widget[name=trululu] input').val(), 'hello world',
"should have taken the correct display name");
form.destroy();
});
QUnit.test('selecting a many2one, then discarding', async function (assert) {
assert.expect(3);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="product_id"/>' +
'</form>',
res_id: 1,
});
assert.strictEqual(form.$('a[name=product_id]').text(), '', 'the tag a should be empty');
await testUtils.form.clickEdit(form);
await testUtils.fields.many2one.clickOpenDropdown('product_id');
await testUtils.fields.many2one.clickItem('product_id','xphone');
assert.strictEqual(form.$('.o_field_widget[name=product_id] input').val(), "xphone", "should have selected xphone");
await testUtils.form.clickDiscard(form);
assert.strictEqual(form.$('a[name=product_id]').text(), '', 'the tag a should be empty');
form.destroy();
});
QUnit.test('domain and context are correctly used when doing a name_search in a m2o', async function (assert) {
assert.expect(4);
this.data.partner.records[0].timmy = [12];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch:
'<form string="Partners">' +
'<field name="product_id" ' +
'domain="[[\'foo\', \'=\', \'bar\'], [\'foo\', \'=\', foo]]" ' +
'context="{\'hello\': \'world\', \'test\': foo}"/>' +
'<field name="foo"/>' +
'<field name="trululu" context="{\'timmy\': timmy}" domain="[[\'id\', \'in\', timmy]]"/>' +
'<field name="timmy" widget="many2many_tags" invisible="1"/>' +
'</form>',
res_id: 1,
session: { user_context: { hey: "ho" } },
mockRPC: function (route, args) {
if (args.method === 'name_search' && args.model === 'product') {
assert.deepEqual(
args.kwargs.args,
[['foo', '=', 'bar'], ['foo', '=', 'yop']],
'the field attr domain should have been used for the RPC (and evaluated)');
assert.deepEqual(
args.kwargs.context,
{ hey: "ho", hello: "world", test: "yop" },
'the field attr context should have been used for the ' +
'RPC (evaluated and merged with the session one)');
return Promise.resolve([]);
}
if (args.method === 'name_search' && args.model === 'partner') {
assert.deepEqual(args.kwargs.args, [['id', 'in', [12]]],
'the field attr domain should have been used for the RPC (and evaluated)');
assert.deepEqual(args.kwargs.context, { hey: 'ho', timmy: [[6, false, [12]]] },
'the field attr context should have been used for the RPC (and evaluated)');
return Promise.resolve([]);
}
return this._super.apply(this, arguments);
},
});
await testUtils.form.clickEdit(form);
testUtils.dom.click(form.$('.o_field_widget[name=product_id] input'));
testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
form.destroy();
});
QUnit.test('quick create on a many2one', async function (assert) {
assert.expect(2);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="product_id"/>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (route === '/web/dataset/call_kw/product/name_create') {
assert.strictEqual(args.args[0], 'new partner',
"should name create a new product");
}
return this._super.apply(this, arguments);
},
});
await testUtils.dom.triggerEvent(form.$('.o_field_many2one input'),'focus');
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one input'),
'new partner', ['keyup', 'blur']);
await testUtils.dom.click($('.modal .modal-footer .btn-primary').first());
assert.strictEqual($('.modal .modal-body').text().trim(), "Do you want to create new partner as a new Product?");
form.destroy();
});
QUnit.test('failing quick create on a many2one', async function (assert) {
assert.expect(4);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="product_id"/></form>',
archs: {
'product,false,form': '<form><field name="name"/></form>',
},
mockRPC(route, args) {
if (args.method === 'name_create') {
return Promise.reject();
}
if (args.method === 'create') {
assert.deepEqual(args.args[0], { name: 'xyz' });
}
return this._super(...arguments);
},
});
await testUtils.fields.many2one.searchAndClickItem('product_id', {
search: 'abcd',
item: 'Create "abcd"',
});
assert.containsOnce(document.body, '.modal .o_form_view');
assert.strictEqual($('.o_field_widget[name=name]').val(), 'abcd');
await testUtils.fields.editInput($('.modal .o_field_widget[name=name]'), 'xyz');
await testUtils.dom.click($('.modal .modal-footer .btn-primary'));
assert.strictEqual(form.$('.o_field_widget[name=product_id] input').val(), 'xyz');
form.destroy();
});
QUnit.test('failing quick create on a many2one inside a one2many', async function (assert) {
assert.expect(4);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="p"/></form>',
archs: {
'partner,false,list': '<tree editable="bottom"><field name="product_id"/></tree>',
'product,false,form': '<form><field name="name"/></form>',
},
mockRPC(route, args) {
if (args.method === 'name_create') {
return Promise.reject();
}
if (args.method === 'create') {
assert.deepEqual(args.args[0], { name: 'xyz' });
}
return this._super(...arguments);
},
});
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
await testUtils.fields.many2one.searchAndClickItem('product_id', {
search: 'abcd',
item: 'Create "abcd"',
});
assert.containsOnce(document.body, '.modal .o_form_view');
assert.strictEqual($('.o_field_widget[name=name]').val(), 'abcd');
await testUtils.fields.editInput($('.modal .o_field_widget[name=name]'), 'xyz');
await testUtils.dom.click($('.modal .modal-footer .btn-primary'));
assert.strictEqual(form.$('.o_field_widget[name=product_id] input').val(), 'xyz');
form.destroy();
});
QUnit.test('slow create on a many2one', async function (assert) {
assert.expect(11);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch:
'<form>' +
'<sheet>' +
'<field name="product_id" options="{\'quick_create\': False}"/>' +
'</sheet>' +
'</form>',
archs: {
'product,false,form':
'<form>' +
'<field name="name"/>' +
'</form>',
},
});
// cancel the many2one creation with Cancel button
form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur');
await testUtils.nextTick();
assert.strictEqual($('.modal').length, 1, "there should be one opened modal");
await testUtils.dom.click($('.modal .modal-footer .btn:contains(Cancel)'));
assert.strictEqual($('.modal').length, 0, "the modal should be closed");
assert.strictEqual(form.$('.o_field_many2one input').val(), "",
'the many2one should not set a value as its creation has been cancelled (with Cancel button)');
// cancel the many2one creation with Close button
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one input'),
'new product', ['keyup', 'blur']);
assert.strictEqual($('.modal').length, 1, "there should be one opened modal");
await testUtils.dom.click($('.modal .modal-header button'));
assert.strictEqual(form.$('.o_field_many2one input').val(), "",
'the many2one should not set a value as its creation has been cancelled (with Close button)');
assert.strictEqual($('.modal').length, 0, "the modal should be closed");
// select a new value then cancel the creation of the new one --> restore the previous
await testUtils.fields.many2one.clickOpenDropdown('product_id');
await testUtils.fields.many2one.clickItem('product_id','o');
assert.strictEqual(form.$('.o_field_many2one input').val(), "xphone", "should have selected xphone");
form.$('.o_field_many2one input').focus().val('new product').trigger('keyup').trigger('blur');
await testUtils.nextTick();
assert.strictEqual($('.modal').length, 1, "there should be one opened modal");
await testUtils.dom.click($('.modal .modal-footer .btn:contains(Cancel)'));
assert.strictEqual(form.$('.o_field_many2one input').val(), "xphone",
'should have restored the many2one with its previous selected value (xphone)');
// confirm the many2one creation
form.$('.o_field_many2one input').focus().val('new partner').trigger('keyup').trigger('blur');
await testUtils.nextTick();
assert.strictEqual($('.modal').length, 1, "there should be one opened modal");
await testUtils.dom.click($('.modal .modal-footer .btn-primary:contains(Create and edit)'));
await testUtils.nextTick();
assert.strictEqual($('.modal .o_form_view').length, 1,
'a new modal should be opened and contain a form view');
await testUtils.dom.click($('.modal .o_form_button_cancel'));
form.destroy();
});
QUnit.test('no_create option on a many2one', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="product_id" options="{\'no_create\': True}"/>' +
'</sheet>' +
'</form>',
});
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one input'),
'new partner', ['keyup', 'focusout']);
await testUtils.nextTick();
assert.strictEqual($('.modal').length, 0, "should not display the create modal");
form.destroy();
});
QUnit.test('can_create and can_write option on a many2one', async function (assert) {
assert.expect(5);
this.data.product.options = {
can_create: "false",
can_write: "false",
};
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="product_id" can_create="false" can_write="false"/>' +
'</sheet>' +
'</form>',
archs: {
'product,false,form': '<form string="Products"><field name="display_name"/></form>',
},
mockRPC: function (route) {
if (route === '/web/dataset/call_kw/product/get_formview_id') {
return Promise.resolve(false);
}
return this._super.apply(this, arguments);
},
});
await testUtils.dom.click(form.$('.o_field_many2one input'));
assert.strictEqual($('.ui-autocomplete .o_m2o_dropdown_option:contains(Create)').length, 0,
"there shouldn't be any option to search and create");
await testUtils.dom.click($('.ui-autocomplete li:contains(xpad)').mouseenter());
assert.strictEqual(form.$('.o_field_many2one input').val(), "xpad",
"the correct record should be selected");
assert.containsOnce(form, '.o_field_many2one .o_external_button',
"there should be an external button displayed");
await testUtils.dom.click(form.$('.o_field_many2one .o_external_button'));
assert.strictEqual($('.modal .o_form_view.o_form_readonly').length, 1,
"there should be a readonly form view opened");
await testUtils.dom.click($('.modal .o_form_button_cancel'));
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one input'),
'new product', ['keyup', 'focusout']);
assert.strictEqual($('.modal').length, 0, "should not display the create modal");
form.destroy();
});
QUnit.test('pressing enter in a m2o in an editable list', async function (assert) {
assert.expect(9);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var list = await createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree editable="bottom"><field name="product_id"/></tree>',
});
await testUtils.dom.click(list.$('td.o_data_cell:first'));
assert.containsOnce(list, '.o_selected_row',
"should have a row in edit mode");
// we now write 'a' and press enter to check that the selection is
// working, and prevent the navigation
await testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a');
var $input = list.$('td.o_data_cell input:first');
var $dropdown = $input.autocomplete('widget');
assert.ok($dropdown.is(':visible'), "autocomplete dropdown should be visible");
// we now trigger ENTER to select first choice
await testUtils.fields.triggerKeydown($input, 'enter');
assert.strictEqual($input[0], document.activeElement,
"input should still be focused");
// we now trigger again ENTER to make sure we can move to next line
await testUtils.fields.triggerKeydown($input, 'enter');
assert.notOk(document.contains($input[0]),
"input should no longer be in dom");
assert.hasClass(list.$('tr.o_data_row:eq(1)'),'o_selected_row',
"second row should now be selected");
// we now write again 'a' in the cell to select xpad. We will now
// test with the tab key
await testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a');
var $input = list.$('td.o_data_cell input:first');
var $dropdown = $input.autocomplete('widget');
assert.ok($dropdown.is(':visible'), "autocomplete dropdown should be visible");
await testUtils.fields.triggerKeydown($input, 'tab');
assert.strictEqual($input[0], document.activeElement,
"input should still be focused");
// we now trigger again ENTER to make sure we can move to next line
await testUtils.fields.triggerKeydown($input, 'tab');
assert.notOk(document.contains($input[0]),
"input should no longer be in dom");
assert.hasClass(list.$('tr.o_data_row:eq(2)'),'o_selected_row',
"third row should now be selected");
list.destroy();
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
});
QUnit.test('pressing ENTER on a \'no_quick_create\' many2one should open a M2ODialog', async function (assert) {
assert.expect(2);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="trululu" options="{\'no_quick_create\': True}"/>' +
'<field name="foo"/>' +
'</form>',
archs: {
'partner,false,form': '<form string="Partners"><field name="display_name"/></form>',
},
});
var $input = form.$('.o_field_many2one input');
await testUtils.fields.editInput($input, "Something that does not exist");
$('.ui-autocomplete .ui-menu-item a:contains(Create and)').trigger('mouseenter');
await testUtils.nextTick();
await testUtils.fields.triggerKey('down', $input, 'enter')
await testUtils.fields.triggerKey('press', $input, 'enter')
await testUtils.fields.triggerKey('up', $input, 'enter')
$input.blur();
assert.strictEqual($('.modal').length, 1,
"should have one modal in body");
// Check that discarding clears $input
await testUtils.dom.click($('.modal .o_form_button_cancel'));
assert.strictEqual($input.val(), '',
"the field should be empty");
form.destroy();
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
});
QUnit.test('select a value by pressing TAB on a many2one with onchange', async function (assert) {
assert.expect(3);
this.data.partner.onchanges.trululu = function () { };
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var prom = testUtils.makeTestPromise();
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="trululu"/>' +
'<field name="display_name"/>' +
'</form>',
mockRPC: function (route, args) {
var result = this._super.apply(this, arguments);
if (args.method === 'onchange') {
return prom.then(_.constant(result));
}
return result;
},
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
var $input = form.$('.o_field_many2one input');
await testUtils.fields.editInput($input, "first");
await testUtils.fields.triggerKey('down', $input, 'tab');
await testUtils.fields.triggerKey('press', $input, 'tab');
await testUtils.fields.triggerKey('up', $input, 'tab');
// simulate a focusout (e.g. because the user clicks outside)
// before the onchange returns
form.$('.o_field_char').focus();
assert.strictEqual($('.modal').length, 0,
"there shouldn't be any modal in body");
// unlock the onchange
prom.resolve();
await testUtils.nextTick();
assert.strictEqual($input.val(), 'first record',
"first record should have been selected");
assert.strictEqual($('.modal').length, 0,
"there shouldn't be any modal in body");
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
form.destroy();
});
QUnit.test('many2one in editable list + onchange, with enter [REQUIRE FOCUS]', async function (assert) {
assert.expect(6);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
this.data.partner.onchanges.product_id = function (obj) {
obj.int_field = obj.product_id || 0;
};
var prom = testUtils.makeTestPromise();
var list = await createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree editable="bottom"><field name="product_id"/><field name="int_field"/></tree>',
mockRPC: function (route, args) {
if (args.method) {
assert.step(args.method);
}
var result = this._super.apply(this, arguments);
if (args.method === 'onchange') {
return prom.then(_.constant(result));
}
return result;
},
});
await testUtils.dom.click(list.$('td.o_data_cell:first'));
await testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a');
var $input = list.$('td.o_data_cell input:first');
await testUtils.fields.triggerKeydown($input, 'enter');
await testUtils.fields.triggerKey('up', $input, 'enter');
prom.resolve();
await testUtils.nextTick();
await testUtils.fields.triggerKeydown($input, 'enter');
assert.strictEqual($('.modal').length, 0, "should not have any modal in DOM");
assert.verifySteps(['name_search', 'onchange', 'write', 'read']);
list.destroy();
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
});
QUnit.test('many2one in editable list + onchange, with enter, part 2 [REQUIRE FOCUS]', async function (assert) {
// this is the same test as the previous one, but the onchange is just
// resolved slightly later
assert.expect(6);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
this.data.partner.onchanges.product_id = function (obj) {
obj.int_field = obj.product_id || 0;
};
var prom = testUtils.makeTestPromise();
var list = await createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree editable="bottom"><field name="product_id"/><field name="int_field"/></tree>',
mockRPC: function (route, args) {
if (args.method) {
assert.step(args.method);
}
var result = this._super.apply(this, arguments);
if (args.method === 'onchange') {
return prom.then(_.constant(result));
}
return result;
},
});
await testUtils.dom.click(list.$('td.o_data_cell:first'));
await testUtils.fields.editInput(list.$('td.o_data_cell input:first'), 'a');
var $input = list.$('td.o_data_cell input:first');
await testUtils.fields.triggerKeydown($input, 'enter');
await testUtils.fields.triggerKey('up', $input, 'enter');
await testUtils.fields.triggerKeydown($input, 'enter');
prom.resolve();
await testUtils.nextTick();
assert.strictEqual($('.modal').length, 0, "should not have any modal in DOM");
assert.verifySteps(['name_search', 'onchange', 'write', 'read']);
list.destroy();
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
});
QUnit.test('many2one: domain updated by an onchange', async function (assert) {
assert.expect(2);
this.data.partner.onchanges = {
int_field: function () { },
};
var domain = [];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="int_field"/>' +
'<field name="trululu"/>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'onchange') {
domain = [['id', 'in', [10]]];
return Promise.resolve({
domain: {
trululu: domain,
unexisting_field: domain,
}
});
}
if (args.method === 'name_search') {
assert.deepEqual(args.kwargs.args, domain,
"sent domain should be correct");
}
return this._super(route, args);
},
viewOptions: {
mode: 'edit',
},
});
// trigger a name_search (domain should be [])
await testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
// close the dropdown
await testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
// trigger an onchange that will update the domain
await testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 2);
// trigger a name_search (domain should be [['id', 'in', [10]]])
await testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
form.destroy();
});
QUnit.test('many2one in one2many: domain updated by an onchange', async function (assert) {
assert.expect(3);
this.data.partner.onchanges = {
trululu: function () { },
};
var domain = [];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'onchange') {
return Promise.resolve({
domain: {
trululu: domain,
},
});
}
if (args.method === 'name_search') {
assert.deepEqual(args.kwargs.args, domain,
"sent domain should be correct");
}
return this._super(route, args);
},
viewOptions: {
mode: 'edit',
},
});
// add a first row with a specific domain for the m2o
domain = [['id', 'in', [10]]]; // domain for subrecord 1
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
await testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
// add a second row with another domain for the m2o
domain = [['id', 'in', [5]]]; // domain for subrecord 2
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
await testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
// check again the first row to ensure that the domain hasn't change
domain = [['id', 'in', [10]]]; // domain for subrecord 1 should have been kept
await testUtils.dom.click(form.$('.o_data_row:first .o_data_cell'));
await testUtils.dom.click(form.$('.o_field_widget[name=trululu] input'));
form.destroy();
});
QUnit.test('search more in many2one: no text in input', async function (assert) {
// when the user clicks on 'Search More...' in a many2one dropdown, and there is no text
// in the input (i.e. no value to search on), we bypass the name_search that is meant to
// return a list of preselected ids to filter on in the list view (opened in a dialog)
assert.expect(6);
for (var i = 0; i < 8; i++) {
this.data.partner.records.push({id: 100 + i, display_name: 'test_' + i});
}
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="trululu"/></form>',
archs: {
'partner,false,list': '<list><field name="display_name"/></list>',
'partner,false,search': '<search></search>',
},
mockRPC: function (route, args) {
assert.step(args.method || route);
if (route === '/web/dataset/search_read') {
assert.deepEqual(args.domain, [],
"should not preselect ids as there as nothing in the m2o input");
}
return this._super.apply(this, arguments);
},
});
await testUtils.fields.many2one.searchAndClickItem('trululu', {
item: 'Search More',
search: '',
});
assert.verifySteps([
'onchange',
'name_search', // to display results in the dropdown
'load_views', // list view in dialog
'/web/dataset/search_read', // to display results in the dialog
]);
form.destroy();
});
QUnit.test('search more in many2one: text in input', async function (assert) {
// when the user clicks on 'Search More...' in a many2one dropdown, and there is some
// text in the input, we perform a name_search to get a (limited) list of preselected
// ids and we add a dynamic filter (with those ids) to the search view in the dialog, so
// that the user can remove this filter to bypass the limit
assert.expect(12);
for (var i = 0; i < 8; i++) {
this.data.partner.records.push({id: 100 + i, display_name: 'test_' + i});
}
var expectedDomain;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="trululu"/></form>',
archs: {
'partner,false,list': '<list><field name="display_name"/></list>',
'partner,false,search': '<search></search>',
},
mockRPC: function (route, args) {
assert.step(args.method || route);
if (route === '/web/dataset/search_read') {
assert.deepEqual(args.domain, expectedDomain);
}
return this._super.apply(this, arguments);
},
});
expectedDomain = [['id', 'in', [100, 101, 102, 103, 104, 105, 106, 107]]];
await testUtils.fields.many2one.searchAndClickItem('trululu', {
item: 'Search More',
search: 'test',
});
assert.containsOnce(document.body, '.modal .o_list_view');
assert.containsOnce(document.body, '.modal .o_cp_searchview .o_facet_values',
"should have a special facet for the pre-selected ids");
// remove the filter on ids
expectedDomain = [];
await testUtils.dom.click($('.modal .o_cp_searchview .o_facet_remove'));
assert.verifySteps([
'onchange',
'name_search', // empty search, triggered when the user clicks in the input
'name_search', // to display results in the dropdown
'name_search', // to get preselected ids matching the search
'load_views', // list view in dialog
'/web/dataset/search_read', // to display results in the dialog
'/web/dataset/search_read', // after removal of dynamic filter
]);
form.destroy();
});
QUnit.test('search more in many2one: dropdown click', async function (assert) {
assert.expect(8);
for (let i = 0; i < 8; i++) {
this.data.partner.records.push({id: 100 + i, display_name: 'test_' + i});
}
// simulate modal-like element rendered by the field html
const $fakeDialog = $(`<div>
<div class="pouet">
<div class="modal"></div>
</div>
</div>`);
$('body').append($fakeDialog);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="trululu"/></form>',
archs: {
'partner,false,list': '<list><field name="display_name"/></list>',
'partner,false,search': '<search></search>',
},
});
await testUtils.fields.many2one.searchAndClickItem('trululu', {
item: 'Search More',
search: 'test',
});
// dropdown selector
let filterMenuCss = '.o_search_options > .o_filter_menu';
let groupByMenuCss = '.o_search_options > .o_group_by_menu';
await testUtils.dom.click(document.querySelector(`${filterMenuCss} > .o_dropdown_toggler_btn`));
assert.hasClass(document.querySelector(filterMenuCss), 'show');
assert.isVisible(document.querySelector(`${filterMenuCss} > .dropdown-menu`),
"the filter dropdown menu should be visible");
assert.doesNotHaveClass(document.querySelector(groupByMenuCss), 'show');
assert.isNotVisible(document.querySelector(`${groupByMenuCss} > .dropdown-menu`),
"the Group by dropdown menu should be not visible");
await testUtils.dom.click(document.querySelector(`${groupByMenuCss} > .o_dropdown_toggler_btn`));
assert.hasClass(document.querySelector(groupByMenuCss), 'show');
assert.isVisible(document.querySelector(`${groupByMenuCss} > .dropdown-menu`),
"the group by dropdown menu should be visible");
assert.doesNotHaveClass(document.querySelector(filterMenuCss), 'show');
assert.isNotVisible(document.querySelector(`${filterMenuCss} > .dropdown-menu`),
"the filter dropdown menu should be not visible");
$fakeDialog.remove();
form.destroy();
});
QUnit.test('updating a many2one from a many2many', async function (assert) {
assert.expect(4);
this.data.turtle.records[1].turtle_trululu = 1;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<group>' +
'<field name="turtles">' +
'<tree editable="bottom">' +
'<field name="display_name"/>' +
'<field name="turtle_trululu"/>' +
'</tree>' +
'</field>' +
'</group>' +
'</form>',
res_id: 1,
archs: {
'partner,false,form': '<form string="Trululu"><field name="display_name"/></form>',
},
mockRPC: function (route, args) {
if (args.method === 'get_formview_id') {
assert.deepEqual(args.args[0], [1], "should call get_formview_id with correct id");
return Promise.resolve(false);
}
return this._super(route, args);
},
});
// Opening the modal
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_data_row td:contains(first record)'));
await testUtils.dom.click(form.$('.o_external_button'));
assert.strictEqual($('.modal').length, 1,
"should have one modal in body");
// Changing the 'trululu' value
await testUtils.fields.editInput($('.modal input[name="display_name"]'), 'test');
await testUtils.dom.click($('.modal button.btn-primary'));
// Test whether the value has changed
assert.strictEqual($('.modal').length, 0,
"the modal should be closed");
assert.equal(form.$('.o_data_cell:contains(test)').text(), 'test',
"the partner name should have been updated to 'test'");
form.destroy();
});
QUnit.test('search more in many2one: resequence inside dialog', async function (assert) {
// when the user clicks on 'Search More...' in a many2one dropdown, resequencing inside
// the dialog works
assert.expect(10);
this.data.partner.fields.sequence = { string: 'Sequence', type: 'integer' };
for (var i = 0; i < 8; i++) {
this.data.partner.records.push({id: 100 + i, display_name: 'test_' + i});
}
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="trululu"/></form>',
archs: {
'partner,false,list': '<list>' +
'<field name="sequence" widget="handle"/>' +
'<field name="display_name"/>' +
'</list>',
'partner,false,search': '<search></search>',
},
mockRPC: function (route, args) {
assert.step(args.method || route);
if (route === '/web/dataset/search_read') {
assert.deepEqual(args.domain, [],
"should not preselect ids as there as nothing in the m2o input");
}
return this._super.apply(this, arguments);
},
});
await testUtils.fields.many2one.searchAndClickItem('trululu', {
item: 'Search More',
search: '',
});
var $modal = $('.modal');
assert.equal($modal.length, 1,
'There should be 1 modal opened');
var $handles = $modal.find('.ui-sortable-handle');
assert.equal($handles.length, 11,
'There should be 11 sequence handlers');
await testUtils.dom.dragAndDrop($handles.eq(1),
$modal.find('tbody tr').first(), { position: 'top' });
assert.verifySteps([
'onchange',
'name_search', // to display results in the dropdown
'load_views', // list view in dialog
'/web/dataset/search_read', // to display results in the dialog
'/web/dataset/resequence', // resequencing lines
'read',
]);
form.destroy();
});
QUnit.test('many2one dropdown disappears on scroll', async function (assert) {
assert.expect(2);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch:
'<form>' +
'<div style="height: 2000px;">' +
'<field name="trululu"/>' +
'</div>' +
'</form>',
res_id: 1,
});
await testUtils.form.clickEdit(form);
var $input = form.$('.o_field_many2one input');
await testUtils.dom.click($input);
assert.isVisible($input.autocomplete('widget'), "dropdown should be opened");
form.el.dispatchEvent(new Event('scroll'));
assert.isNotVisible($input.autocomplete('widget'), "dropdown should be closed");
form.destroy();
});
QUnit.test('x2many list sorted by many2one', async function (assert) {
assert.expect(3);
this.data.partner.records[0].p = [1, 2, 4];
this.data.partner.fields.trululu.sortable = true;
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="p">' +
'<tree>' +
'<field name="id"/>' +
'<field name="trululu"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
});
assert.strictEqual(form.$('.o_data_row .o_list_number').text(), '124',
"should have correct order initially");
await testUtils.dom.click(form.$('.o_list_view thead th:nth(1)'));
assert.strictEqual(form.$('.o_data_row .o_list_number').text(), '412',
"should have correct order (ASC)");
await testUtils.dom.click(form.$('.o_list_view thead th:nth(1)'));
assert.strictEqual(form.$('.o_data_row .o_list_number').text(), '214',
"should have correct order (DESC)");
form.destroy();
});
QUnit.test('one2many with extra field from server not in form', async function (assert) {
assert.expect(6);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="p" >' +
'<tree>' +
'<field name="datetime"/>' +
'<field name="display_name"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
archs: {
'partner,false,form': '<form>' +
'<field name="display_name"/>' +
'</form>'},
mockRPC: function(route, args) {
if (route === '/web/dataset/call_kw/partner/write') {
args.args[1].p[0][2].datetime = '2018-04-05 12:00:00';
}
return this._super.apply(this, arguments);
}
});
await testUtils.form.clickEdit(form);
var x2mList = form.$('.o_field_x2many_list[name=p]');
// Add a record in the list
await testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a'));
var modal = $('.modal-lg');
var nameInput = modal.find('input.o_input[name=display_name]');
await testUtils.fields.editInput(nameInput, 'michelangelo');
// Save the record in the modal (though it is still virtual)
await testUtils.dom.click(modal.find('.btn-primary').first());
assert.equal(x2mList.find('.o_data_row').length, 1,
'There should be 1 records in the x2m list');
var newlyAdded = x2mList.find('.o_data_row').eq(0);
assert.equal(newlyAdded.find('.o_data_cell').first().text(), '',
'The create_date field should be empty');
assert.equal(newlyAdded.find('.o_data_cell').eq(1).text(), 'michelangelo',
'The display name field should have the right value');
// Save the whole thing
await testUtils.form.clickSave(form);
x2mList = form.$('.o_field_x2many_list[name=p]');
// Redo asserts in RO mode after saving
assert.equal(x2mList.find('.o_data_row').length, 1,
'There should be 1 records in the x2m list');
newlyAdded = x2mList.find('.o_data_row').eq(0);
assert.equal(newlyAdded.find('.o_data_cell').first().text(), '04/05/2018 12:00:00',
'The create_date field should have the right value');
assert.equal(newlyAdded.find('.o_data_cell').eq(1).text(), 'michelangelo',
'The display name field should have the right value');
form.destroy();
});
QUnit.test('one2many with extra field from server not in (inline) form', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="p" >' +
'<tree>' +
'<field name="datetime"/>' +
'<field name="display_name"/>' +
'</tree>' +
'<form>' +
'<field name="display_name"/>' +
'</form>' +
'</field>' +
'</form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
var x2mList = form.$('.o_field_x2many_list[name=p]');
// Add a record in the list
await testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a'));
var modal = $('.modal-lg');
var nameInput = modal.find('input.o_input[name=display_name]');
await testUtils.fields.editInput(nameInput, 'michelangelo');
// Save the record in the modal (though it is still virtual)
await testUtils.dom.click(modal.find('.btn-primary').first());
assert.equal(x2mList.find('.o_data_row').length, 1,
'There should be 1 records in the x2m list');
form.destroy();
});
QUnit.test('one2many with extra X2many field from server not in inline form', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="p" >' +
'<tree>' +
'<field name="turtles"/>' +
'<field name="display_name"/>' +
'</tree>' +
'<form>' +
'<field name="display_name"/>' +
'</form>' +
'</field>' +
'</form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
var x2mList = form.$('.o_field_x2many_list[name=p]');
// Add a first record in the list
await testUtils.dom.click(x2mList.find('.o_field_x2many_list_row_add a'));
// Save & New
await testUtils.dom.click($('.modal-lg').find('.btn-primary').eq(1));
// Save & Close
await testUtils.dom.click($('.modal-lg').find('.btn-primary').eq(0));
assert.equal(x2mList.find('.o_data_row').length, 2,
'There should be 2 records in the x2m list');
form.destroy();
});
QUnit.test('one2many invisible depends on parent field', async function (assert) {
assert.expect(4);
this.data.partner.records[0].p = [2];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="product_id"/>' +
'</group>' +
'<notebook>' +
'<page string="Partner page">' +
'<field name="bar"/>' +
'<field name="p">' +
'<tree>' +
'<field name="foo" attrs="{\'column_invisible\': [(\'parent.product_id\', \'!=\', False)]}"/>' +
'<field name="bar" attrs="{\'column_invisible\': [(\'parent.bar\', \'=\', False)]}"/>' +
'</tree>' +
'</field>' +
'</page>' +
'</notebook>' +
'</sheet>' +
'</form>',
res_id: 1,
});
assert.containsN(form, 'th', 2,
"should be 2 columns in the one2many");
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input'));
await testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter'));
await testUtils.owlCompatibilityNextTick();
assert.containsOnce(form, 'th:not(.o_list_record_remove_header)',
"should be 1 column when the product_id is set");
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one[name="product_id"] input'),
'', 'keyup');
await testUtils.owlCompatibilityNextTick();
assert.containsN(form, 'th:not(.o_list_record_remove_header)', 2,
"should be 2 columns in the one2many when product_id is not set");
await testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input'));
await testUtils.owlCompatibilityNextTick();
assert.containsOnce(form, 'th:not(.o_list_record_remove_header)',
"should be 1 column after the value change");
form.destroy();
});
QUnit.test('one2many column visiblity depends on onchange of parent field', async function (assert) {
assert.expect(3);
this.data.partner.records[0].p = [2];
this.data.partner.records[0].bar = false;
this.data.partner.onchanges.p = function (obj) {
// set bar to true when line is added
if (obj.p.length > 1 && obj.p[1][2].foo === 'New line') {
obj.bar = true;
}
};
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form>' +
'<field name="bar"/>' +
'<field name="p">' +
'<tree editable="bottom">' +
'<field name="foo"/>' +
'<field name="int_field" attrs="{\'column_invisible\': [(\'parent.bar\', \'=\', False)]}"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
});
// bar is false so there should be 1 column
assert.containsOnce(form, 'th',
"should be only 1 column ('foo') in the one2many");
assert.containsOnce(form, '.o_list_view .o_data_row', "should contain one row");
await testUtils.form.clickEdit(form);
// add a new o2m record
await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
form.$('.o_field_one2many input:first').focus();
await testUtils.fields.editInput(form.$('.o_field_one2many input:first'), 'New line');
await testUtils.dom.click(form.$el);
assert.containsN(form, 'th:not(.o_list_record_remove_header)', 2, "should be 2 columns('foo' + 'int_field')");
form.destroy();
});
QUnit.test('one2many column_invisible on view not inline', async function (assert) {
assert.expect(4);
this.data.partner.records[0].p = [2];
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="product_id"/>' +
'</group>' +
'<notebook>' +
'<page string="Partner page">' +
'<field name="bar"/>' +
'<field name="p"/>' +
'</page>' +
'</notebook>' +
'</sheet>' +
'</form>',
res_id: 1,
archs: {
'partner,false,list': '<tree>' +
'<field name="foo" attrs="{\'column_invisible\': [(\'parent.product_id\', \'!=\', False)]}"/>' +
'<field name="bar" attrs="{\'column_invisible\': [(\'parent.bar\', \'=\', False)]}"/>' +
'</tree>',
},
});
assert.containsN(form, 'th', 2,
"should be 2 columns in the one2many");
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_field_many2one[name="product_id"] input'));
await testUtils.dom.click($('li.ui-menu-item a:contains(xpad)').trigger('mouseenter'));
await testUtils.owlCompatibilityNextTick();
assert.containsOnce(form, 'th:not(.o_list_record_remove_header)',
"should be 1 column when the product_id is set");
await testUtils.fields.editAndTrigger(form.$('.o_field_many2one[name="product_id"] input'),
'', 'keyup');
await testUtils.owlCompatibilityNextTick();
assert.containsN(form, 'th:not(.o_list_record_remove_header)', 2,
"should be 2 columns in the one2many when product_id is not set");
await testUtils.dom.click(form.$('.o_field_boolean[name="bar"] input'));
await testUtils.owlCompatibilityNextTick();
assert.containsOnce(form, 'th:not(.o_list_record_remove_header)',
"should be 1 column after the value change");
form.destroy();
});
QUnit.module('Many2OneAvatar');
QUnit.test('many2one_avatar widget in form view', async function (assert) {
assert.expect(10);
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form><field name="user_id" widget="many2one_avatar"/></form>',
res_id: 1,
});
assert.hasClass(form.$('.o_form_view'), 'o_form_readonly');
assert.strictEqual(form.$('.o_field_widget[name=user_id]').text().trim(), 'Aline');
assert.containsOnce(form, 'img.o_m2o_avatar[data-src="/web/image/user/17/image_128"]');
await testUtils.form.clickEdit(form);
assert.hasClass(form.$('.o_form_view'), 'o_form_editable');
assert.containsOnce(form, '.o_input_dropdown');
assert.strictEqual(form.$('.o_input_dropdown input').val(), 'Aline');
assert.containsOnce(form, '.o_external_button');
await testUtils.fields.many2one.clickOpenDropdown("user_id");
await testUtils.fields.many2one.clickItem("user_id", "Christine");
await testUtils.form.clickSave(form);
assert.hasClass(form.$('.o_form_view'), 'o_form_readonly');
assert.strictEqual(form.$('.o_field_widget[name=user_id]').text().trim(), 'Christine');
assert.containsOnce(form, 'img.o_m2o_avatar[data-src="/web/image/user/19/image_128"]');
form.destroy();
});
QUnit.test('many2one_avatar widget in form view, with onchange', async function (assert) {
assert.expect(7);
this.data.partner.onchanges = {
int_field: function (obj) {
if (obj.int_field === 1) {
obj.user_id = [19, 'Christine'];
} else if (obj.int_field === 2) {
obj.user_id = false;
} else {
obj.user_id = [17, 'Aline']; // default value
}
},
};
const form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch: `
<form>
<field name="int_field"/>
<field name="user_id" widget="many2one_avatar" readonly="1"/>
</form>`,
});
assert.hasClass(form.$('.o_form_view'), 'o_form_editable');
assert.strictEqual(form.$('.o_field_widget[name=user_id]').text().trim(), 'Aline');
assert.containsOnce(form, 'img.o_m2o_avatar[data-src="/web/image/user/17/image_128"]');
await testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 1);
assert.strictEqual(form.$('.o_field_widget[name=user_id]').text().trim(), 'Christine');
assert.containsOnce(form, 'img.o_m2o_avatar[data-src="/web/image/user/19/image_128"]');
await testUtils.fields.editInput(form.$('.o_field_widget[name=int_field]'), 2);
assert.strictEqual(form.$('.o_field_widget[name=user_id]').text().trim(), '');
assert.containsNone(form, 'img.o_m2o_avatar');
form.destroy();
});
QUnit.test('many2one_avatar widget in list view', async function (assert) {
assert.expect(5);
this.data.partner.records = [
{ id: 1, user_id: 17, },
{ id: 2, user_id: 19, },
{ id: 3, user_id: 17, },
{ id: 4, user_id: false, },
];
const list = await createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree><field name="user_id" widget="many2one_avatar"/></tree>',
});
assert.strictEqual(list.$('.o_data_cell span').text(), 'AlineChristineAline');
assert.containsOnce(list.$('.o_data_cell:nth(0)'), 'img.o_m2o_avatar[data-src="/web/image/user/17/image_128"]');
assert.containsOnce(list.$('.o_data_cell:nth(1)'), 'img.o_m2o_avatar[data-src="/web/image/user/19/image_128"]');
assert.containsOnce(list.$('.o_data_cell:nth(2)'), 'img.o_m2o_avatar[data-src="/web/image/user/17/image_128"]');
assert.containsNone(list.$('.o_data_cell:nth(3)'), 'img.o_m2o_avatar');
list.destroy();
});
});
});
});
|