| 1 |
import { describe, expect, test } from "@odoo/hoot"; |
| 2 |
import { press, queryAllTexts, queryFirst } from "@odoo/hoot-dom"; |
| 3 |
import { Deferred, animationFrame, runAllTimers } from "@odoo/hoot-mock"; |
| 4 |
|
| 5 |
import { |
| 6 |
Command, |
| 7 |
MockServer, |
| 8 |
clickKanbanRecord, |
| 9 |
clickModalButton, |
| 10 |
clickSave, |
| 11 |
contains, |
| 12 |
defineModels, |
| 13 |
editSelectMenu, |
| 14 |
fieldInput, |
| 15 |
fields, |
| 16 |
models, |
| 17 |
mountView, |
| 18 |
onRpc, |
| 19 |
patchWithCleanup, |
| 20 |
serverState, |
| 21 |
stepAllNetworkCalls, |
| 22 |
mockService, |
| 23 |
} from "@web/../tests/web_test_helpers"; |
| 24 |
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog"; |
| 25 |
import { registry } from "@web/core/registry"; |
| 26 |
import { useService } from "@web/core/utils/hooks"; |
| 27 |
import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field"; |
| 28 |
import { Many2XAutocomplete } from "@web/views/fields/relational_utils"; |
| 29 |
import { cookie } from "@web/core/browser/cookie"; |
| 30 |
import { ListRenderer } from "@web/views/list/list_renderer"; |
| 31 |
|
| 32 |
describe.current.tags("desktop"); |
| 33 |
|
| 34 |
class Partner extends models.Model { |
| 35 |
_name = "partner"; |
| 36 |
|
| 37 |
name = fields.Char(); |
| 38 |
foo = fields.Char({ default: "My little Foo Value" }); |
| 39 |
bar = fields.Boolean({ default: true }); |
| 40 |
int_field = fields.Integer(); |
| 41 |
p = fields.Many2many({ relation: "partner", relation_field: "trululu" }); |
| 42 |
turtles = fields.One2many({ relation: "turtle", relation_field: "turtle_trululu" }); |
| 43 |
trululu = fields.Many2one({ relation: "partner" }); |
| 44 |
timmy = fields.Many2many({ relation: "partner.type", string: "pokemon" }); |
| 45 |
product_id = fields.Many2one({ relation: "product.product" }); |
| 46 |
color = fields.Selection({ |
| 47 |
selection: [ |
| 48 |
["red", "Red"], |
| 49 |
["black", "Black"], |
| 50 |
], |
| 51 |
default: "red", |
| 52 |
}); |
| 53 |
date = fields.Date(); |
| 54 |
datetime = fields.Datetime(); |
| 55 |
user_id = fields.Many2one({ relation: "res.users" }); |
| 56 |
reference = fields.Reference({ |
| 57 |
selection: [ |
| 58 |
["product.product", "Product"], |
| 59 |
["partner.type", "Partner Type"], |
| 60 |
["partner", "Partner"], |
| 61 |
], |
| 62 |
}); |
| 63 |
|
| 64 |
_records = [ |
| 65 |
{ |
| 66 |
id: 1, |
| 67 |
name: "first record", |
| 68 |
foo: "yop", |
| 69 |
int_field: 10, |
| 70 |
turtles: [2], |
| 71 |
trululu: 3, |
| 72 |
user_id: 1, |
| 73 |
reference: "product.product,1", |
| 74 |
}, |
| 75 |
{ |
| 76 |
id: 2, |
| 77 |
name: "second record", |
| 78 |
foo: "blip", |
| 79 |
int_field: 9, |
| 80 |
trululu: 1, |
| 81 |
product_id: 1, |
| 82 |
date: "2017-01-25", |
| 83 |
datetime: "2016-12-12 10:55:05", |
| 84 |
user_id: 1, |
| 85 |
}, |
| 86 |
{ |
| 87 |
id: 3, |
| 88 |
name: "aaa", |
| 89 |
bar: false, |
| 90 |
}, |
| 91 |
]; |
| 92 |
} |
| 93 |
|
| 94 |
class PartnerType extends models.Model { |
| 95 |
color = fields.Integer({ string: "Color index" }); |
| 96 |
name = fields.Char(); |
| 97 |
|
| 98 |
_records = [ |
| 99 |
{ |
| 100 |
id: 1, |
| 101 |
name: "gold", |
| 102 |
color: 2, |
| 103 |
}, |
| 104 |
{ |
| 105 |
id: 2, |
| 106 |
name: "silver", |
| 107 |
color: 5, |
| 108 |
}, |
| 109 |
]; |
| 110 |
} |
| 111 |
|
| 112 |
class Product extends models.Model { |
| 113 |
_name = "product.product"; |
| 114 |
|
| 115 |
name = fields.Char(); |
| 116 |
|
| 117 |
_records = [ |
| 118 |
{ |
| 119 |
id: 1, |
| 120 |
name: "xphone", |
| 121 |
}, |
| 122 |
{ |
| 123 |
id: 2, |
| 124 |
name: "xpad", |
| 125 |
}, |
| 126 |
]; |
| 127 |
} |
| 128 |
|
| 129 |
class Turtle extends models.Model { |
| 130 |
_name = "turtle"; |
| 131 |
|
| 132 |
name = fields.Char(); |
| 133 |
turtle_foo = fields.Char(); |
| 134 |
turtle_bar = fields.Boolean({ default: true }); |
| 135 |
turtle_int = fields.Integer(); |
| 136 |
turtle_trululu = fields.Many2one({ relation: "partner" }); |
| 137 |
turtle_ref = fields.Reference({ |
| 138 |
selection: [ |
| 139 |
["product.product", "Product"], |
| 140 |
["partner", "Partner"], |
| 141 |
], |
| 142 |
}); |
| 143 |
product_id = fields.Many2one({ relation: "product.product", required: true }); |
| 144 |
partner_ids = fields.Many2many({ relation: "partner" }); |
| 145 |
|
| 146 |
_records = [ |
| 147 |
{ |
| 148 |
id: 1, |
| 149 |
name: "leonardo", |
| 150 |
turtle_foo: "yop", |
| 151 |
}, |
| 152 |
{ |
| 153 |
id: 2, |
| 154 |
name: "donatello", |
| 155 |
turtle_foo: "blip", |
| 156 |
turtle_int: 9, |
| 157 |
partner_ids: [2, 3], |
| 158 |
}, |
| 159 |
{ |
| 160 |
id: 3, |
| 161 |
name: "raphael", |
| 162 |
product_id: 1, |
| 163 |
turtle_bar: false, |
| 164 |
turtle_foo: "kawa", |
| 165 |
turtle_int: 21, |
| 166 |
turtle_ref: "product.product,1", |
| 167 |
}, |
| 168 |
]; |
| 169 |
} |
| 170 |
|
| 171 |
class Users extends models.Model { |
| 172 |
_name = "res.users"; |
| 173 |
|
| 174 |
name = fields.Char(); |
| 175 |
partner_ids = fields.One2many({ relation: "partner", relation_field: "user_id" }); |
| 176 |
|
| 177 |
has_group() { |
| 178 |
return true; |
| 179 |
} |
| 180 |
|
| 181 |
_records = [ |
| 182 |
{ |
| 183 |
id: 1, |
| 184 |
name: "Aline", |
| 185 |
partner_ids: [1, 2], |
| 186 |
}, |
| 187 |
{ |
| 188 |
id: 2, |
| 189 |
name: "Christine", |
| 190 |
}, |
| 191 |
]; |
| 192 |
} |
| 193 |
|
| 194 |
defineModels([Partner, PartnerType, Product, Turtle, Users]); |
| 195 |
|
| 196 |
test.tags("desktop"); |
| 197 |
test("many2many kanban: edition", async () => { |
| 198 |
expect.assertions(24); |
| 199 |
|
| 200 |
onRpc("partner.type", "web_save", ({ args }) => { |
| 201 |
if (args[0].length) { |
| 202 |
expect(args[1].name).toBe("new name"); |
| 203 |
} else { |
| 204 |
expect(args[1].name).toBe("A new type"); |
| 205 |
} |
| 206 |
}); |
| 207 |
onRpc("partner", "web_save", ({ args }) => { |
| 208 |
const commands = args[1].timmy; |
| 209 |
const [record] = MockServer.env["partner.type"].search_read([["name", "=", "A new type"]]); |
| 210 |
// get the created type's id |
| 211 |
expect(commands).toEqual([ |
| 212 |
Command.link(3), |
| 213 |
Command.link(4), |
| 214 |
Command.link(record.id), |
| 215 |
Command.unlink(2), |
| 216 |
]); |
| 217 |
}); |
| 218 |
|
| 219 |
Partner._records[0].timmy = [1, 2]; |
| 220 |
PartnerType._records.push( |
| 221 |
{ id: 3, name: "red", color: 6 }, |
| 222 |
{ id: 4, name: "yellow", color: 4 }, |
| 223 |
{ id: 5, name: "blue", color: 1 } |
| 224 |
); |
| 225 |
|
| 226 |
PartnerType._views = { |
| 227 |
form: /* xml */ ` |
| 228 |
<form> |
| 229 |
<field name="name" /> |
| 230 |
</form> |
| 231 |
`, |
| 232 |
list: /* xml */ ` |
| 233 |
<list> |
| 234 |
<field name="name" /> |
| 235 |
</list> |
| 236 |
`, |
| 237 |
search: /* xml */ ` |
| 238 |
<search> |
| 239 |
<field name="name" string="Name" /> |
| 240 |
</search> |
| 241 |
`, |
| 242 |
}; |
| 243 |
|
| 244 |
await mountView({ |
| 245 |
type: "form", |
| 246 |
resModel: "partner", |
| 247 |
resId: 1, |
| 248 |
arch: /* xml */ ` |
| 249 |
<form> |
| 250 |
<field name="timmy"> |
| 251 |
<kanban> |
| 252 |
<templates> |
| 253 |
<t t-name="card"> |
| 254 |
<div> |
| 255 |
<a |
| 256 |
type="delete" |
| 257 |
class="fa fa-times float-end delete_icon" |
| 258 |
/> |
| 259 |
<field name="name"/> |
| 260 |
</div> |
| 261 |
</t> |
| 262 |
</templates> |
| 263 |
</kanban> |
| 264 |
<form> |
| 265 |
<field name="name" /> |
| 266 |
</form> |
| 267 |
</field> |
| 268 |
</form>`, |
| 269 |
}); |
| 270 |
|
| 271 |
expect(`.o_kanban_record:visible:not(.o-kanban-button-new)`).toHaveCount(2); |
| 272 |
expect(`.o_kanban_record:first`).toHaveText("gold"); |
| 273 |
expect(`.o_kanban_renderer .delete_icon`).toBeVisible(); |
| 274 |
expect(`.o_field_many2many .o-kanban-button-new:visible`).toHaveText("Add pokemon"); |
| 275 |
|
| 276 |
// edit existing subrecord |
| 277 |
|
| 278 |
await clickKanbanRecord({ text: "gold" }); |
| 279 |
|
| 280 |
await fieldInput("name").edit("new name"); |
| 281 |
await clickModalButton({ text: "Save" }); |
| 282 |
await animationFrame(); // todo: ???? |
| 283 |
|
| 284 |
expect(".o_kanban_record:first:visible").toHaveText("new name"); |
| 285 |
|
| 286 |
// add subrecords |
| 287 |
// -> single select |
| 288 |
await contains(".o_view_controller .btn:contains(Add pokemon)").click(); |
| 289 |
|
| 290 |
expect(".modal .o_list_view tbody .o_list_record_selector").toHaveCount(3); |
| 291 |
|
| 292 |
await contains(".modal .o_list_view tbody tr:contains(red) .o_data_cell").click(); |
| 293 |
|
| 294 |
expect(".o_kanban_record:visible:not(.o-kanban-button-new)").toHaveCount(3); |
| 295 |
expect(".o_kanban_record:contains(red)").toBeVisible(); |
| 296 |
|
| 297 |
// -> multiple select |
| 298 |
await contains(".o_view_controller .btn:contains(Add pokemon)").click(); |
| 299 |
expect(".modal .o_select_button").not.toBeEnabled(); |
| 300 |
await animationFrame(); |
| 301 |
|
| 302 |
expect(".modal .o_list_view tbody .o_list_record_selector").toHaveCount(2); |
| 303 |
|
| 304 |
await contains(".modal .o_list_view thead .o_list_record_selector input").click(); |
| 305 |
await clickModalButton({ text: "Select" }); |
| 306 |
|
| 307 |
expect(".modal .o_list_view").toHaveCount(0); |
| 308 |
expect(".o_kanban_record:visible:not(.o-kanban-button-new)").toHaveCount(5); |
| 309 |
|
| 310 |
// -> created record |
| 311 |
await contains(".o_view_controller .btn:contains(Add pokemon)").click(); |
| 312 |
await clickModalButton({ text: "New" }); |
| 313 |
|
| 314 |
expect(".modal .o_form_view .o_form_editable").toBeVisible(); |
| 315 |
|
| 316 |
await fieldInput("name").edit("A new type"); |
| 317 |
await clickModalButton({ text: "Save & Close" }); |
| 318 |
|
| 319 |
expect(".o_kanban_record:visible:not(.o-kanban-button-new)").toHaveCount(6); |
| 320 |
expect(".o_kanban_record:contains(A new type)").toBeVisible(); |
| 321 |
|
| 322 |
// delete subrecords |
| 323 |
await clickKanbanRecord({ text: "silver" }); |
| 324 |
|
| 325 |
expect(".modal .modal-footer .o_btn_remove").toHaveCount(1); |
| 326 |
await clickModalButton({ text: "Remove" }); |
| 327 |
|
| 328 |
expect(".modal").toHaveCount(0); |
| 329 |
expect(".o_kanban_record:visible:not(.o-kanban-button-new)").toHaveCount(5); |
| 330 |
expect(".o_kanban_record:contains(silver)").toHaveCount(0); |
| 331 |
|
| 332 |
await clickKanbanRecord({ text: "blue", target: ".delete_icon" }); |
| 333 |
|
| 334 |
expect(".o_kanban_record:visible:not(.o-kanban-button-new)").toHaveCount(4); |
| 335 |
expect(".o_kanban_record:contains(blue)").toHaveCount(0); |
| 336 |
|
| 337 |
// save the record |
| 338 |
await clickSave(); |
| 339 |
}); |
| 340 |
|
| 341 |
test("many2many kanban(editable): properly handle add-label node attribute", async () => { |
| 342 |
Partner._records[0].timmy = [1]; |
| 343 |
|
| 344 |
await mountView({ |
| 345 |
type: "form", |
| 346 |
resModel: "partner", |
| 347 |
arch: ` |
| 348 |
<form> |
| 349 |
<field name="timmy" add-label="Add timmy" mode="kanban"> |
| 350 |
<kanban> |
| 351 |
<templates> |
| 352 |
<t t-name="card"> |
| 353 |
<field name="name"/> |
| 354 |
</t> |
| 355 |
</templates> |
| 356 |
</kanban> |
| 357 |
</field> |
| 358 |
</form>`, |
| 359 |
resId: 1, |
| 360 |
}); |
| 361 |
|
| 362 |
expect(".o_field_many2many[name=timmy] .o-kanban-button-new").toHaveText("Add timmy", { |
| 363 |
message: "In M2M Kanban, Add button should have 'Add timmy' label", |
| 364 |
}); |
| 365 |
}); |
| 366 |
|
| 367 |
test("field string is used in the SelectCreateDialog", async () => { |
| 368 |
PartnerType._views = { |
| 369 |
list: '<list><field name="name"/></list>', |
| 370 |
search: '<search><field name="name"/></search>', |
| 371 |
}; |
| 372 |
Turtle._views = { |
| 373 |
list: '<list><field name="name"/></list>', |
| 374 |
search: '<search><field name="name"/></search>', |
| 375 |
}; |
| 376 |
await mountView({ |
| 377 |
type: "form", |
| 378 |
resModel: "partner", |
| 379 |
arch: ` |
| 380 |
<form> |
| 381 |
<field name="timmy"> |
| 382 |
<list> |
| 383 |
<field name="name"/> |
| 384 |
</list> |
| 385 |
</field> |
| 386 |
<field name="turtles" widget="many2many" string="Abcde"> |
| 387 |
<list> |
| 388 |
<field name="name"/> |
| 389 |
</list> |
| 390 |
</field> |
| 391 |
</form>`, |
| 392 |
}); |
| 393 |
|
| 394 |
await contains(".o_field_x2many_list_row_add a:eq(0)").click(); |
| 395 |
expect(".modal").toHaveCount(1); |
| 396 |
expect(".modal .modal-title").toHaveText("Add: pokemon"); |
| 397 |
|
| 398 |
await contains(".modal .o_form_button_cancel").click(); |
| 399 |
expect(".modal").toHaveCount(0); |
| 400 |
|
| 401 |
await contains(".o_field_x2many_list_row_add a:eq(1)").click(); |
| 402 |
expect(".modal").toHaveCount(1); |
| 403 |
expect(".modal .modal-title").toHaveText("Add: Abcde"); |
| 404 |
}); |
| 405 |
|
| 406 |
test("many2many kanban: create action disabled", async () => { |
| 407 |
Partner._records[0].timmy = [1, 2]; |
| 408 |
PartnerType._views = { |
| 409 |
list: '<list><field name="name"/></list>', |
| 410 |
search: '<search><field name="name" string="Name"/></search>', |
| 411 |
}; |
| 412 |
|
| 413 |
await mountView({ |
| 414 |
type: "form", |
| 415 |
resModel: "partner", |
| 416 |
arch: ` |
| 417 |
<form> |
| 418 |
<field name="timmy"> |
| 419 |
<kanban create="0"> |
| 420 |
<templates> |
| 421 |
<t t-name="card"> |
| 422 |
<div> |
| 423 |
<a type="delete" class="fa fa-times float-end delete_icon"/> |
| 424 |
<field name="name"/> |
| 425 |
</div> |
| 426 |
</t> |
| 427 |
</templates> |
| 428 |
</kanban> |
| 429 |
</field> |
| 430 |
</form>`, |
| 431 |
resId: 1, |
| 432 |
}); |
| 433 |
|
| 434 |
expect(".o-kanban-button-new").toHaveCount(1); |
| 435 |
expect(".o_kanban_renderer .delete_icon").toHaveCount(2); |
| 436 |
|
| 437 |
await contains(".o-kanban-button-new:eq(0)").click(); |
| 438 |
expect(".modal .modal-footer .btn-primary").toHaveCount(1); |
| 439 |
}); |
| 440 |
|
| 441 |
test("many2many kanban: conditional create/delete actions", async () => { |
| 442 |
PartnerType._views = { |
| 443 |
form: '<form><field name="name"/></form>', |
| 444 |
list: '<list><field name="name"/></list>', |
| 445 |
}; |
| 446 |
Partner._records[0].timmy = [1, 2]; |
| 447 |
|
| 448 |
await mountView({ |
| 449 |
type: "form", |
| 450 |
resModel: "partner", |
| 451 |
arch: ` |
| 452 |
<form> |
| 453 |
<field name="color"/> |
| 454 |
<field name="timmy" options="{'create': [('color', '=', 'red')], 'delete': [('color', '=', 'red')]}"> |
| 455 |
<kanban> |
| 456 |
<templates> |
| 457 |
<t t-name="card"> |
| 458 |
<field name="name"/> |
| 459 |
</t> |
| 460 |
</templates> |
| 461 |
</kanban> |
| 462 |
</field> |
| 463 |
</form>`, |
| 464 |
resId: 1, |
| 465 |
}); |
| 466 |
|
| 467 |
// color is red |
| 468 |
expect(".o-kanban-button-new").toHaveCount(1, { |
| 469 |
message: '"Add" button should be available', |
| 470 |
}); |
| 471 |
|
| 472 |
await contains(".o_kanban_record:contains(silver):eq(0)").click(); |
| 473 |
expect(".modal .modal-footer .o_btn_remove").toHaveCount(1); |
| 474 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 475 |
|
| 476 |
await contains(".o-kanban-button-new:eq(0)").click(); |
| 477 |
expect(".modal .modal-footer button").toHaveCount(3); |
| 478 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 479 |
|
| 480 |
// set color to black |
| 481 |
await editSelectMenu(".o_field_widget[name='color'] input", { value: "Black" }); |
| 482 |
expect(".o-kanban-button-new").toHaveCount(1, { |
| 483 |
message: '"Add" button should still be available even after color field changed', |
| 484 |
}); |
| 485 |
|
| 486 |
await contains(".o-kanban-button-new:eq(0)").click(); |
| 487 |
// only select and cancel button should be available, create |
| 488 |
// button should be removed based on color field condition |
| 489 |
expect(".modal .modal-footer button").toHaveCount(2); |
| 490 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 491 |
|
| 492 |
await contains(".o_kanban_record:contains(silver):eq(0)").click(); |
| 493 |
expect(".modal .modal-footer .o_btn_remove").toHaveCount(0); |
| 494 |
}); |
| 495 |
|
| 496 |
test("many2many list (non editable): create a new record and click on action button 1", async () => { |
| 497 |
PartnerType._views = { |
| 498 |
list: '<list><field name="name"/></list>', |
| 499 |
search: '<search><field name="name"/></search>', |
| 500 |
}; |
| 501 |
onRpc((args) => { |
| 502 |
expect.step(args.method); |
| 503 |
if (args.method === "web_save") { |
| 504 |
expect(args.args[1]).toEqual({ name: "Hello" }); |
| 505 |
} |
| 506 |
}); |
| 507 |
onRpc("myaction", () => { |
| 508 |
expect.step(`action: myaction`); |
| 509 |
return true; |
| 510 |
}); |
| 511 |
await mountView({ |
| 512 |
type: "form", |
| 513 |
resModel: "partner", |
| 514 |
arch: ` |
| 515 |
<form> |
| 516 |
<field name="timmy"> |
| 517 |
<list> |
| 518 |
<field name="name"/> |
| 519 |
</list> |
| 520 |
<form> |
| 521 |
<header> |
| 522 |
<button name="myaction" string="coucou" type="object"/> |
| 523 |
</header> |
| 524 |
<field name="name"/> |
| 525 |
</form> |
| 526 |
</field> |
| 527 |
</form>`, |
| 528 |
resId: 1, |
| 529 |
}); |
| 530 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 531 |
|
| 532 |
await contains(".modal .o_create_button").click(); |
| 533 |
expect.verifySteps([ |
| 534 |
"get_views", |
| 535 |
"web_read", |
| 536 |
"get_views", |
| 537 |
"web_search_read", |
| 538 |
"has_group", |
| 539 |
"onchange", |
| 540 |
]); |
| 541 |
await contains(".modal [name='name'] input").edit("Hello"); |
| 542 |
expect("[name='name'] input").toHaveValue("Hello"); |
| 543 |
|
| 544 |
await contains(".modal .o_statusbar_buttons [name='myaction']").click(); |
| 545 |
expect("[name='name'] input").toHaveValue("Hello"); |
| 546 |
expect.verifySteps(["web_save", "action: myaction", "web_read"]); |
| 547 |
}); |
| 548 |
|
| 549 |
test("many2many list (non editable): create a new record and click on action button 2", async () => { |
| 550 |
PartnerType._views = { |
| 551 |
list: '<list><field name="name"/></list>', |
| 552 |
search: '<search><field name="name"/></search>', |
| 553 |
}; |
| 554 |
onRpc((args) => { |
| 555 |
expect.step(args.method); |
| 556 |
if (args.method === "web_save" && args.args[0].length === 0) { |
| 557 |
expect(args.args[1]).toEqual({ name: "Hello" }); |
| 558 |
} |
| 559 |
}); |
| 560 |
onRpc("myaction", () => { |
| 561 |
expect.step(`action: myaction`); |
| 562 |
return true; |
| 563 |
}); |
| 564 |
await mountView({ |
| 565 |
type: "form", |
| 566 |
resModel: "partner", |
| 567 |
arch: ` |
| 568 |
<form> |
| 569 |
<field name="timmy"> |
| 570 |
<list> |
| 571 |
<field name="name"/> |
| 572 |
</list> |
| 573 |
<form> |
| 574 |
<header> |
| 575 |
<button name="myaction" string="coucou" type="object"/> |
| 576 |
</header> |
| 577 |
<field name="name"/> |
| 578 |
</form> |
| 579 |
</field> |
| 580 |
</form>`, |
| 581 |
resId: 1, |
| 582 |
}); |
| 583 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 584 |
|
| 585 |
await contains(".modal .o_create_button").click(); |
| 586 |
expect.verifySteps([ |
| 587 |
"get_views", |
| 588 |
"web_read", |
| 589 |
"get_views", |
| 590 |
"web_search_read", |
| 591 |
"has_group", |
| 592 |
"onchange", |
| 593 |
]); |
| 594 |
|
| 595 |
await contains(".modal [name='name'] input").edit("Hello"); |
| 596 |
expect("[name='name'] input").toHaveValue("Hello"); |
| 597 |
|
| 598 |
await contains(".modal .o_statusbar_buttons [name='myaction']").click(); |
| 599 |
expect("[name='name'] input").toHaveValue("Hello"); |
| 600 |
expect(queryAllTexts(".modal .modal-footer button")).toEqual([ |
| 601 |
"Save & Close", |
| 602 |
"Save & New", |
| 603 |
"Discard", |
| 604 |
]); |
| 605 |
|
| 606 |
await contains(".modal [name='name'] input").edit("Hello (edited)"); |
| 607 |
|
| 608 |
await contains(".modal-footer button").click(); |
| 609 |
expect(".modal").toHaveCount(0); |
| 610 |
expect(queryAllTexts("[name='timmy'] .o_data_row")).toEqual(["Hello (edited)"]); |
| 611 |
|
| 612 |
expect.verifySteps(["web_save", "action: myaction", "web_read", "web_save", "web_read"]); |
| 613 |
}); |
| 614 |
|
| 615 |
test("add a new record in a many2many non editable list", async () => { |
| 616 |
PartnerType._views = { |
| 617 |
list: '<list><field name="name"/></list>', |
| 618 |
form: '<form><field name="name"/></form>', |
| 619 |
search: '<search><field name="name"/></search>', |
| 620 |
}; |
| 621 |
|
| 622 |
stepAllNetworkCalls(); |
| 623 |
onRpc("web_save", ({ kwargs }) => { |
| 624 |
// should not read the record as we're closing the dialog |
| 625 |
expect(kwargs.specification).toEqual({}); |
| 626 |
}); |
| 627 |
await mountView({ |
| 628 |
type: "form", |
| 629 |
resModel: "partner", |
| 630 |
arch: ` |
| 631 |
<form> |
| 632 |
<field name="timmy"> |
| 633 |
<list> |
| 634 |
<field name="name"/> |
| 635 |
</list> |
| 636 |
</field> |
| 637 |
</form>`, |
| 638 |
}); |
| 639 |
|
| 640 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 641 |
await contains(".o_dialog .o_create_button").click(); |
| 642 |
await contains(".o_dialog .o_field_widget[name=name] input").edit("a name"); |
| 643 |
await contains(".o_dialog .o_form_button_save").click(); |
| 644 |
expect.verifySteps([ |
| 645 |
"/web/webclient/translations", |
| 646 |
"/web/webclient/load_menus", |
| 647 |
"get_views", |
| 648 |
"onchange", |
| 649 |
"get_views", |
| 650 |
"web_search_read", |
| 651 |
"has_group", |
| 652 |
"get_views", |
| 653 |
"onchange", |
| 654 |
"web_save", |
| 655 |
"web_read", |
| 656 |
]); |
| 657 |
}); |
| 658 |
|
| 659 |
test("add record in a many2many non editable list with context", async () => { |
| 660 |
expect.assertions(1); |
| 661 |
|
| 662 |
PartnerType._views = { |
| 663 |
list: '<list><field name="name"/></list>', |
| 664 |
search: '<search><field name="name"/></search>', |
| 665 |
}; |
| 666 |
onRpc("web_search_read", (args) => { |
| 667 |
// done by the SelectCreateDialog |
| 668 |
expect(args.kwargs.context).toEqual({ |
| 669 |
abc: 2, |
| 670 |
allowed_company_ids: [1], |
| 671 |
bin_size: true, |
| 672 |
lang: "en", |
| 673 |
tz: "taht", |
| 674 |
uid: 7, |
| 675 |
}); |
| 676 |
}); |
| 677 |
await mountView({ |
| 678 |
type: "form", |
| 679 |
resModel: "partner", |
| 680 |
arch: ` |
| 681 |
<form> |
| 682 |
<field name="int_field"/> |
| 683 |
<field name="timmy" context="{'abc': int_field}"> |
| 684 |
<list> |
| 685 |
<field name="name"/> |
| 686 |
</list> |
| 687 |
</field> |
| 688 |
</form>`, |
| 689 |
}); |
| 690 |
|
| 691 |
await contains(".o_field_widget[name=int_field] input").edit("2"); |
| 692 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 693 |
}); |
| 694 |
|
| 695 |
test("many2many list (editable): edition", async () => { |
| 696 |
Partner._records[0].timmy = [1, 2]; |
| 697 |
PartnerType._records.push({ id: 15, name: "bronze", color: 6 }); |
| 698 |
PartnerType._fields.float_field = fields.Float({ string: "Float" }); |
| 699 |
|
| 700 |
PartnerType._views = { |
| 701 |
list: '<list><field name="name"/></list>', |
| 702 |
search: '<search><field name="name"/></search>', |
| 703 |
}; |
| 704 |
onRpc((args) => { |
| 705 |
expect.step(args.method); |
| 706 |
if (args.method === "write") { |
| 707 |
expect(args.args[1].timmy).toEqual([ |
| 708 |
[6, false, [12, 15]], |
| 709 |
[1, 12, { name: "new name" }], |
| 710 |
]); |
| 711 |
} |
| 712 |
}); |
| 713 |
await mountView({ |
| 714 |
type: "form", |
| 715 |
resModel: "partner", |
| 716 |
arch: ` |
| 717 |
<form> |
| 718 |
<field name="timmy"> |
| 719 |
<list editable="top"> |
| 720 |
<field name="name"/> |
| 721 |
<field name="float_field"/> |
| 722 |
</list> |
| 723 |
</field> |
| 724 |
</form>`, |
| 725 |
resId: 1, |
| 726 |
}); |
| 727 |
|
| 728 |
expect(".o_list_renderer td.o_list_number").toHaveCount(2); |
| 729 |
expect(".o_list_renderer tbody td:eq(0)").toHaveText("gold", { |
| 730 |
message: "name of first subrecord should be the one in DB", |
| 731 |
}); |
| 732 |
expect(".o_list_record_remove").toHaveCount(2); |
| 733 |
expect("td.o_list_record_remove button").toHaveClass("fa fa-times"); |
| 734 |
expect(".o_field_x2many_list_row_add").toHaveCount(1); |
| 735 |
|
| 736 |
// edit existing subrecord |
| 737 |
await contains(".o_list_renderer tbody td:eq(0)").click(); |
| 738 |
expect(".modal").toHaveCount(0); |
| 739 |
expect(".o_list_renderer tbody tr:eq(0)").toHaveClass("o_selected_row"); |
| 740 |
await contains(".o_selected_row div[name=name] input").edit("new name", { confirm: false }); |
| 741 |
expect(".o_list_renderer .o_data_row:eq(0)").toHaveClass("o_selected_row"); |
| 742 |
expect(".o_list_renderer div[name=name] input").toBeFocused({ |
| 743 |
message: "edited field should still have the focus", |
| 744 |
}); |
| 745 |
await contains(".o_form_view").click(); |
| 746 |
expect(".o_list_renderer tbody tr:eq(0)").not.toHaveClass("o_selected_row"); |
| 747 |
expect(".o_list_renderer tbody td:eq(0)").toHaveText("new name", { |
| 748 |
message: "value of subrecord should have been updated", |
| 749 |
}); |
| 750 |
expect.verifySteps(["get_views", "web_read"]); |
| 751 |
|
| 752 |
// add new subrecords |
| 753 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 754 |
expect(".modal").toHaveCount(1); |
| 755 |
expect(".modal .o_list_view .o_data_row").toHaveCount(1); |
| 756 |
await contains(".modal .o_list_view .o_data_row .o_data_cell").click(); |
| 757 |
expect(".modal .o_list_view").toHaveCount(0); |
| 758 |
expect(".o_list_renderer td.o_list_number").toHaveCount(3); |
| 759 |
|
| 760 |
// remove subrecords |
| 761 |
await contains(".o_list_record_remove:eq(1)").click(); |
| 762 |
expect(".o_list_renderer td.o_list_number").toHaveCount(2); |
| 763 |
expect(".o_list_renderer tbody .o_data_row td:eq(0)").toHaveText("new name", { |
| 764 |
message: "the updated row still has the correct values", |
| 765 |
}); |
| 766 |
|
| 767 |
// save |
| 768 |
await clickSave(); |
| 769 |
expect(".o_list_renderer td.o_list_number").toHaveCount(2); |
| 770 |
expect(".o_list_renderer .o_data_row td:eq(0)").toHaveText("new name", { |
| 771 |
message: "the updated row still has the correct values", |
| 772 |
}); |
| 773 |
|
| 774 |
expect.verifySteps([ |
| 775 |
"get_views", // list view in dialog |
| 776 |
"web_search_read", // list view in dialog |
| 777 |
"has_group", |
| 778 |
"web_read", // relational field (updated) |
| 779 |
"web_save", // save main record |
| 780 |
]); |
| 781 |
}); |
| 782 |
|
| 783 |
test("many2many: create & delete attributes (both true)", async () => { |
| 784 |
Partner._records[0].timmy = [1, 2]; |
| 785 |
|
| 786 |
await mountView({ |
| 787 |
type: "form", |
| 788 |
resModel: "partner", |
| 789 |
arch: ` |
| 790 |
<form> |
| 791 |
<field name="timmy"> |
| 792 |
<list create="true" delete="true"> |
| 793 |
<field name="color"/> |
| 794 |
</list> |
| 795 |
</field> |
| 796 |
</form>`, |
| 797 |
resId: 1, |
| 798 |
}); |
| 799 |
|
| 800 |
expect(".o_field_x2many_list_row_add").toHaveCount(1); |
| 801 |
expect(".o_list_record_remove").toHaveCount(2); |
| 802 |
}); |
| 803 |
|
| 804 |
test("many2many: create & delete attributes (both false)", async () => { |
| 805 |
Partner._records[0].timmy = [1, 2]; |
| 806 |
|
| 807 |
await mountView({ |
| 808 |
type: "form", |
| 809 |
resModel: "partner", |
| 810 |
arch: ` |
| 811 |
<form> |
| 812 |
<field name="timmy"> |
| 813 |
<list create="false" delete="false"> |
| 814 |
<field name="color"/> |
| 815 |
</list> |
| 816 |
</field> |
| 817 |
</form>`, |
| 818 |
resId: 1, |
| 819 |
}); |
| 820 |
|
| 821 |
expect(".o_field_x2many_list_row_add").toHaveCount(1); |
| 822 |
expect(".o_list_record_remove").toHaveCount(2); |
| 823 |
}); |
| 824 |
|
| 825 |
test("many2many list: create action disabled", async () => { |
| 826 |
await mountView({ |
| 827 |
type: "form", |
| 828 |
resModel: "partner", |
| 829 |
arch: ` |
| 830 |
<form> |
| 831 |
<field name="timmy"> |
| 832 |
<list create="0"> |
| 833 |
<field name="name"/> |
| 834 |
</list> |
| 835 |
</field> |
| 836 |
</form>`, |
| 837 |
resId: 1, |
| 838 |
}); |
| 839 |
|
| 840 |
expect(".o_field_x2many_list_row_add").toHaveCount(1); |
| 841 |
}); |
| 842 |
|
| 843 |
test("fieldmany2many list comodel not writable", async () => { |
| 844 |
/** |
| 845 |
* Many2Many List should behave as the m2m_tags |
| 846 |
* that is, the relation can be altered even if the comodel itself is not CRUD-able |
| 847 |
* This can happen when someone has read access alone on the comodel |
| 848 |
* and full CRUD on the current model |
| 849 |
*/ |
| 850 |
expect.assertions(12); |
| 851 |
|
| 852 |
PartnerType._views = { |
| 853 |
list: ` |
| 854 |
<list create="false" delete="false" edit="false"> |
| 855 |
<field name="name"/> |
| 856 |
</list>`, |
| 857 |
search: '<search><field name="name"/></search>', |
| 858 |
}; |
| 859 |
onRpc("partner", "web_save", ({ args }) => { |
| 860 |
if (args[0].length === 0) { |
| 861 |
expect(args[1]).toEqual({ timmy: [[4, 1]] }); |
| 862 |
} else { |
| 863 |
expect(args[1]).toEqual({ timmy: [[3, 1]] }); |
| 864 |
} |
| 865 |
}); |
| 866 |
await mountView({ |
| 867 |
type: "form", |
| 868 |
resModel: "partner", |
| 869 |
arch: ` |
| 870 |
<form> |
| 871 |
<field name="timmy" widget="many2many" can_create="False" can_write="False"/> |
| 872 |
</form>`, |
| 873 |
}); |
| 874 |
|
| 875 |
expect(".o_field_many2many .o_field_x2many_list_row_add").toHaveCount(1); |
| 876 |
await contains(".o_field_many2many .o_field_x2many_list_row_add a").click(); |
| 877 |
expect(".modal").toHaveCount(1); |
| 878 |
|
| 879 |
expect(".modal-footer button").toHaveCount(2); |
| 880 |
expect(".modal-footer button.o_select_button").toHaveCount(1); |
| 881 |
expect(".modal-footer button.o_form_button_cancel").toHaveCount(1); |
| 882 |
|
| 883 |
await contains(".modal .o_list_view .o_data_cell").click(); |
| 884 |
expect(".modal").toHaveCount(0); |
| 885 |
|
| 886 |
expect(".o_field_many2many .o_data_row").toHaveCount(1); |
| 887 |
expect(queryAllTexts(".o_field_many2many .o_data_row")).toEqual(["gold"]); |
| 888 |
expect(".o_field_many2many .o_field_x2many_list_row_add").toHaveCount(1); |
| 889 |
|
| 890 |
await clickSave(); |
| 891 |
|
| 892 |
expect(".o_field_many2many .o_data_row .o_list_record_remove").toHaveCount(1); |
| 893 |
await contains(".o_field_many2many .o_data_row .o_list_record_remove").click(); |
| 894 |
await clickSave(); |
| 895 |
}); |
| 896 |
|
| 897 |
test("many2many list: conditional create/delete actions", async () => { |
| 898 |
Partner._records[0].timmy = [1, 2]; |
| 899 |
|
| 900 |
PartnerType._views = { |
| 901 |
list: '<list><field name="name"/></list>', |
| 902 |
}; |
| 903 |
|
| 904 |
await mountView({ |
| 905 |
type: "form", |
| 906 |
resModel: "partner", |
| 907 |
arch: ` |
| 908 |
<form> |
| 909 |
<field name="color"/> |
| 910 |
<field name="timmy" options="{'create': [('color', '=', 'red')], 'delete': [('color', '=', 'red')]}"> |
| 911 |
<list> |
| 912 |
<field name="name"/> |
| 913 |
</list> |
| 914 |
</field> |
| 915 |
</form>`, |
| 916 |
resId: 1, |
| 917 |
}); |
| 918 |
|
| 919 |
// color is red -> create and delete actions are available |
| 920 |
expect(".o_field_x2many_list_row_add").toHaveCount(1, { |
| 921 |
message: "should have the 'Add an item' link", |
| 922 |
}); |
| 923 |
expect(".o_list_record_remove").toHaveCount(2); |
| 924 |
|
| 925 |
await contains(".o_field_x2many_list_row_add a:eq(0)").click(); |
| 926 |
|
| 927 |
expect(".modal .modal-footer button").toHaveCount(3); |
| 928 |
|
| 929 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 930 |
|
| 931 |
// set color to black -> create and delete actions are no longer available |
| 932 |
await editSelectMenu(".o_field_widget[name='color'] input", { value: "Black" }); |
| 933 |
|
| 934 |
// add a line and remove icon should still be there as they don't create/delete records, |
| 935 |
// but rather add/remove links |
| 936 |
expect(".o_field_x2many_list_row_add").toHaveCount(1); |
| 937 |
expect(".o_list_record_remove").toHaveCount(2); |
| 938 |
|
| 939 |
await contains(".o_field_x2many_list_row_add a:eq(0)").click(); |
| 940 |
expect(".modal .modal-footer button").toHaveCount(2); |
| 941 |
}); |
| 942 |
|
| 943 |
test("many2many field with link/unlink options (list)", async () => { |
| 944 |
Partner._records[0].timmy = [1, 2]; |
| 945 |
PartnerType._views = { |
| 946 |
list: '<list><field name="name"/></list>', |
| 947 |
}; |
| 948 |
|
| 949 |
await mountView({ |
| 950 |
type: "form", |
| 951 |
resModel: "partner", |
| 952 |
arch: ` |
| 953 |
<form> |
| 954 |
<field name="color"/> |
| 955 |
<field name="timmy" options="{'link': [('color', '=', 'red')], 'unlink': [('color', '=', 'red')]}"> |
| 956 |
<list> |
| 957 |
<field name="name"/> |
| 958 |
</list> |
| 959 |
</field> |
| 960 |
</form>`, |
| 961 |
resId: 1, |
| 962 |
}); |
| 963 |
|
| 964 |
// color is red -> link and unlink actions are available |
| 965 |
expect(".o_field_x2many_list_row_add").toHaveCount(1); |
| 966 |
expect(".o_list_record_remove").toHaveCount(2); |
| 967 |
|
| 968 |
await contains(".o_field_x2many_list_row_add a:eq(0)").click(); |
| 969 |
|
| 970 |
expect(".modal .modal-footer button").toHaveCount(3); |
| 971 |
|
| 972 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 973 |
|
| 974 |
// set color to black -> link and unlink actions are no longer available |
| 975 |
await editSelectMenu(".o_field_widget[name='color'] input", { value: "Black" }); |
| 976 |
|
| 977 |
expect(".o_field_x2many_list_row_add").toHaveCount(0); |
| 978 |
expect(".o_list_record_remove").toHaveCount(0); |
| 979 |
}); |
| 980 |
|
| 981 |
test('many2many field with link/unlink options (list, create="0")', async () => { |
| 982 |
Partner._records[0].timmy = [1, 2]; |
| 983 |
PartnerType._views = { |
| 984 |
list: '<list><field name="name"/></list>', |
| 985 |
}; |
| 986 |
|
| 987 |
await mountView({ |
| 988 |
type: "form", |
| 989 |
resModel: "partner", |
| 990 |
arch: ` |
| 991 |
<form> |
| 992 |
<field name="color"/> |
| 993 |
<field name="timmy" options="{'link': [('color', '=', 'red')], 'unlink': [('color', '=', 'red')]}"> |
| 994 |
<list create="0"> |
| 995 |
<field name="name"/> |
| 996 |
</list> |
| 997 |
</field> |
| 998 |
</form>`, |
| 999 |
resId: 1, |
| 1000 |
}); |
| 1001 |
|
| 1002 |
// color is red -> link and unlink actions are available |
| 1003 |
expect(".o_field_x2many_list_row_add").toHaveCount(1); |
| 1004 |
expect(".o_list_record_remove").toHaveCount(2); |
| 1005 |
|
| 1006 |
await contains(".o_field_x2many_list_row_add a:eq(0)").click(); |
| 1007 |
|
| 1008 |
expect(".modal .modal-footer button").toHaveCount(2); |
| 1009 |
|
| 1010 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 1011 |
|
| 1012 |
// set color to black -> link and unlink actions are no longer available |
| 1013 |
await editSelectMenu(".o_field_widget[name='color'] input", { value: "Black" }); |
| 1014 |
|
| 1015 |
expect(".o_field_x2many_list_row_add").toHaveCount(0); |
| 1016 |
expect(".o_list_record_remove").toHaveCount(0); |
| 1017 |
}); |
| 1018 |
|
| 1019 |
test("many2many field with link option (kanban)", async () => { |
| 1020 |
Partner._records[0].timmy = [1, 2]; |
| 1021 |
|
| 1022 |
PartnerType._views = { |
| 1023 |
list: '<list><field name="name"/></list>', |
| 1024 |
}; |
| 1025 |
|
| 1026 |
await mountView({ |
| 1027 |
type: "form", |
| 1028 |
resModel: "partner", |
| 1029 |
arch: ` |
| 1030 |
<form> |
| 1031 |
<field name="color"/> |
| 1032 |
<field name="timmy" options="{'link': [('color', '=', 'red')]}"> |
| 1033 |
<kanban> |
| 1034 |
<templates> |
| 1035 |
<t t-name="card"> |
| 1036 |
<field name="name"/> |
| 1037 |
</t> |
| 1038 |
</templates> |
| 1039 |
</kanban> |
| 1040 |
</field> |
| 1041 |
</form>`, |
| 1042 |
resId: 1, |
| 1043 |
}); |
| 1044 |
|
| 1045 |
// color is red -> link and unlink actions are available |
| 1046 |
expect(".o-kanban-button-new").toHaveCount(1); |
| 1047 |
|
| 1048 |
await contains(".o-kanban-button-new").click(); |
| 1049 |
|
| 1050 |
expect(".modal .modal-footer button").toHaveCount(3); |
| 1051 |
|
| 1052 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 1053 |
|
| 1054 |
// set color to black -> link and unlink actions are no longer available |
| 1055 |
await editSelectMenu(".o_field_widget[name='color'] input", { value: "Black" }); |
| 1056 |
|
| 1057 |
expect(".o-kanban-button-new").toHaveCount(0); |
| 1058 |
}); |
| 1059 |
|
| 1060 |
test('many2many field with link option (kanban, create="0")', async () => { |
| 1061 |
Partner._records[0].timmy = [1, 2]; |
| 1062 |
PartnerType._views = { |
| 1063 |
list: '<list><field name="name"/></list>', |
| 1064 |
}; |
| 1065 |
|
| 1066 |
await mountView({ |
| 1067 |
type: "form", |
| 1068 |
resModel: "partner", |
| 1069 |
arch: ` |
| 1070 |
<form> |
| 1071 |
<field name="color"/> |
| 1072 |
<field name="timmy" options="{'link': [('color', '=', 'red')]}"> |
| 1073 |
<kanban create="0"> |
| 1074 |
<templates> |
| 1075 |
<t t-name="card"> |
| 1076 |
<field name="name"/> |
| 1077 |
</t> |
| 1078 |
</templates> |
| 1079 |
</kanban> |
| 1080 |
</field> |
| 1081 |
</form>`, |
| 1082 |
resId: 1, |
| 1083 |
}); |
| 1084 |
|
| 1085 |
// color is red -> link and unlink actions are available |
| 1086 |
expect(".o-kanban-button-new").toHaveCount(1); |
| 1087 |
|
| 1088 |
await contains(".o-kanban-button-new").click(); |
| 1089 |
|
| 1090 |
expect(".modal .modal-footer button").toHaveCount(2); |
| 1091 |
|
| 1092 |
await contains(".modal .modal-footer .o_form_button_cancel:eq(0)").click(); |
| 1093 |
|
| 1094 |
// set color to black -> link and unlink actions are no longer available |
| 1095 |
await editSelectMenu(".o_field_widget[name='color'] input", { value: "Black" }); |
| 1096 |
|
| 1097 |
expect(".o-kanban-button-new").toHaveCount(0); |
| 1098 |
}); |
| 1099 |
|
| 1100 |
test("readonly many2many field: edit record", async () => { |
| 1101 |
Partner._records[0].timmy = [1, 2]; |
| 1102 |
|
| 1103 |
onRpc("web_save", ({ args }) => { |
| 1104 |
expect.step(`save ${args[1].name}`); |
| 1105 |
}); |
| 1106 |
await mountView({ |
| 1107 |
type: "form", |
| 1108 |
resModel: "partner", |
| 1109 |
arch: ` |
| 1110 |
<form> |
| 1111 |
<field name="color"/> |
| 1112 |
<field name="timmy" readonly="1"> |
| 1113 |
<list> |
| 1114 |
<field name="name"/> |
| 1115 |
</list> |
| 1116 |
<form> |
| 1117 |
<field name="name"/> |
| 1118 |
</form> |
| 1119 |
</field> |
| 1120 |
</form>`, |
| 1121 |
resId: 1, |
| 1122 |
}); |
| 1123 |
|
| 1124 |
expect(".o_field_widget[name=timmy]").toHaveClass("o_readonly_modifier"); |
| 1125 |
expect(".o_field_x2many_list_row_add").toHaveCount(0); |
| 1126 |
expect(".o_list_record_remove").toHaveCount(0); |
| 1127 |
expect(queryAllTexts(".o_data_cell")).toEqual(["gold", "silver"]); |
| 1128 |
|
| 1129 |
await contains(".o_data_row:first .o_data_cell").click(); |
| 1130 |
expect(".o_dialog .o_form_renderer").toHaveClass("o_form_editable"); |
| 1131 |
|
| 1132 |
await contains(".o_dialog .o_field_widget[name=name] input").edit("new name"); |
| 1133 |
await contains(".o_dialog .o_form_button_save").click(); |
| 1134 |
expect(queryAllTexts(".o_data_cell")).toEqual(["new name", "silver"]); |
| 1135 |
expect.verifySteps(["save new name"]); |
| 1136 |
}); |
| 1137 |
|
| 1138 |
test("many2many list: list of id as default value", async () => { |
| 1139 |
Partner._fields.turtles = fields.Many2many({ |
| 1140 |
relation: "turtle", |
| 1141 |
relation_field: "turtle_trululu", |
| 1142 |
default: [ |
| 1143 |
[4, 2], |
| 1144 |
[4, 3], |
| 1145 |
], |
| 1146 |
}); |
| 1147 |
|
| 1148 |
await mountView({ |
| 1149 |
type: "form", |
| 1150 |
resModel: "partner", |
| 1151 |
arch: ` |
| 1152 |
<form> |
| 1153 |
<field name="turtles"> |
| 1154 |
<list> |
| 1155 |
<field name="turtle_foo"/> |
| 1156 |
</list> |
| 1157 |
</field> |
| 1158 |
</form> |
| 1159 |
`, |
| 1160 |
}); |
| 1161 |
|
| 1162 |
expect(queryAllTexts("td.o_data_cell")).toEqual(["blip", "kawa"]); |
| 1163 |
}); |
| 1164 |
|
| 1165 |
test("context and domain dependent on an x2m must contain the list of current ids for the x2m", async () => { |
| 1166 |
expect.assertions(2); |
| 1167 |
|
| 1168 |
Partner._fields.turtles = fields.Many2many({ |
| 1169 |
relation: "turtle", |
| 1170 |
relation_field: "turtle_trululu", |
| 1171 |
default: [ |
| 1172 |
[4, 2], |
| 1173 |
[4, 3], |
| 1174 |
], |
| 1175 |
}); |
| 1176 |
Turtle._views = { |
| 1177 |
list: '<list><field name="name"/></list>', |
| 1178 |
search: '<search><field name="name"/></search>', |
| 1179 |
}; |
| 1180 |
onRpc("web_search_read", (args) => { |
| 1181 |
expect(args.kwargs.domain).toEqual(["&", ["id", "in", [2, 3]], "!", ["id", "in", [2, 3]]]); |
| 1182 |
expect(args.kwargs.context.test).toEqual([2, 3]); |
| 1183 |
}); |
| 1184 |
|
| 1185 |
await mountView({ |
| 1186 |
type: "form", |
| 1187 |
resModel: "partner", |
| 1188 |
arch: ` |
| 1189 |
<form> |
| 1190 |
<field name="turtles" context="{'test': turtles}" domain="[('id', 'in', turtles)]"> |
| 1191 |
<list> |
| 1192 |
<field name="turtle_foo"/> |
| 1193 |
</list> |
| 1194 |
</field> |
| 1195 |
</form>`, |
| 1196 |
}); |
| 1197 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1198 |
}); |
| 1199 |
|
| 1200 |
test("many2many list with x2many: add a record", async () => { |
| 1201 |
PartnerType._fields.m2m = fields.Many2many({ |
| 1202 |
string: "M2M", |
| 1203 |
relation: "turtle", |
| 1204 |
}); |
| 1205 |
PartnerType._records[0].m2m = [1, 2]; |
| 1206 |
PartnerType._records[1].m2m = [2, 3]; |
| 1207 |
|
| 1208 |
PartnerType._views = { |
| 1209 |
list: ` |
| 1210 |
<list> |
| 1211 |
<field name="name"/> |
| 1212 |
<field name="m2m" widget="many2many_tags"/> |
| 1213 |
</list>`, |
| 1214 |
search: '<search><field name="name" string="Name"/></search>', |
| 1215 |
}; |
| 1216 |
onRpc((args) => { |
| 1217 |
if (args.method !== "get_views") { |
| 1218 |
expect.step(args.route.split("/").at(-1) + " on " + args.model); |
| 1219 |
} |
| 1220 |
}); |
| 1221 |
|
| 1222 |
await mountView({ |
| 1223 |
type: "form", |
| 1224 |
resModel: "partner", |
| 1225 |
arch: '<form><field name="timmy"/></form>', |
| 1226 |
resId: 1, |
| 1227 |
}); |
| 1228 |
|
| 1229 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1230 |
await contains(".modal .o_data_row:first .o_data_cell:eq(0)").click(); |
| 1231 |
|
| 1232 |
expect(".o_data_row").toHaveCount(1); |
| 1233 |
expect(queryAllTexts(".o_data_row:first .o_tag_badge_text")).toEqual(["leonardo", "donatello"]); |
| 1234 |
|
| 1235 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1236 |
await contains(".modal .o_data_row .o_data_cell:eq(1)").click(); |
| 1237 |
|
| 1238 |
expect(".o_data_row").toHaveCount(2); |
| 1239 |
expect(queryAllTexts(".o_data_row:eq(1) .o_tag_badge_text")).toEqual(["donatello", "raphael"]); |
| 1240 |
|
| 1241 |
expect.verifySteps([ |
| 1242 |
"web_read on partner", |
| 1243 |
"web_search_read on partner.type", |
| 1244 |
"has_group on res.users", |
| 1245 |
"web_read on partner.type", |
| 1246 |
"web_search_read on partner.type", |
| 1247 |
"web_read on partner.type", |
| 1248 |
]); |
| 1249 |
}); |
| 1250 |
|
| 1251 |
test("many2many with a domain", async () => { |
| 1252 |
// The domain specified on the field should not be replaced by the potential |
| 1253 |
// domain the user writes in the dialog, they should rather be concatenated |
| 1254 |
PartnerType._views = { |
| 1255 |
list: '<list><field name="name"/></list>', |
| 1256 |
search: '<search><field name="name" string="Name"/></search>', |
| 1257 |
}; |
| 1258 |
|
| 1259 |
await mountView({ |
| 1260 |
type: "form", |
| 1261 |
resModel: "partner", |
| 1262 |
arch: ` |
| 1263 |
<form> |
| 1264 |
<field name="timmy" domain="[['name', '=', 'gold']]"/> |
| 1265 |
</form>`, |
| 1266 |
resId: 1, |
| 1267 |
}); |
| 1268 |
|
| 1269 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1270 |
expect(".modal .o_data_row").toHaveCount(1); |
| 1271 |
await contains(`.modal .o_searchview input`).edit("s"); |
| 1272 |
await press("enter"); |
| 1273 |
await animationFrame(); |
| 1274 |
|
| 1275 |
expect(".modal .o_data_row").toHaveCount(0); |
| 1276 |
}); |
| 1277 |
|
| 1278 |
test("many2many list (editable): edition concurrence", async () => { |
| 1279 |
Partner._records[0].timmy = [1, 2]; |
| 1280 |
PartnerType._records.push({ id: 15, name: "bronze", color: 6 }); |
| 1281 |
PartnerType._fields.float_field = fields.Float({ string: "Float" }); |
| 1282 |
PartnerType._views = { |
| 1283 |
list: '<list><field name="name"/></list>', |
| 1284 |
search: '<search><field name="name" string="Name"/></search>', |
| 1285 |
}; |
| 1286 |
|
| 1287 |
onRpc((args) => { |
| 1288 |
expect.step(args.method); |
| 1289 |
if (args.method === "web_save") { |
| 1290 |
expect(args.args[1]).toEqual({ |
| 1291 |
timmy: [[3, 1]], |
| 1292 |
}); |
| 1293 |
} |
| 1294 |
}); |
| 1295 |
|
| 1296 |
await mountView({ |
| 1297 |
type: "form", |
| 1298 |
resModel: "partner", |
| 1299 |
arch: ` |
| 1300 |
<form> |
| 1301 |
<field name="timmy"> |
| 1302 |
<list editable="top"> |
| 1303 |
<field name="display_name"/> |
| 1304 |
<field name="float_field"/> |
| 1305 |
</list> |
| 1306 |
</field> |
| 1307 |
</form>`, |
| 1308 |
resId: 1, |
| 1309 |
}); |
| 1310 |
|
| 1311 |
queryFirst(".o_list_record_remove").click(); |
| 1312 |
queryFirst(".o_list_record_remove").click(); |
| 1313 |
await clickSave(); |
| 1314 |
expect.verifySteps(["get_views", "web_read", "web_save"]); |
| 1315 |
}); |
| 1316 |
|
| 1317 |
test("many2many editable list: delete with confirmation (cancel, then delete again)", async () => { |
| 1318 |
class ListRendererWithConfirmation extends ListRenderer { |
| 1319 |
setup() { |
| 1320 |
this.dialog = useService("dialog"); |
| 1321 |
super.setup(); |
| 1322 |
} |
| 1323 |
onDeleteRecord(record) { |
| 1324 |
return new Promise((resolve) => { |
| 1325 |
this.dialog.add(ConfirmationDialog, { |
| 1326 |
body: "Are you sure you want to delete this record?", |
| 1327 |
confirm: () => super.onDeleteRecord(record).then(resolve), |
| 1328 |
cancel: resolve, |
| 1329 |
}); |
| 1330 |
}); |
| 1331 |
} |
| 1332 |
} |
| 1333 |
class X2ManyFieldWithConfirmation extends X2ManyField { |
| 1334 |
static components = { |
| 1335 |
...X2ManyField.components, |
| 1336 |
ListRenderer: ListRendererWithConfirmation, |
| 1337 |
}; |
| 1338 |
} |
| 1339 |
const x2ManyFieldWithConfirmation = { |
| 1340 |
...x2ManyField, |
| 1341 |
component: X2ManyFieldWithConfirmation, |
| 1342 |
additionalClasses: ["o_field_one2many"], |
| 1343 |
}; |
| 1344 |
registry.category("fields").add("x2many_with_confirmation", x2ManyFieldWithConfirmation); |
| 1345 |
|
| 1346 |
Partner._records[0].timmy = [1, 2]; |
| 1347 |
|
| 1348 |
await mountView({ |
| 1349 |
type: "form", |
| 1350 |
resModel: "partner", |
| 1351 |
arch: ` |
| 1352 |
<form> |
| 1353 |
<field name="timmy" widget="x2many_with_confirmation"> |
| 1354 |
<list editable="top"> |
| 1355 |
<field name="display_name"/> |
| 1356 |
</list> |
| 1357 |
</field> |
| 1358 |
</form>`, |
| 1359 |
resId: 1, |
| 1360 |
}); |
| 1361 |
|
| 1362 |
expect(".o_data_row").toHaveCount(2); |
| 1363 |
|
| 1364 |
await contains(".o_list_record_remove button").click(); |
| 1365 |
expect(".o_dialog").toHaveCount(1); |
| 1366 |
|
| 1367 |
await contains(".o_dialog footer .btn-secondary").click(); |
| 1368 |
expect(".o_dialog").toHaveCount(0); |
| 1369 |
expect(".o_data_row").toHaveCount(2); |
| 1370 |
|
| 1371 |
await runAllTimers(); // the button is disabled (programmatically) for a while |
| 1372 |
await contains(".o_list_record_remove button").click(); |
| 1373 |
expect(".o_dialog").toHaveCount(1); |
| 1374 |
|
| 1375 |
await contains(".o_dialog footer .btn-primary").click(); |
| 1376 |
expect(".o_dialog").toHaveCount(0); |
| 1377 |
expect(".o_data_row").toHaveCount(1); |
| 1378 |
}); |
| 1379 |
|
| 1380 |
test("many2many list with onchange and edition of a record", async () => { |
| 1381 |
Partner._fields.turtles = fields.Many2many({ |
| 1382 |
relation: "turtle", |
| 1383 |
relation_field: "turtle_trululu", |
| 1384 |
onChange: function () {}, |
| 1385 |
}); |
| 1386 |
|
| 1387 |
Turtle._views = { |
| 1388 |
form: '<form string="Turtle Power"><field name="turtle_bar"/></form>', |
| 1389 |
}; |
| 1390 |
onRpc((args) => { |
| 1391 |
expect.step(args.method); |
| 1392 |
}); |
| 1393 |
|
| 1394 |
await mountView({ |
| 1395 |
type: "form", |
| 1396 |
resModel: "partner", |
| 1397 |
arch: ` |
| 1398 |
<form> |
| 1399 |
<field name="turtles"> |
| 1400 |
<list> |
| 1401 |
<field name="turtle_foo"/> |
| 1402 |
</list> |
| 1403 |
</field> |
| 1404 |
</form>`, |
| 1405 |
resId: 1, |
| 1406 |
}); |
| 1407 |
expect.verifySteps(["get_views", "web_read"]); |
| 1408 |
|
| 1409 |
await contains("td.o_data_cell").click(); |
| 1410 |
expect.verifySteps(["get_views", "web_read"]); |
| 1411 |
|
| 1412 |
await contains(".modal-body input[type=checkbox]").click(); |
| 1413 |
await contains(".modal .modal-footer .btn-primary").click(); |
| 1414 |
expect.verifySteps(["web_save"]); |
| 1415 |
expect(".o_form_button_save").not.toBeVisible(); |
| 1416 |
}); |
| 1417 |
|
| 1418 |
test("many2many concurrency edition", async () => { |
| 1419 |
Partner._fields.turtles = fields.Many2many({ |
| 1420 |
relation: "turtle", |
| 1421 |
relation_field: "turtle_trululu", |
| 1422 |
onChange: function () {}, |
| 1423 |
}); |
| 1424 |
Turtle._records.push({ |
| 1425 |
id: 4, |
| 1426 |
name: "Bloop", |
| 1427 |
turtle_bar: true, |
| 1428 |
turtle_foo: "Bloop", |
| 1429 |
partner_ids: [], |
| 1430 |
}); |
| 1431 |
Partner._records[0].turtles = [1, 2, 3, 4]; |
| 1432 |
Turtle._views = { |
| 1433 |
list: '<list><field name="name"/></list>', |
| 1434 |
search: '<search><field name="name" string="Name"/></search>', |
| 1435 |
}; |
| 1436 |
|
| 1437 |
const def = new Deferred(); |
| 1438 |
let firstOnChange = false; |
| 1439 |
onRpc("onchange", async () => { |
| 1440 |
if (!firstOnChange) { |
| 1441 |
firstOnChange = true; |
| 1442 |
await def; |
| 1443 |
} |
| 1444 |
}); |
| 1445 |
|
| 1446 |
await mountView({ |
| 1447 |
type: "form", |
| 1448 |
resModel: "partner", |
| 1449 |
arch: ` |
| 1450 |
<form> |
| 1451 |
<field name="turtles"> |
| 1452 |
<list> |
| 1453 |
<field name="turtle_foo"/> |
| 1454 |
</list> |
| 1455 |
</field> |
| 1456 |
</form>`, |
| 1457 |
resId: 1, |
| 1458 |
}); |
| 1459 |
expect(".o_data_row").toHaveCount(4); |
| 1460 |
await contains(".o_data_row .o_list_record_remove").click(); |
| 1461 |
await contains(".o_data_row .o_list_record_remove").click(); |
| 1462 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1463 |
await contains(".modal .o_data_row td.o_data_cell:eq(0)").click(); |
| 1464 |
def.resolve(); |
| 1465 |
await animationFrame(); |
| 1466 |
expect(".o_data_row").toHaveCount(3); |
| 1467 |
}); |
| 1468 |
|
| 1469 |
test("many2many widget: creates a new record with a context containing the parentID", async () => { |
| 1470 |
Turtle._views = { |
| 1471 |
list: '<list><field name="name"/></list>', |
| 1472 |
search: '<search><field name="name"/></search>', |
| 1473 |
form: '<form string="Turtle Power"><field name="turtle_trululu"/></form>', |
| 1474 |
}; |
| 1475 |
onRpc(({ args, method, kwargs }) => { |
| 1476 |
expect.step(method); |
| 1477 |
if (method === "onchange") { |
| 1478 |
expect(kwargs.context.default_turtle_trululu).toBe(1); |
| 1479 |
expect(args).toEqual([ |
| 1480 |
[], |
| 1481 |
{}, |
| 1482 |
[], |
| 1483 |
{ |
| 1484 |
turtle_foo: {}, |
| 1485 |
turtle_trululu: { |
| 1486 |
fields: { |
| 1487 |
display_name: {}, |
| 1488 |
}, |
| 1489 |
}, |
| 1490 |
}, |
| 1491 |
]); |
| 1492 |
} |
| 1493 |
}); |
| 1494 |
|
| 1495 |
await mountView({ |
| 1496 |
type: "form", |
| 1497 |
resModel: "partner", |
| 1498 |
arch: ` |
| 1499 |
<form> |
| 1500 |
<field name="turtles" widget="many2many" context="{'default_turtle_trululu': id}" > |
| 1501 |
<list> |
| 1502 |
<field name="turtle_foo"/> |
| 1503 |
</list> |
| 1504 |
</field> |
| 1505 |
</form>`, |
| 1506 |
resId: 1, |
| 1507 |
}); |
| 1508 |
expect.verifySteps(["get_views", "web_read"]); |
| 1509 |
|
| 1510 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1511 |
expect.verifySteps(["get_views", "web_search_read", "has_group"]); |
| 1512 |
|
| 1513 |
await contains(".o_create_button").click(); |
| 1514 |
expect("[name='turtle_trululu'] input").toHaveValue("first record"); |
| 1515 |
expect.verifySteps(["get_views", "onchange"]); |
| 1516 |
}); |
| 1517 |
|
| 1518 |
test("onchange with 40+ commands for a many2many", async () => { |
| 1519 |
// this test ensures that the basic_model correctly handles more LINK_TO |
| 1520 |
// commands than the limit of the dataPoint (40 for x2many kanban) |
| 1521 |
expect.assertions(10); |
| 1522 |
|
| 1523 |
// create a lot of partner_types that will be linked by the onchange |
| 1524 |
const commands = []; |
| 1525 |
for (let id = 100; id < 145; id++) { |
| 1526 |
PartnerType._records.push({ id, name: "type " + id }); |
| 1527 |
commands.push(Command.link(id)); |
| 1528 |
} |
| 1529 |
Partner._fields.foo = fields.Char({ |
| 1530 |
default: "My little Foo Value", |
| 1531 |
onChange: function (obj) { |
| 1532 |
obj.timmy = commands; |
| 1533 |
}, |
| 1534 |
}); |
| 1535 |
onRpc((args) => { |
| 1536 |
expect.step(args.method); |
| 1537 |
if (args.method === "web_save") { |
| 1538 |
expect(args.args[1].timmy).toEqual(commands.map((c) => [c[0], c[1]])); |
| 1539 |
} |
| 1540 |
}); |
| 1541 |
|
| 1542 |
await mountView({ |
| 1543 |
type: "form", |
| 1544 |
resModel: "partner", |
| 1545 |
arch: ` |
| 1546 |
<form> |
| 1547 |
<field name="foo"/> |
| 1548 |
<field name="timmy"> |
| 1549 |
<kanban> |
| 1550 |
<templates> |
| 1551 |
<t t-name="card"> |
| 1552 |
<field name="name"/> |
| 1553 |
</t> |
| 1554 |
</templates> |
| 1555 |
</kanban> |
| 1556 |
</field> |
| 1557 |
</form>`, |
| 1558 |
resId: 1, |
| 1559 |
}); |
| 1560 |
|
| 1561 |
expect.verifySteps(["get_views", "web_read"]); |
| 1562 |
|
| 1563 |
await contains(".o_field_widget[name=foo] input").edit("trigger onchange"); |
| 1564 |
expect.verifySteps(["onchange"]); |
| 1565 |
expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40); |
| 1566 |
await contains(".o_field_widget[name=timmy] .o_pager_next:eq(0)").click(); |
| 1567 |
expect.verifySteps([]); |
| 1568 |
expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(5); |
| 1569 |
|
| 1570 |
await clickSave(); |
| 1571 |
|
| 1572 |
expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40); |
| 1573 |
|
| 1574 |
await contains(".o_field_widget[name=timmy] .o_pager_next:eq(0)").click(); |
| 1575 |
expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(5); |
| 1576 |
|
| 1577 |
await contains(".o_field_widget[name=timmy] .o_pager_next:eq(0)").click(); |
| 1578 |
expect(".o_kanban_record:not(.o_kanban_ghost):not(.o-kanban-button-new)").toHaveCount(40); |
| 1579 |
|
| 1580 |
expect.verifySteps(["web_save", "web_read"]); |
| 1581 |
}); |
| 1582 |
|
| 1583 |
test.tags("desktop"); |
| 1584 |
test("onchange with 40+ commands for a many2many on desktop", async () => { |
| 1585 |
// this test ensures that the basic_model correctly handles more LINK_TO |
| 1586 |
// commands than the limit of the dataPoint (40 for x2many kanban) |
| 1587 |
|
| 1588 |
// create a lot of partner_types that will be linked by the onchange |
| 1589 |
const commands = []; |
| 1590 |
for (let id = 100; id < 145; id++) { |
| 1591 |
PartnerType._records.push({ id, name: "type " + id }); |
| 1592 |
commands.push(Command.link(id)); |
| 1593 |
} |
| 1594 |
Partner._fields.foo = fields.Char({ |
| 1595 |
default: "My little Foo Value", |
| 1596 |
onChange: function (obj) { |
| 1597 |
obj.timmy = commands; |
| 1598 |
}, |
| 1599 |
}); |
| 1600 |
|
| 1601 |
await mountView({ |
| 1602 |
type: "form", |
| 1603 |
resModel: "partner", |
| 1604 |
arch: ` |
| 1605 |
<form> |
| 1606 |
<field name="foo"/> |
| 1607 |
<field name="timmy"> |
| 1608 |
<kanban> |
| 1609 |
<templates> |
| 1610 |
<t t-name="card"> |
| 1611 |
<field name="name"/> |
| 1612 |
</t> |
| 1613 |
</templates> |
| 1614 |
</kanban> |
| 1615 |
</field> |
| 1616 |
</form>`, |
| 1617 |
resId: 1, |
| 1618 |
}); |
| 1619 |
|
| 1620 |
await contains(".o_field_widget[name=foo] input").edit("trigger onchange"); |
| 1621 |
expect(".o_x2m_control_panel .o_pager_counter").toHaveText("1-40 / 45"); |
| 1622 |
await contains(".o_field_widget[name=timmy] .o_pager_next:eq(0)").click(); |
| 1623 |
expect(".o_x2m_control_panel .o_pager_counter").toHaveText("41-45 / 45"); |
| 1624 |
|
| 1625 |
await clickSave(); |
| 1626 |
|
| 1627 |
expect(".o_x2m_control_panel .o_pager_counter").toHaveText("1-40 / 45"); |
| 1628 |
|
| 1629 |
await contains(".o_field_widget[name=timmy] .o_pager_next:eq(0)").click(); |
| 1630 |
expect(".o_x2m_control_panel .o_pager_counter").toHaveText("41-45 / 45"); |
| 1631 |
|
| 1632 |
await contains(".o_field_widget[name=timmy] .o_pager_next:eq(0)").click(); |
| 1633 |
expect(".o_x2m_control_panel .o_pager_counter").toHaveText("1-40 / 45"); |
| 1634 |
}); |
| 1635 |
|
| 1636 |
test("default_get, onchange, onchange on m2m", async () => { |
| 1637 |
expect.assertions(1); |
| 1638 |
Partner._fields.int_field = fields.Integer({ onChange: function () {} }); |
| 1639 |
|
| 1640 |
let firstOnChange = true; |
| 1641 |
onRpc("onchange", (args) => { |
| 1642 |
if (firstOnChange) { |
| 1643 |
firstOnChange = false; |
| 1644 |
return { |
| 1645 |
value: { |
| 1646 |
timmy: [[1, 12, { name: "gold" }]], |
| 1647 |
}, |
| 1648 |
}; |
| 1649 |
} else { |
| 1650 |
expect(args.args[1]).toEqual({ |
| 1651 |
display_name: false, |
| 1652 |
int_field: 2, |
| 1653 |
timmy: [[1, 12, { name: "gold" }]], |
| 1654 |
}); |
| 1655 |
} |
| 1656 |
}); |
| 1657 |
|
| 1658 |
await mountView({ |
| 1659 |
type: "form", |
| 1660 |
resModel: "partner", |
| 1661 |
arch: ` |
| 1662 |
<form> |
| 1663 |
<sheet> |
| 1664 |
<field name="timmy"> |
| 1665 |
<list> |
| 1666 |
<field name="name"/> |
| 1667 |
</list> |
| 1668 |
</field> |
| 1669 |
<field name="int_field"/> |
| 1670 |
</sheet> |
| 1671 |
</form>`, |
| 1672 |
}); |
| 1673 |
|
| 1674 |
await contains(".o_field_widget[name=int_field] input").edit(2); |
| 1675 |
}); |
| 1676 |
|
| 1677 |
test("many2many list add *many* records, remove, re-add", async () => { |
| 1678 |
Partner._fields.timmy = fields.Many2many({ |
| 1679 |
relation: "partner.type", |
| 1680 |
string: "pokemon", |
| 1681 |
domain: [["color", "=", 2]], |
| 1682 |
onChange: true, |
| 1683 |
}); |
| 1684 |
PartnerType._fields.product_ids = fields.Many2many({ |
| 1685 |
string: "Product", |
| 1686 |
relation: "product.product", |
| 1687 |
}); |
| 1688 |
|
| 1689 |
for (let i = 0; i < 50; i++) { |
| 1690 |
const new_record_partner_type = { id: 100 + i, name: "batch" + i, color: 2 }; |
| 1691 |
PartnerType._records.push(new_record_partner_type); |
| 1692 |
} |
| 1693 |
|
| 1694 |
PartnerType._views = { |
| 1695 |
list: '<list><field name="name"/></list>', |
| 1696 |
search: '<search><field name="name"/><field name="color"/></search>', |
| 1697 |
}; |
| 1698 |
onRpc("get_formview_id", (args) => { |
| 1699 |
expect(args.args[0]).toEqual([1]); |
| 1700 |
}); |
| 1701 |
|
| 1702 |
await mountView({ |
| 1703 |
type: "form", |
| 1704 |
resModel: "partner", |
| 1705 |
arch: ` |
| 1706 |
<form> |
| 1707 |
<field name="timmy" widget="many2many"> |
| 1708 |
<list> |
| 1709 |
<field name="name"/> |
| 1710 |
<field name="product_ids" widget="many2many_tags"/> |
| 1711 |
</list> |
| 1712 |
</field> |
| 1713 |
</form>`, |
| 1714 |
resId: 1, |
| 1715 |
}); |
| 1716 |
|
| 1717 |
// First round: add 51 records in batch |
| 1718 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1719 |
|
| 1720 |
expect(".modal-lg").toHaveCount(1); |
| 1721 |
|
| 1722 |
await contains("thead input[type=checkbox]:eq(0)").click(); |
| 1723 |
await animationFrame(); |
| 1724 |
|
| 1725 |
await contains(".btn.btn-primary.o_select_button:eq(0)").click(); |
| 1726 |
|
| 1727 |
expect(".o_data_row").toHaveCount(51); // the 50 in batch + 'gold' |
| 1728 |
|
| 1729 |
expect( |
| 1730 |
".o_field_many2many.o_field_widget .o_field_x2many.o_field_x2many_list .o_cp_pager" |
| 1731 |
).toHaveCount(0); |
| 1732 |
|
| 1733 |
await clickSave(); |
| 1734 |
|
| 1735 |
expect( |
| 1736 |
".o_field_many2many.o_field_widget .o_field_x2many.o_field_x2many_list .o_cp_pager" |
| 1737 |
).toHaveCount(1); |
| 1738 |
|
| 1739 |
expect( |
| 1740 |
".o_field_many2many.o_field_widget .o_field_x2many.o_field_x2many_list .o_pager_value" |
| 1741 |
).toHaveText("1-40"); |
| 1742 |
|
| 1743 |
// Secound round: remove one record |
| 1744 |
await contains( |
| 1745 |
".o_field_many2many.o_field_widget .o_field_x2many.o_field_x2many_list .o_list_record_remove:eq(0)" |
| 1746 |
).click(); |
| 1747 |
expect( |
| 1748 |
".o_field_many2many.o_field_widget .o_field_x2many.o_field_x2many_list .o_pager_limit" |
| 1749 |
).toHaveText("50"); |
| 1750 |
|
| 1751 |
// Third round: re-add 1 records |
| 1752 |
await contains(".o_field_x2many_list_row_add a:eq(0)").click(); |
| 1753 |
|
| 1754 |
expect(".modal-lg").toHaveCount(1); |
| 1755 |
|
| 1756 |
await contains("thead input[type=checkbox]:eq(0)").click(); |
| 1757 |
await animationFrame(); |
| 1758 |
|
| 1759 |
await contains(".btn.btn-primary.o_select_button:eq(0)").click(); |
| 1760 |
|
| 1761 |
expect(".o_data_row").toHaveCount(41); |
| 1762 |
}); |
| 1763 |
|
| 1764 |
test("many2many kanban: action/type attribute", async () => { |
| 1765 |
Partner._records[0].timmy = [1]; |
| 1766 |
onRpc("a1", () => { |
| 1767 |
expect.step(`action: a1`); |
| 1768 |
return true; |
| 1769 |
}); |
| 1770 |
await mountView({ |
| 1771 |
type: "form", |
| 1772 |
resModel: "partner", |
| 1773 |
arch: ` |
| 1774 |
<form> |
| 1775 |
<field name="timmy"> |
| 1776 |
<kanban action="a1" type="object"> |
| 1777 |
<templates> |
| 1778 |
<t t-name="card"> |
| 1779 |
<field name="name"/> |
| 1780 |
</t> |
| 1781 |
</templates> |
| 1782 |
</kanban> |
| 1783 |
</field> |
| 1784 |
</form>`, |
| 1785 |
resId: 1, |
| 1786 |
}); |
| 1787 |
await contains(".o_kanban_record").click(); |
| 1788 |
expect.verifySteps(["action: a1"]); |
| 1789 |
}); |
| 1790 |
|
| 1791 |
test("select create with _view_ref as text", async () => { |
| 1792 |
PartnerType._views = { |
| 1793 |
[["list", "my.little.string"]]: `<list><field name="name"/></list>`, |
| 1794 |
}; |
| 1795 |
patchWithCleanup(Many2XAutocomplete.defaultProps, { |
| 1796 |
searchLimit: 1, |
| 1797 |
}); |
| 1798 |
let checkGetViews = false; |
| 1799 |
onRpc("get_views", (args) => { |
| 1800 |
if (checkGetViews) { |
| 1801 |
expect.step("get_views"); |
| 1802 |
expect(args.kwargs.views).toEqual([ |
| 1803 |
[false, "list"], |
| 1804 |
[false, "search"], |
| 1805 |
]); |
| 1806 |
expect(args.kwargs.context.list_view_ref).toBe("my.little.string"); |
| 1807 |
} |
| 1808 |
}); |
| 1809 |
|
| 1810 |
await mountView({ |
| 1811 |
type: "form", |
| 1812 |
resId: 1, |
| 1813 |
resModel: "partner", |
| 1814 |
arch: ` |
| 1815 |
<form> |
| 1816 |
<field name="timmy" widget="many2many_tags" context="{ 'list_view_ref': 'my.little.string' }"/> |
| 1817 |
</form>`, |
| 1818 |
}); |
| 1819 |
await contains(".o_field_many2many_selection input").click(); |
| 1820 |
checkGetViews = true; |
| 1821 |
await contains(".o_m2o_dropdown_option_search_more").click(); |
| 1822 |
expect.verifySteps([`get_views`]); |
| 1823 |
|
| 1824 |
expect(".modal").toHaveCount(1); |
| 1825 |
expect(".modal-title").toHaveText("Search: pokemon"); |
| 1826 |
}); |
| 1827 |
|
| 1828 |
test("many2many basic keys in field evalcontext -- in list", async () => { |
| 1829 |
expect.assertions(5); |
| 1830 |
PartnerType._fields.partner_id = fields.Many2one({ |
| 1831 |
string: "Partners", |
| 1832 |
relation: "partner", |
| 1833 |
}); |
| 1834 |
Partner._records.push({ id: 7, name: "default partner" }); |
| 1835 |
PartnerType._views = { |
| 1836 |
form: `<form><field name="partner_id" /></form>`, |
| 1837 |
}; |
| 1838 |
|
| 1839 |
cookie.set("cids", "3"); |
| 1840 |
serverState.companies = [ |
| 1841 |
{ id: 3, name: "Hermit", sequence: 1 }, |
| 1842 |
{ id: 2, name: "Herman's", sequence: 2 }, |
| 1843 |
{ id: 1, name: "Heroes TM", sequence: 3 }, |
| 1844 |
]; |
| 1845 |
onRpc("onchange", (args) => { |
| 1846 |
expect(args.kwargs.context.uid).toBe(7); |
| 1847 |
expect(args.kwargs.context.allowed_company_ids).toEqual([3]); |
| 1848 |
expect(args.kwargs.context.company_id).toBe(3); |
| 1849 |
}); |
| 1850 |
|
| 1851 |
await mountView({ |
| 1852 |
type: "list", |
| 1853 |
resModel: "partner", |
| 1854 |
arch: ` |
| 1855 |
<list editable="top"> |
| 1856 |
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': uid, 'allowed_company_ids': allowed_company_ids, 'company_id': current_company_id}"/> |
| 1857 |
</list>`, |
| 1858 |
}); |
| 1859 |
|
| 1860 |
await contains(".o_data_cell").click(); |
| 1861 |
await contains(".o_field_many2many_selection input").edit("indianapolis", { confirm: false }); |
| 1862 |
await runAllTimers(); |
| 1863 |
await contains(".o_m2o_dropdown_option_create_edit").click(); |
| 1864 |
expect(".modal .o_field_many2one").toHaveCount(1); |
| 1865 |
expect(".modal .o_field_many2one input").toHaveValue("default partner"); |
| 1866 |
}); |
| 1867 |
|
| 1868 |
test("many2many basic keys in field evalcontext -- in form", async () => { |
| 1869 |
expect.assertions(5); |
| 1870 |
PartnerType._fields.partner_id = fields.Many2one({ |
| 1871 |
string: "Partners", |
| 1872 |
relation: "partner", |
| 1873 |
}); |
| 1874 |
Partner._records.push({ id: 7, name: "default partner" }); |
| 1875 |
PartnerType._views = { |
| 1876 |
form: `<form><field name="partner_id" /></form>`, |
| 1877 |
}; |
| 1878 |
cookie.set("cids", "3"); |
| 1879 |
serverState.companies = [ |
| 1880 |
{ id: 3, name: "Hermit", sequence: 1 }, |
| 1881 |
{ id: 2, name: "Herman's", sequence: 2 }, |
| 1882 |
{ id: 1, name: "Heroes TM", sequence: 3 }, |
| 1883 |
]; |
| 1884 |
|
| 1885 |
onRpc("onchange", (args) => { |
| 1886 |
expect(args.kwargs.context.default_partner_id).toBe(7); |
| 1887 |
expect(args.kwargs.context.allowed_company_ids).toEqual([3]); |
| 1888 |
expect(args.kwargs.context.company_id).toBe(3); |
| 1889 |
}); |
| 1890 |
|
| 1891 |
await mountView({ |
| 1892 |
type: "form", |
| 1893 |
resId: 1, |
| 1894 |
resModel: "partner", |
| 1895 |
arch: ` |
| 1896 |
<form> |
| 1897 |
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': uid, 'allowed_company_ids': allowed_company_ids, 'company_id': current_company_id}"/> |
| 1898 |
</form>`, |
| 1899 |
}); |
| 1900 |
|
| 1901 |
await contains(".o_field_many2many_selection input").edit("indianapolis", { confirm: false }); |
| 1902 |
await runAllTimers(); |
| 1903 |
await contains(".o_m2o_dropdown_option_create_edit").click(); |
| 1904 |
expect(".modal .o_field_many2one").toHaveCount(1); |
| 1905 |
expect(".modal .o_field_many2one input").toHaveValue("default partner"); |
| 1906 |
}); |
| 1907 |
|
| 1908 |
test("many2many basic keys in field evalcontext -- in a x2many in form", async () => { |
| 1909 |
expect.assertions(5); |
| 1910 |
PartnerType._fields.partner_id = fields.Many2one({ |
| 1911 |
string: "Partners", |
| 1912 |
relation: "partner", |
| 1913 |
}); |
| 1914 |
Partner._records.push({ id: 7, name: "default partner" }); |
| 1915 |
PartnerType._views = { |
| 1916 |
form: `<form><field name="partner_id" /></form>`, |
| 1917 |
}; |
| 1918 |
|
| 1919 |
const rec = Partner._records.find(({ id }) => id === 2); |
| 1920 |
rec.p = [1]; |
| 1921 |
cookie.set("cids", "3"); |
| 1922 |
serverState.companies = [ |
| 1923 |
{ id: 3, name: "Hermit", sequence: 1 }, |
| 1924 |
{ id: 2, name: "Herman's", sequence: 2 }, |
| 1925 |
{ id: 1, name: "Heroes TM", sequence: 3 }, |
| 1926 |
]; |
| 1927 |
onRpc("onchange", (args) => { |
| 1928 |
expect(args.kwargs.context.default_partner_id).toBe(7); |
| 1929 |
expect(args.kwargs.context.allowed_company_ids).toEqual([3]); |
| 1930 |
expect(args.kwargs.context.company_id).toBe(3); |
| 1931 |
}); |
| 1932 |
|
| 1933 |
await mountView({ |
| 1934 |
type: "form", |
| 1935 |
resId: 2, |
| 1936 |
resModel: "partner", |
| 1937 |
arch: ` |
| 1938 |
<form> |
| 1939 |
<field name="p"> |
| 1940 |
<list editable="top"> |
| 1941 |
<field name="timmy" widget="many2many_tags" context="{ 'default_partner_id': uid, 'allowed_company_ids': allowed_company_ids, 'company_id': current_company_id}"/> |
| 1942 |
</list> |
| 1943 |
</field> |
| 1944 |
</form>`, |
| 1945 |
}); |
| 1946 |
|
| 1947 |
await contains(".o_data_cell").click(); |
| 1948 |
await contains(".o_field_many2many_selection input").edit("indianapolis", { confirm: false }); |
| 1949 |
await runAllTimers(); |
| 1950 |
await contains(".o_m2o_dropdown_option_create_edit").click(); |
| 1951 |
expect(".modal .o_field_many2one").toHaveCount(1); |
| 1952 |
expect(".modal .o_field_many2one input").toHaveValue("default partner"); |
| 1953 |
}); |
| 1954 |
|
| 1955 |
test("`this` inside rendererProps should reference the component", async () => { |
| 1956 |
class CustomX2manyField extends X2ManyField { |
| 1957 |
setup() { |
| 1958 |
super.setup(); |
| 1959 |
this.selectCreate = (params) => { |
| 1960 |
expect.step("selectCreate"); |
| 1961 |
expect(this.num).toBe(2); |
| 1962 |
}; |
| 1963 |
this.num = 1; |
| 1964 |
} |
| 1965 |
|
| 1966 |
async onAdd({ context, editable } = {}) { |
| 1967 |
this.num = 2; |
| 1968 |
expect.step("onAdd"); |
| 1969 |
super.onAdd(...arguments); |
| 1970 |
} |
| 1971 |
} |
| 1972 |
|
| 1973 |
const customX2ManyField = { |
| 1974 |
...x2ManyField, |
| 1975 |
component: CustomX2manyField, |
| 1976 |
}; |
| 1977 |
registry.category("fields").add("custom", customX2ManyField); |
| 1978 |
|
| 1979 |
await mountView({ |
| 1980 |
type: "form", |
| 1981 |
resModel: "partner", |
| 1982 |
arch: ` |
| 1983 |
<form> |
| 1984 |
<field name="timmy" widget="custom"> |
| 1985 |
<list editable="top"> |
| 1986 |
<field name="display_name"/> |
| 1987 |
</list> |
| 1988 |
<form> |
| 1989 |
<field name="display_name" /> |
| 1990 |
</form> |
| 1991 |
</field> |
| 1992 |
</form>`, |
| 1993 |
resId: 1, |
| 1994 |
}); |
| 1995 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 1996 |
expect.verifySteps(["onAdd", "selectCreate"]); |
| 1997 |
}); |
| 1998 |
|
| 1999 |
test("empty many2many tags field with no result", async () => { |
| 2000 |
patchWithCleanup(Many2XAutocomplete.prototype, { |
| 2001 |
getCreationContext(value) { |
| 2002 |
expect(value).toBe(""); |
| 2003 |
const context = super.getCreationContext(value); |
| 2004 |
expect(context[`default_${this.props.nameCreateField}`]).toBe(undefined); |
| 2005 |
return context; |
| 2006 |
}, |
| 2007 |
}); |
| 2008 |
class M2M extends models.Model { |
| 2009 |
m2m = fields.Many2many({ relation: "m2m" }); |
| 2010 |
} |
| 2011 |
defineModels([M2M]); |
| 2012 |
await mountView({ |
| 2013 |
type: "form", |
| 2014 |
resModel: "m2m", |
| 2015 |
arch: ` |
| 2016 |
<form> |
| 2017 |
<sheet> |
| 2018 |
<group> |
| 2019 |
<field name="m2m" widget="many2many_tags"/> |
| 2020 |
</group> |
| 2021 |
</sheet> |
| 2022 |
</form>`, |
| 2023 |
}); |
| 2024 |
|
| 2025 |
await contains(".o_field_many2many_selection input").click(); |
| 2026 |
expect(".dropdown-menu li.o_m2o_dropdown_option").toHaveCount(1); |
| 2027 |
expect(".dropdown-menu li.o_m2o_dropdown_option").toHaveText("Create..."); |
| 2028 |
expect(".dropdown-menu li.o_m2o_start_typing").toHaveCount(0); |
| 2029 |
|
| 2030 |
await contains(".dropdown-menu li.o_m2o_dropdown_option").click(); |
| 2031 |
expect(".o_dialog").toHaveCount(1); |
| 2032 |
expect(".o_dialog .o_field_many2many_selection input").toHaveValue(""); |
| 2033 |
press("Esc"); |
| 2034 |
await animationFrame(); |
| 2035 |
expect(".o_dialog").toHaveCount(0); |
| 2036 |
|
| 2037 |
await contains(".o_field_many2many_selection input").edit("abc", { confirm: false }); |
| 2038 |
await runAllTimers(); |
| 2039 |
|
| 2040 |
expect(".dropdown-menu li.o_m2o_dropdown_option").toHaveCount(2); |
| 2041 |
expect(".dropdown-menu li.o_m2o_start_typing").toHaveCount(0); |
| 2042 |
expect(".dropdown-menu li.o_m2o_no_result").toHaveCount(0); |
| 2043 |
}); |
| 2044 |
|
| 2045 |
test("highlight search in many2many", async () => { |
| 2046 |
await mountView({ |
| 2047 |
type: "form", |
| 2048 |
resModel: "partner", |
| 2049 |
arch: `<form><field name="p" widget="many2many_tags"/></form>`, |
| 2050 |
}); |
| 2051 |
await contains(".o_field_widget[name=p] input").edit("rec", { confirm: false }); |
| 2052 |
await runAllTimers(); |
| 2053 |
expect(`.o-autocomplete.dropdown li a > span`).toHaveCount(2); |
| 2054 |
expect(`.o-autocomplete.dropdown li:eq(0) a > span`).toHaveInnerHTML(` |
| 2055 |
<span> |
| 2056 |
first |
| 2057 |
<span class="text-primary fw-bold"> |
| 2058 |
rec |
| 2059 |
</span> |
| 2060 |
ord |
| 2061 |
</span>`); |
| 2062 |
expect(`.o-autocomplete.dropdown li:eq(1) a > span`).toHaveInnerHTML(` |
| 2063 |
<span> |
| 2064 |
second |
| 2065 |
<span class="text-primary fw-bold"> |
| 2066 |
rec |
| 2067 |
</span> |
| 2068 |
ord |
| 2069 |
</span> |
| 2070 |
`); |
| 2071 |
}); |
| 2072 |
|
| 2073 |
test("test view button warning on opening unsaved record", async () => { |
| 2074 |
// Making the field required so that we get a sticky notification |
| 2075 |
Turtle._fields.name.required = true; |
| 2076 |
|
| 2077 |
mockService("notification", { |
| 2078 |
add(message, options) { |
| 2079 |
expect.step("notification"); |
| 2080 |
expect(message).toBe("Please save your changes first"); |
| 2081 |
expect(options).toEqual({ type: "danger" }); |
| 2082 |
}, |
| 2083 |
}); |
| 2084 |
|
| 2085 |
await mountView({ |
| 2086 |
type: "form", |
| 2087 |
resModel: "partner", |
| 2088 |
arch: ` |
| 2089 |
<form> |
| 2090 |
<field name="turtles" context="{'default_turtle_trululu': id}" > |
| 2091 |
<list editable="bottom" open_form_view="True"> |
| 2092 |
<field name="name"/> |
| 2093 |
<field name="turtle_foo"/> |
| 2094 |
</list> |
| 2095 |
</field> |
| 2096 |
</form> |
| 2097 |
`, |
| 2098 |
}); |
| 2099 |
|
| 2100 |
await contains(".o_field_x2many_list_row_add a").click(); |
| 2101 |
await contains(".o_list_record_open_form_view button").click(); |
| 2102 |
|
| 2103 |
expect.verifySteps(["notification"]); |
| 2104 |
}); |