| 1 |
import { expect, test } from "@odoo/hoot"; |
| 2 |
import { |
| 3 |
check, |
| 4 |
dblclick, |
| 5 |
pointerDown, |
| 6 |
queryAll, |
| 7 |
queryAllTexts, |
| 8 |
queryFirst, |
| 9 |
select, |
| 10 |
} from "@odoo/hoot-dom"; |
| 11 |
import { animationFrame, Deferred, runAllTimers } from "@odoo/hoot-mock"; |
| 12 |
import { |
| 13 |
contains, |
| 14 |
defineModels, |
| 15 |
fields, |
| 16 |
getMockEnv, |
| 17 |
models, |
| 18 |
mountView, |
| 19 |
onRpc, |
| 20 |
patchWithCleanup, |
| 21 |
serverState, |
| 22 |
toggleSearchBarMenu, |
| 23 |
} from "@web/../tests/web_test_helpers"; |
| 24 |
|
| 25 |
import { download } from "@web/core/network/download"; |
| 26 |
|
| 27 |
async function exportAllAction() { |
| 28 |
await contains(".o_cp_action_menus .dropdown-toggle").click(); |
| 29 |
await contains(".o-dropdown--menu .dropdown-item").click(); |
| 30 |
} |
| 31 |
const openExportDialog = async () => { |
| 32 |
if (getMockEnv().isSmall) { |
| 33 |
await pointerDown(".o_data_row:nth-child(1)"); |
| 34 |
await runAllTimers(); |
| 35 |
} else { |
| 36 |
await contains(".o_list_record_selector input[type='checkbox']").click(); |
| 37 |
} |
| 38 |
await contains(".o_control_panel .o_cp_action_menus .dropdown-toggle").click(); |
| 39 |
await contains(".dropdown-menu span:contains(Export)").click(); |
| 40 |
await animationFrame(); |
| 41 |
}; |
| 42 |
|
| 43 |
class Partner extends models.Model { |
| 44 |
display_name = fields.Char(); |
| 45 |
foo = fields.Char(); |
| 46 |
bar = fields.Boolean(); |
| 47 |
|
| 48 |
_records = [ |
| 49 |
{ id: 1, foo: "blip", display_name: "blipblip", bar: true }, |
| 50 |
{ id: 2, foo: "ta tata ta ta", display_name: "macgyver", bar: false }, |
| 51 |
{ id: 3, foo: "piou piou", display_name: "Jack O'Neill", bar: true }, |
| 52 |
]; |
| 53 |
} |
| 54 |
class User extends models.Model { |
| 55 |
_name = "res.users"; |
| 56 |
has_group() { |
| 57 |
return true; |
| 58 |
} |
| 59 |
} |
| 60 |
class IrExports extends models.Model { |
| 61 |
_name = "ir.exports"; |
| 62 |
name = fields.Char(); |
| 63 |
resource = fields.Char(); |
| 64 |
export_fields = fields.One2many({ relation: "ir.exports.line" }); |
| 65 |
} |
| 66 |
class IrExportsLine extends models.Model { |
| 67 |
_name = "ir.exports.line"; |
| 68 |
name = fields.Char(); |
| 69 |
export_id = fields.Many2one({ relation: "ir.exports" }); |
| 70 |
} |
| 71 |
defineModels([Partner, User, IrExports, IrExportsLine]); |
| 72 |
|
| 73 |
const fetchedFields = { |
| 74 |
root: [ |
| 75 |
{ |
| 76 |
field_type: "one2many", |
| 77 |
string: "Activities", |
| 78 |
required: false, |
| 79 |
value: "activity_ids/id", |
| 80 |
id: "activity_ids", |
| 81 |
params: { |
| 82 |
model: "mail.activity", |
| 83 |
prefix: "activity_ids", |
| 84 |
name: "Activities", |
| 85 |
}, |
| 86 |
relation_field: "res_id", |
| 87 |
children: true, |
| 88 |
}, |
| 89 |
{ |
| 90 |
children: false, |
| 91 |
field_type: "char", |
| 92 |
id: "foo", |
| 93 |
relation_field: null, |
| 94 |
required: true, |
| 95 |
string: "Foo", |
| 96 |
value: "foo", |
| 97 |
}, |
| 98 |
{ |
| 99 |
children: false, |
| 100 |
field_type: "boolean", |
| 101 |
id: "bar", |
| 102 |
relation_field: null, |
| 103 |
required: false, |
| 104 |
string: "Bar", |
| 105 |
value: "bar", |
| 106 |
}, |
| 107 |
], |
| 108 |
activity_ids: [ |
| 109 |
{ |
| 110 |
field_type: "one2many", |
| 111 |
string: "Attendants", |
| 112 |
required: false, |
| 113 |
value: "activity_ids/id", |
| 114 |
id: "activity_ids/partner_ids", |
| 115 |
params: { |
| 116 |
model: "mail.activity", |
| 117 |
prefix: "partner_ids", |
| 118 |
name: "Company", |
| 119 |
}, |
| 120 |
children: true, |
| 121 |
}, |
| 122 |
{ |
| 123 |
field_type: "one2many", |
| 124 |
string: "Activity types", |
| 125 |
required: false, |
| 126 |
value: "activity_ids/id", |
| 127 |
id: "activity_ids/types", |
| 128 |
params: { |
| 129 |
model: "mail.activity", |
| 130 |
prefix: "activity_types", |
| 131 |
name: "Activity types", |
| 132 |
}, |
| 133 |
children: true, |
| 134 |
}, |
| 135 |
{ |
| 136 |
id: "activity_ids/mail_template_ids", |
| 137 |
string: "Activities/Email templates", |
| 138 |
value: "activity_ids/mail_template_ids/id", |
| 139 |
children: true, |
| 140 |
field_type: "many2many", |
| 141 |
required: false, |
| 142 |
relation_field: null, |
| 143 |
default_export: false, |
| 144 |
params: { |
| 145 |
model: "mail.template", |
| 146 |
prefix: "activity_ids/mail_template_ids", |
| 147 |
name: "Activities/Email templates", |
| 148 |
}, |
| 149 |
}, |
| 150 |
], |
| 151 |
partner_ids: [ |
| 152 |
{ |
| 153 |
children: false, |
| 154 |
field_type: "many2one", |
| 155 |
id: "activity_ids/partner_ids/company_ids", |
| 156 |
relation_field: null, |
| 157 |
string: "Company", |
| 158 |
value: "company_ids", |
| 159 |
}, |
| 160 |
{ |
| 161 |
children: false, |
| 162 |
field_type: "char", |
| 163 |
id: "activity_ids/partner_ids/name", |
| 164 |
relation_field: null, |
| 165 |
string: "Partner name", |
| 166 |
value: "partner_name", |
| 167 |
}, |
| 168 |
], |
| 169 |
}; |
| 170 |
|
| 171 |
test("Export dialog UI test", async () => { |
| 172 |
onRpc("/web/export/formats", () => [ |
| 173 |
{ tag: "csv", label: "CSV" }, |
| 174 |
{ tag: "xls", label: "Excel" }, |
| 175 |
]); |
| 176 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 177 |
|
| 178 |
await mountView({ |
| 179 |
type: "list", |
| 180 |
resModel: "partner", |
| 181 |
arch: `<list><field name="foo"/></list>`, |
| 182 |
loadActionMenus: true, |
| 183 |
}); |
| 184 |
|
| 185 |
await openExportDialog(); |
| 186 |
expect(`.o_dialog`).toHaveCount(1); |
| 187 |
expect(`.o_dialog .o_export_tree_item`).toHaveCount(3, { |
| 188 |
message: "There should be only three items visible", |
| 189 |
}); |
| 190 |
await contains(".modal .o_export_search_input").edit("ac"); |
| 191 |
expect(`.modal .o_export_tree_item`).toHaveCount(1, { |
| 192 |
message: "Only matching item is visible", |
| 193 |
}); |
| 194 |
await contains(".modal .o_export_tree_item .o_add_field").click(); |
| 195 |
expect(`.modal .o_export_field`).toHaveCount(2, { |
| 196 |
message: "There should be two fields in export field list", |
| 197 |
}); |
| 198 |
expect(".modal .o_export_field:nth-child(2)").toHaveText("Activities"); |
| 199 |
expect(".o_export_search_input").toHaveValue("ac", { |
| 200 |
message: "Search input still contains the search string", |
| 201 |
}); |
| 202 |
await contains(".modal .o_export_search_input").edit(""); |
| 203 |
expect(".modal .o_export_tree_item:nth-child(2) .o_tree_column").toHaveClass("fw-bolder"); |
| 204 |
await contains(".modal .o_export_field:first-child .o_remove_field").click(); |
| 205 |
expect(`.modal .o_export_field`).toHaveCount(1); |
| 206 |
}); |
| 207 |
|
| 208 |
test("Export dialog: interacting with export templates", async () => { |
| 209 |
onRpc("/web/export/formats", () => [ |
| 210 |
{ tag: "csv", label: "CSV" }, |
| 211 |
{ tag: "xls", label: "Excel" }, |
| 212 |
]); |
| 213 |
onRpc("/web/export/get_fields", () => [ |
| 214 |
...fetchedFields.root, |
| 215 |
{ |
| 216 |
children: false, |
| 217 |
field_type: "string", |
| 218 |
id: "third_field", |
| 219 |
relation_field: null, |
| 220 |
required: false, |
| 221 |
string: "Third field selected", |
| 222 |
value: "third_field", |
| 223 |
}, |
| 224 |
]); |
| 225 |
onRpc("/web/export/namelist", async (request) => { |
| 226 |
const { params } = await request.json(); |
| 227 |
if (params.export_id === 1) { |
| 228 |
return [{ id: "activity_ids", string: "Activities" }]; |
| 229 |
} |
| 230 |
return []; |
| 231 |
}); |
| 232 |
onRpc(({ args, method, model, kwargs }) => { |
| 233 |
switch (method) { |
| 234 |
case "search_read": |
| 235 |
expect(kwargs.domain).toEqual([["resource", "=", "partner"]], { |
| 236 |
message: "rpc contains the right domain filter to fetch templates", |
| 237 |
}); |
| 238 |
return [{ id: 1, name: "Activities template" }]; |
| 239 |
case "create": |
| 240 |
expect(model).toBe("ir.exports"); |
| 241 |
expect(args[0][0].name).toBe("Export template", { |
| 242 |
message: "the template name is correctly sent", |
| 243 |
}); |
| 244 |
return [2]; |
| 245 |
} |
| 246 |
}); |
| 247 |
|
| 248 |
await mountView({ |
| 249 |
type: "list", |
| 250 |
resModel: "partner", |
| 251 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 252 |
loadActionMenus: true, |
| 253 |
}); |
| 254 |
|
| 255 |
await openExportDialog(); |
| 256 |
|
| 257 |
expect(`.o_dialog`).toHaveCount(1); |
| 258 |
expect(".o_export_tree_item:nth-child(2) .o_add_field").toHaveClass("o_inactive", { |
| 259 |
message: "fields already selected cannot be added anymore", |
| 260 |
}); |
| 261 |
|
| 262 |
// load a template which contains the activity_ids field |
| 263 |
await select("1", { target: ".o_exported_lists_select" }); |
| 264 |
await animationFrame(); |
| 265 |
expect(`.o_fields_list .o_export_field`).toHaveCount(1); |
| 266 |
expect(`.o_fields_list .o_export_field`).toHaveText("Activities"); |
| 267 |
await contains(".o_export_tree_item:nth-child(2) .o_add_field").click(); |
| 268 |
expect(`.o_exported_lists_select`).toHaveCount(1); |
| 269 |
expect(`.o_save_list_btn`).toHaveCount(0); |
| 270 |
expect(`.o_cancel_list_btn .fa-undo`).toHaveCount(1); |
| 271 |
expect(`.o_fields_list .o_export_field`).toHaveCount(2); |
| 272 |
await contains(".o_cancel_list_btn").click(); |
| 273 |
expect(`.o_fields_list .o_export_field`).toHaveCount(1, { |
| 274 |
message: "the template has been reset and the added field is no longer in the list", |
| 275 |
}); |
| 276 |
await contains(".o_export_tree_item:nth-child(2) .o_add_field").click(); |
| 277 |
await select("new_template", { target: ".o_exported_lists_select" }); |
| 278 |
await animationFrame(); |
| 279 |
expect(`.o_exported_lists_select`).toHaveCount(0); |
| 280 |
expect(`input.o_save_list_name`).toHaveCount(1, { |
| 281 |
message: "an input is present to edit the current template name", |
| 282 |
}); |
| 283 |
await contains(".o_save_list_btn").click(); |
| 284 |
expect(".o_notification").toHaveText("Please enter save field list name"); |
| 285 |
await contains(".o_cancel_list_btn").click(); |
| 286 |
expect(`.o_exported_lists_select`).toHaveCount(1); |
| 287 |
await contains(".o_export_tree_item:nth-child(3) .o_add_field").click(); |
| 288 |
expect(`.o_fields_list .o_export_field`).toHaveCount(3); |
| 289 |
await select("new_template", { target: ".o_exported_lists_select" }); |
| 290 |
await animationFrame(); |
| 291 |
await contains(".o_save_list_name").edit("Export template"); |
| 292 |
await contains(".o_save_list_btn").click(); |
| 293 |
expect(".o_exported_lists_select").toHaveValue("2", { |
| 294 |
message: "the new template is now selected", |
| 295 |
}); |
| 296 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual([ |
| 297 |
"Activities", |
| 298 |
"Foo", |
| 299 |
"Bar", |
| 300 |
]); |
| 301 |
await select("", { target: ".o_exported_lists_select" }); |
| 302 |
await animationFrame(); |
| 303 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual( |
| 304 |
["Activities", "Foo", "Bar"], |
| 305 |
{ |
| 306 |
message: "unselecting an export template has not changed the export list", |
| 307 |
} |
| 308 |
); |
| 309 |
expect(".o_delete_exported_list").toHaveCount(0, { |
| 310 |
message: "trash icon is not visible when no template has been selected", |
| 311 |
}); |
| 312 |
await select("2", { target: ".o_exported_lists_select" }); |
| 313 |
await animationFrame(); |
| 314 |
await contains(".o_delete_exported_list").click(); |
| 315 |
expect(queryAll(".o_dialog .modal-body")[1]).toHaveText( |
| 316 |
"Do you really want to delete this export template?" |
| 317 |
); |
| 318 |
await contains(".o-overlay-item:nth-child(2) .btn-primary").click(); |
| 319 |
expect(".o_exported_lists_select").toHaveValue("", { |
| 320 |
message: "the template list has been reset", |
| 321 |
}); |
| 322 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual(["Foo"]); |
| 323 |
}); |
| 324 |
|
| 325 |
test("Export dialog: interacting with export templates in debug", async () => { |
| 326 |
serverState.debug = "1"; |
| 327 |
|
| 328 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 329 |
onRpc("/web/export/get_fields", () => [...fetchedFields.root]); |
| 330 |
onRpc("/web/export/namelist", async (request) => { |
| 331 |
const { params } = await request.json(); |
| 332 |
if (params.export_id === 1) { |
| 333 |
return [{ id: "activity_ids", string: "Activities" }]; |
| 334 |
} |
| 335 |
return []; |
| 336 |
}); |
| 337 |
onRpc(({ method }) => { |
| 338 |
if (method === "search_read") { |
| 339 |
return [{ id: 1, name: "Activities template" }]; |
| 340 |
} |
| 341 |
}); |
| 342 |
|
| 343 |
await mountView({ |
| 344 |
type: "list", |
| 345 |
resModel: "partner", |
| 346 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 347 |
loadActionMenus: true, |
| 348 |
}); |
| 349 |
|
| 350 |
await openExportDialog(); |
| 351 |
|
| 352 |
expect(".o_fields_list .o_export_field").toHaveText("Foo (foo)"); |
| 353 |
await select("1", { target: ".o_exported_lists_select" }); |
| 354 |
await animationFrame(); |
| 355 |
expect(".o_fields_list .o_export_field").toHaveCount(1); |
| 356 |
expect(".o_fields_list .o_export_field").toHaveText("Activities (activity_ids)"); |
| 357 |
}); |
| 358 |
|
| 359 |
test.tags("desktop"); |
| 360 |
test("Export dialog: interacting with available fields", async () => { |
| 361 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 362 |
onRpc("/web/export/get_fields", async (request) => { |
| 363 |
const { params } = await request.json(); |
| 364 |
if (!params.parent_field) { |
| 365 |
return fetchedFields.root; |
| 366 |
} |
| 367 |
if (params.prefix === "partner_ids") { |
| 368 |
expect.step("fetch fields for 'partner_ids'"); |
| 369 |
} |
| 370 |
return fetchedFields[params.prefix]; |
| 371 |
}); |
| 372 |
|
| 373 |
await mountView({ |
| 374 |
type: "list", |
| 375 |
resModel: "partner", |
| 376 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 377 |
loadActionMenus: true, |
| 378 |
}); |
| 379 |
|
| 380 |
await openExportDialog(); |
| 381 |
|
| 382 |
const firstField = ".o_left_field_panel .o_export_tree_item:first-child "; |
| 383 |
await contains(firstField).click(); |
| 384 |
|
| 385 |
// show then hide content for the 'partner_ids' field. Then show it again |
| 386 |
await contains(firstField + ".o_export_tree_item").click(); |
| 387 |
await contains(firstField + ".o_export_tree_item").click(); |
| 388 |
await contains(firstField + ".o_export_tree_item").click(); |
| 389 |
// we should only make one rpc to fetch fields |
| 390 |
expect.verifySteps(["fetch fields for 'partner_ids'"]); |
| 391 |
expect( |
| 392 |
".o_export_tree_item[data-field_id='activity_ids/partner_ids/company_ids'] .o_expand_parent" |
| 393 |
).toHaveCount(0, { |
| 394 |
message: "available fields are limited to 2 levels of subfields", |
| 395 |
}); |
| 396 |
await dblclick(".o_export_tree_item[data-field_id='activity_ids/partner_ids/company_ids']"); |
| 397 |
await animationFrame(); |
| 398 |
expect( |
| 399 |
".o_export_tree_item[data-field_id='activity_ids/partner_ids/company_ids'] .o_add_field" |
| 400 |
).toHaveClass("o_inactive", { |
| 401 |
message: "field has been added by double clicking on it and cannot be added anymore", |
| 402 |
}); |
| 403 |
await contains(firstField + ".o_add_field").click(); |
| 404 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual([ |
| 405 |
"Foo", |
| 406 |
"Company", |
| 407 |
"Activities", |
| 408 |
]); |
| 409 |
await dblclick(".o_export_tree_item[data-field_id='activity_ids']"); |
| 410 |
await animationFrame(); |
| 411 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual( |
| 412 |
["Foo", "Company", "Activities"], |
| 413 |
{ |
| 414 |
message: "double clicking on an expandable field does not add the field", |
| 415 |
} |
| 416 |
); |
| 417 |
await contains(".o_export_field:first-child").dragAndDrop( |
| 418 |
queryFirst(".o_export_field:nth-child(2)") |
| 419 |
); |
| 420 |
await contains(".o_export_field:nth-child(3)").dragAndDrop( |
| 421 |
queryFirst(".o_export_field:first-child") |
| 422 |
); |
| 423 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual([ |
| 424 |
"Activities", |
| 425 |
"Company", |
| 426 |
"Foo", |
| 427 |
]); |
| 428 |
await contains(".modal .o_export_field:nth-child(2) .o_remove_field").click(); |
| 429 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual(["Activities", "Foo"]); |
| 430 |
await contains( |
| 431 |
firstField + |
| 432 |
".o_export_tree_item[data-field_id='activity_ids/partner_ids/name'] .o_add_field" |
| 433 |
).click(); |
| 434 |
expect(queryAllTexts(".o_right_field_panel .o_export_field")).toEqual([ |
| 435 |
"Activities", |
| 436 |
"Foo", |
| 437 |
"Partner name", |
| 438 |
]); |
| 439 |
}); |
| 440 |
|
| 441 |
test("Export dialog: compatible and export type options", async () => { |
| 442 |
patchWithCleanup(download, { |
| 443 |
_download: (options) => { |
| 444 |
expect.step(options.url); |
| 445 |
expect(JSON.parse(options.data.data)["import_compat"]).toBe(true); |
| 446 |
}, |
| 447 |
}); |
| 448 |
onRpc("/web/export/formats", () => [ |
| 449 |
{ tag: "csv", label: "CSV" }, |
| 450 |
{ tag: "xls", label: "Excel" }, |
| 451 |
{ tag: "wow", label: "WOW" }, |
| 452 |
]); |
| 453 |
let checkpoint; |
| 454 |
const def = new Deferred(); |
| 455 |
onRpc("/web/export/get_fields", async () => { |
| 456 |
if (checkpoint) { |
| 457 |
await def; |
| 458 |
} |
| 459 |
checkpoint = true; |
| 460 |
return fetchedFields.root; |
| 461 |
}); |
| 462 |
|
| 463 |
await mountView({ |
| 464 |
type: "list", |
| 465 |
resModel: "partner", |
| 466 |
arch: `<list><field name="foo"/></list>`, |
| 467 |
loadActionMenus: true, |
| 468 |
}); |
| 469 |
|
| 470 |
await openExportDialog(); |
| 471 |
expect("input[name='o_export_format_name']").toHaveCount(3); |
| 472 |
expect("[name=o_export_format_name][value=csv]").toBeChecked(); |
| 473 |
expect(".o_export_format div:nth-of-type(3)").toHaveText("WOW"); |
| 474 |
await check(".o_export_format div:nth-of-type(3) input"); |
| 475 |
await animationFrame(); |
| 476 |
expect(".o_export_tree_item").toHaveCount(3); |
| 477 |
await contains(".o_import_compat input").click(); |
| 478 |
expect(".o_export_tree_item").toHaveCount(3); |
| 479 |
def.resolve(); |
| 480 |
await animationFrame(); |
| 481 |
await contains(".o_select_button").click(); |
| 482 |
// download file has been called with the correct url |
| 483 |
expect.verifySteps(["/web/export/wow"]); |
| 484 |
}); |
| 485 |
|
| 486 |
test("toggling import compatibility after adding an expanded field", async () => { |
| 487 |
patchWithCleanup(download, { |
| 488 |
_download: (options) => { |
| 489 |
expect.step(options.url); |
| 490 |
expect(JSON.parse(options.data.data)["import_compat"]).toBe(true); |
| 491 |
}, |
| 492 |
}); |
| 493 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 494 |
onRpc("/web/export/get_fields", async (request) => { |
| 495 |
const { params } = await request.json(); |
| 496 |
if (!params.parent_field) { |
| 497 |
return fetchedFields.root; |
| 498 |
} |
| 499 |
return fetchedFields[params.prefix]; |
| 500 |
}); |
| 501 |
|
| 502 |
await mountView({ |
| 503 |
type: "list", |
| 504 |
resModel: "partner", |
| 505 |
arch: `<list><field name="foo"/></list>`, |
| 506 |
loadActionMenus: true, |
| 507 |
}); |
| 508 |
|
| 509 |
await openExportDialog(); |
| 510 |
|
| 511 |
await contains("[data-field_id='activity_ids']").click(); |
| 512 |
await contains("[data-field_id='activity_ids/partner_ids'] .o_add_field").click(); |
| 513 |
await contains(".o_import_compat input").click(); |
| 514 |
await contains("[data-field_id='activity_ids']").click(); |
| 515 |
await contains(".o_select_button").click(); |
| 516 |
// download file has been called with the correct url |
| 517 |
expect.verifySteps(["/web/export/csv"]); |
| 518 |
}); |
| 519 |
|
| 520 |
test("Export dialog: many2many fields are extendable", async () => { |
| 521 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 522 |
onRpc("/web/export/get_fields", async (request) => { |
| 523 |
const { params } = await request.json(); |
| 524 |
if (!params.parent_field) { |
| 525 |
return fetchedFields.root; |
| 526 |
} |
| 527 |
return fetchedFields[params.prefix]; |
| 528 |
}); |
| 529 |
|
| 530 |
await mountView({ |
| 531 |
type: "list", |
| 532 |
resModel: "partner", |
| 533 |
arch: `<list><field name="foo"/></list>`, |
| 534 |
loadActionMenus: true, |
| 535 |
}); |
| 536 |
|
| 537 |
await openExportDialog(); |
| 538 |
|
| 539 |
await contains("[data-field_id='activity_ids']").click(); |
| 540 |
expect(queryFirst("[data-field_id='activity_ids/mail_template_ids'] span")).toHaveClass( |
| 541 |
"o_expand_parent", |
| 542 |
{ |
| 543 |
message: "many2many element is expandable", |
| 544 |
} |
| 545 |
); |
| 546 |
}); |
| 547 |
|
| 548 |
test("Export dialog: export list with 'exportable: false'", async () => { |
| 549 |
Partner._fields.not_exportable = fields.Char({ string: "Not exportable", exportable: false }); |
| 550 |
Partner._fields.exportable = fields.Char(); |
| 551 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 552 |
onRpc("/web/export/get_fields", async (request) => { |
| 553 |
const { params } = await request.json(); |
| 554 |
if (!params.parent_field) { |
| 555 |
return [ |
| 556 |
...fetchedFields.root, |
| 557 |
{ |
| 558 |
id: "not_exportable", |
| 559 |
string: "Not exportable", |
| 560 |
type: "char", |
| 561 |
exportable: false, |
| 562 |
}, |
| 563 |
{ |
| 564 |
id: "exportable", |
| 565 |
string: "Exportable", |
| 566 |
}, |
| 567 |
]; |
| 568 |
} |
| 569 |
return fetchedFields[params.prefix]; |
| 570 |
}); |
| 571 |
|
| 572 |
await mountView({ |
| 573 |
type: "list", |
| 574 |
resModel: "partner", |
| 575 |
arch: `<list export_xlsx="1"> |
| 576 |
<field name="foo"/> |
| 577 |
<field name="not_exportable"/> |
| 578 |
<field name="exportable"/> |
| 579 |
</list>`, |
| 580 |
loadActionMenus: true, |
| 581 |
}); |
| 582 |
|
| 583 |
await openExportDialog(); |
| 584 |
|
| 585 |
expect(".o_export_field").toHaveCount(2); |
| 586 |
expect(".o_fields_list").toHaveText("Foo\nExportable"); |
| 587 |
}); |
| 588 |
|
| 589 |
test.tags("desktop"); |
| 590 |
test("Export dialog: sortable on desktop", async () => { |
| 591 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 592 |
onRpc("/web/export/get_fields", async (request) => { |
| 593 |
const { params } = await request.json(); |
| 594 |
if (!params.parent_field) { |
| 595 |
return fetchedFields.root; |
| 596 |
} |
| 597 |
return fetchedFields[params.prefix]; |
| 598 |
}); |
| 599 |
|
| 600 |
await mountView({ |
| 601 |
type: "list", |
| 602 |
resModel: "partner", |
| 603 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 604 |
loadActionMenus: true, |
| 605 |
}); |
| 606 |
|
| 607 |
await openExportDialog(); |
| 608 |
|
| 609 |
await contains(".modal .o_export_tree_item .o_add_field").click(); |
| 610 |
expect(".o_export_field_sortable").toHaveCount(2, { |
| 611 |
message: "exported fields can be sorted by drag and drop", |
| 612 |
}); |
| 613 |
}); |
| 614 |
|
| 615 |
test.tags("mobile"); |
| 616 |
test("Export dialog: non-sortable on mobile", async () => { |
| 617 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 618 |
onRpc("/web/export/get_fields", async (request) => { |
| 619 |
const { params } = await request.json(); |
| 620 |
if (!params.parent_field) { |
| 621 |
return fetchedFields.root; |
| 622 |
} |
| 623 |
return fetchedFields[params.prefix]; |
| 624 |
}); |
| 625 |
|
| 626 |
await mountView({ |
| 627 |
type: "list", |
| 628 |
resModel: "partner", |
| 629 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 630 |
loadActionMenus: true, |
| 631 |
}); |
| 632 |
|
| 633 |
await openExportDialog(); |
| 634 |
|
| 635 |
await contains(".modal .o_export_tree_item .o_add_field").click(); |
| 636 |
expect(".o_export_field_sortable").toHaveCount(0, { |
| 637 |
message: "exported fields can't be sorted by drag and drop", |
| 638 |
}); |
| 639 |
}); |
| 640 |
|
| 641 |
test.tags("desktop"); |
| 642 |
test("ExportDialog: export all records of the domain", async () => { |
| 643 |
let isDomainSelected = false; |
| 644 |
patchWithCleanup(download, { |
| 645 |
_download: (options) => { |
| 646 |
if (isDomainSelected) { |
| 647 |
expect(JSON.parse(options.data.data).ids).toBe(false); |
| 648 |
expect.step("download called with correct params when all records are selected"); |
| 649 |
} else { |
| 650 |
expect(JSON.parse(options.data.data).ids).toEqual([1]); |
| 651 |
expect.step("download called with correct params when only one record is selected"); |
| 652 |
} |
| 653 |
}, |
| 654 |
}); |
| 655 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 656 |
onRpc("/web/export/get_fields", async (request) => { |
| 657 |
const { params } = await request.json(); |
| 658 |
if (isDomainSelected) { |
| 659 |
const expectedDomain = params.parent_field ? [] : [["bar", "!=", "glou"]]; |
| 660 |
expect(params.domain).toEqual(expectedDomain, { |
| 661 |
message: "Domain is only applied on the root model", |
| 662 |
}); |
| 663 |
expect.step("get export fields route called with correct domain"); |
| 664 |
} |
| 665 |
return fetchedFields.root; |
| 666 |
}); |
| 667 |
|
| 668 |
await mountView({ |
| 669 |
type: "list", |
| 670 |
resModel: "partner", |
| 671 |
arch: ` |
| 672 |
<list export_xlsx="1" limit="1"> |
| 673 |
<field name="foo"/> |
| 674 |
<field name="bar"/> |
| 675 |
</list>`, |
| 676 |
loadActionMenus: true, |
| 677 |
domain: [["bar", "!=", "glou"]], |
| 678 |
}); |
| 679 |
|
| 680 |
await openExportDialog(); |
| 681 |
|
| 682 |
await contains(".o_select_button").click(); |
| 683 |
await contains(".o_form_button_cancel").click(); |
| 684 |
|
| 685 |
isDomainSelected = true; |
| 686 |
await contains(".o_select_domain").click(); |
| 687 |
await contains(".o_control_panel .o_cp_action_menus .dropdown-toggle").click(); |
| 688 |
await contains(".dropdown-menu span:contains(Export)").click(); |
| 689 |
await contains(".o_select_button").click(); |
| 690 |
|
| 691 |
const firstField = ".o_left_field_panel .o_export_tree_item:first-child "; |
| 692 |
await contains(firstField).click(); |
| 693 |
|
| 694 |
expect.verifySteps([ |
| 695 |
"download called with correct params when only one record is selected", |
| 696 |
"get export fields route called with correct domain", |
| 697 |
"download called with correct params when all records are selected", |
| 698 |
"get export fields route called with correct domain", |
| 699 |
]); |
| 700 |
}); |
| 701 |
|
| 702 |
test("Direct export list", async () => { |
| 703 |
patchWithCleanup(download, { |
| 704 |
_download: (options) => { |
| 705 |
expect(options.url).toBe("/web/export/xlsx"); |
| 706 |
expect(JSON.parse(options.data.data)).toEqual({ |
| 707 |
context: { allowed_company_ids: [1], lang: "en", uid: 7, tz: "taht" }, |
| 708 |
model: "partner", |
| 709 |
domain: [["bar", "!=", "glou"]], |
| 710 |
groupby: [], |
| 711 |
ids: false, |
| 712 |
import_compat: false, |
| 713 |
fields: [ |
| 714 |
{ |
| 715 |
name: "foo", |
| 716 |
label: "Foo", |
| 717 |
store: true, |
| 718 |
type: "char", |
| 719 |
}, |
| 720 |
{ |
| 721 |
name: "bar", |
| 722 |
label: "Bar", |
| 723 |
store: true, |
| 724 |
type: "boolean", |
| 725 |
}, |
| 726 |
], |
| 727 |
}); |
| 728 |
}, |
| 729 |
}); |
| 730 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 731 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 732 |
|
| 733 |
await mountView({ |
| 734 |
type: "list", |
| 735 |
resModel: "partner", |
| 736 |
arch: ` |
| 737 |
<list export_xlsx="1"> |
| 738 |
<field name="foo"/> |
| 739 |
<field name="bar"/> |
| 740 |
</list>`, |
| 741 |
loadActionMenus: true, |
| 742 |
domain: [["bar", "!=", "glou"]], |
| 743 |
}); |
| 744 |
|
| 745 |
await exportAllAction(); |
| 746 |
}); |
| 747 |
|
| 748 |
test("Export list with modified context", async () => { |
| 749 |
patchWithCleanup(download, { |
| 750 |
_download: (options) => { |
| 751 |
expect.step("Export records"); |
| 752 |
expect(options.url).toBe("/web/export/xlsx"); |
| 753 |
expect(JSON.parse(options.data.data)).toEqual({ |
| 754 |
context: { |
| 755 |
allowed_company_ids: [1], |
| 756 |
lang: "en", |
| 757 |
uid: 7, |
| 758 |
tz: "taht", |
| 759 |
yipi: true, |
| 760 |
}, |
| 761 |
model: "partner", |
| 762 |
domain: [["bar", "!=", "glou"]], |
| 763 |
groupby: [], |
| 764 |
ids: false, |
| 765 |
import_compat: false, |
| 766 |
fields: [ |
| 767 |
{ |
| 768 |
name: "foo", |
| 769 |
label: "Foo", |
| 770 |
store: true, |
| 771 |
type: "char", |
| 772 |
}, |
| 773 |
{ |
| 774 |
name: "bar", |
| 775 |
label: "Bar", |
| 776 |
store: true, |
| 777 |
type: "boolean", |
| 778 |
}, |
| 779 |
], |
| 780 |
}); |
| 781 |
}, |
| 782 |
}); |
| 783 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 784 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 785 |
|
| 786 |
await mountView({ |
| 787 |
type: "list", |
| 788 |
resModel: "partner", |
| 789 |
arch: ` |
| 790 |
<list export_xlsx="1"> |
| 791 |
<field name="foo"/> |
| 792 |
<field name="bar"/> |
| 793 |
</list>`, |
| 794 |
loadActionMenus: true, |
| 795 |
domain: [["bar", "!=", "glou"]], |
| 796 |
searchViewArch: ` |
| 797 |
<search> |
| 798 |
<filter name="owo" string="OwO" context="{'yipi': True}"/> |
| 799 |
</search>`, |
| 800 |
}); |
| 801 |
await toggleSearchBarMenu(); |
| 802 |
await contains(".o-dropdown-item:contains(OwO)").click(); |
| 803 |
await exportAllAction(); |
| 804 |
expect.verifySteps(["Export records"]); |
| 805 |
}); |
| 806 |
|
| 807 |
test("Direct export grouped list", async () => { |
| 808 |
patchWithCleanup(download, { |
| 809 |
_download: (options) => { |
| 810 |
expect(JSON.parse(options.data.data).groupby).toEqual(["foo", "bar"]); |
| 811 |
}, |
| 812 |
}); |
| 813 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 814 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 815 |
|
| 816 |
await mountView({ |
| 817 |
type: "list", |
| 818 |
resModel: "partner", |
| 819 |
arch: ` |
| 820 |
<list export_xlsx="1"> |
| 821 |
<field name="foo"/> |
| 822 |
<field name="bar"/> |
| 823 |
</list>`, |
| 824 |
loadActionMenus: true, |
| 825 |
groupBy: ["foo", "bar"], |
| 826 |
domain: [["bar", "!=", "glou"]], |
| 827 |
}); |
| 828 |
|
| 829 |
await exportAllAction(); |
| 830 |
}); |
| 831 |
|
| 832 |
test.tags("desktop"); |
| 833 |
test("Direct export list take optional fields into account on desktop", async () => { |
| 834 |
patchWithCleanup(download, { |
| 835 |
_download: (options) => { |
| 836 |
expect(JSON.parse(options.data.data).fields).toEqual([ |
| 837 |
{ label: "Bar", name: "bar", store: true, type: "boolean" }, |
| 838 |
]); |
| 839 |
}, |
| 840 |
}); |
| 841 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 842 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 843 |
|
| 844 |
await mountView({ |
| 845 |
type: "list", |
| 846 |
resModel: "partner", |
| 847 |
arch: ` |
| 848 |
<list> |
| 849 |
<field name="foo" optional="show"/> |
| 850 |
<field name="bar" optional="show"/> |
| 851 |
</list>`, |
| 852 |
loadActionMenus: true, |
| 853 |
}); |
| 854 |
|
| 855 |
await contains("table .o_optional_columns_dropdown .dropdown-toggle").click(); |
| 856 |
await contains("span.dropdown-item:first-child").click(); |
| 857 |
expect("th").toHaveCount(3, { |
| 858 |
message: "should have 3 th, 1 for selector, 1 for columns, 1 for optional columns", |
| 859 |
}); |
| 860 |
await exportAllAction(); |
| 861 |
}); |
| 862 |
|
| 863 |
test.tags("mobile"); |
| 864 |
test("Direct export list take optional fields into account on mobile", async () => { |
| 865 |
patchWithCleanup(download, { |
| 866 |
_download: (options) => { |
| 867 |
expect(JSON.parse(options.data.data).fields).toEqual([ |
| 868 |
{ label: "Bar", name: "bar", store: true, type: "boolean" }, |
| 869 |
]); |
| 870 |
}, |
| 871 |
}); |
| 872 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 873 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 874 |
|
| 875 |
await mountView({ |
| 876 |
type: "list", |
| 877 |
resModel: "partner", |
| 878 |
arch: ` |
| 879 |
<list> |
| 880 |
<field name="foo" optional="show"/> |
| 881 |
<field name="bar" optional="show"/> |
| 882 |
</list>`, |
| 883 |
loadActionMenus: true, |
| 884 |
}); |
| 885 |
|
| 886 |
await contains("table .o_optional_columns_dropdown .dropdown-toggle").click(); |
| 887 |
await contains("span.dropdown-item:first-child").click(); |
| 888 |
expect("th").toHaveCount(2, { |
| 889 |
message: "should have 2 th, 1 for columns, 1 for optional columns", |
| 890 |
}); |
| 891 |
await exportAllAction(); |
| 892 |
}); |
| 893 |
|
| 894 |
test.tags("desktop"); |
| 895 |
test("Export dialog with duplicated fields on desktop", async () => { |
| 896 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 897 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 898 |
|
| 899 |
await mountView({ |
| 900 |
type: "list", |
| 901 |
resModel: "partner", |
| 902 |
arch: ` |
| 903 |
<list> |
| 904 |
<field name="foo" string="Foo"/> |
| 905 |
<field name="foo" string="duplicate of Foo"/> |
| 906 |
</list>`, |
| 907 |
loadActionMenus: true, |
| 908 |
}); |
| 909 |
|
| 910 |
expect(".o_list_table th:nth-child(2)").toHaveText("Foo"); |
| 911 |
expect(".o_list_table th:nth-child(3)").toHaveText("duplicate of Foo"); |
| 912 |
await openExportDialog(); |
| 913 |
expect(".modal .o_export_field").toHaveCount(1); |
| 914 |
expect(".modal .o_export_field").toHaveText("Foo", { |
| 915 |
message: "the only field to export corresponds to the field displayed in the list view", |
| 916 |
}); |
| 917 |
}); |
| 918 |
|
| 919 |
test.tags("mobile"); |
| 920 |
test("Export dialog with duplicated fields on mobile", async () => { |
| 921 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 922 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 923 |
|
| 924 |
await mountView({ |
| 925 |
type: "list", |
| 926 |
resModel: "partner", |
| 927 |
arch: ` |
| 928 |
<list> |
| 929 |
<field name="foo" string="Foo"/> |
| 930 |
<field name="foo" string="duplicate of Foo"/> |
| 931 |
</list>`, |
| 932 |
loadActionMenus: true, |
| 933 |
}); |
| 934 |
|
| 935 |
expect(".o_list_table th:nth-child(1)").toHaveText("Foo"); |
| 936 |
expect(".o_list_table th:nth-child(2)").toHaveText("duplicate of Foo"); |
| 937 |
await openExportDialog(); |
| 938 |
expect(".modal .o_export_field").toHaveCount(1); |
| 939 |
expect(".modal .o_export_field").toHaveText("Foo", { |
| 940 |
message: "the only field to export corresponds to the field displayed in the list view", |
| 941 |
}); |
| 942 |
}); |
| 943 |
|
| 944 |
test("Export dialog: export list contains field with 'default_export: true'", async () => { |
| 945 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 946 |
onRpc("/web/export/get_fields", async (request) => { |
| 947 |
const { params } = await request.json(); |
| 948 |
if (!params.parent_field) { |
| 949 |
return [ |
| 950 |
...fetchedFields.root, |
| 951 |
{ |
| 952 |
id: "default_exportable", |
| 953 |
string: "Default exportable", |
| 954 |
type: "char", |
| 955 |
default_export: true, |
| 956 |
}, |
| 957 |
]; |
| 958 |
} |
| 959 |
return fetchedFields[params.prefix]; |
| 960 |
}); |
| 961 |
|
| 962 |
await mountView({ |
| 963 |
type: "list", |
| 964 |
resModel: "partner", |
| 965 |
arch: ` |
| 966 |
<list> |
| 967 |
<field name="foo" string="Foo"/> |
| 968 |
<field name="foo" string="duplicate of Foo"/> |
| 969 |
</list>`, |
| 970 |
loadActionMenus: true, |
| 971 |
}); |
| 972 |
|
| 973 |
await openExportDialog(); |
| 974 |
expect(".modal .o_export_field").toHaveCount(2); |
| 975 |
expect(".o_fields_list").toHaveText("Foo\nDefault exportable"); |
| 976 |
}); |
| 977 |
|
| 978 |
test("Export dialog: search subfields", async () => { |
| 979 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 980 |
onRpc("/web/export/get_fields", async (request) => { |
| 981 |
const { params } = await request.json(); |
| 982 |
if (!params.parent_field) { |
| 983 |
return fetchedFields.root; |
| 984 |
} |
| 985 |
return fetchedFields[params.prefix]; |
| 986 |
}); |
| 987 |
|
| 988 |
await mountView({ |
| 989 |
type: "list", |
| 990 |
resModel: "partner", |
| 991 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 992 |
loadActionMenus: true, |
| 993 |
}); |
| 994 |
|
| 995 |
await openExportDialog(); |
| 996 |
const firstField = ".o_left_field_panel .o_export_tree_item:first-child "; |
| 997 |
await contains(firstField).click(); |
| 998 |
// show then hide content for the 'partner_ids' field. |
| 999 |
// this will load subfields and make them available to search |
| 1000 |
await contains(firstField + ".o_export_tree_item").click(); |
| 1001 |
await contains(firstField + ".o_export_tree_item").click(); |
| 1002 |
await contains(".o_export_search_input").edit("company"); |
| 1003 |
expect(".o_export_tree_item[data-field_id='activity_ids/partner_ids/company_ids']").toHaveCount( |
| 1004 |
1, |
| 1005 |
{ |
| 1006 |
message: "subfield that was known has been found and is displayed", |
| 1007 |
} |
| 1008 |
); |
| 1009 |
}); |
| 1010 |
|
| 1011 |
test("Export dialog: expand subfields after search", async () => { |
| 1012 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 1013 |
onRpc("/web/export/get_fields", async (request) => { |
| 1014 |
const { params } = await request.json(); |
| 1015 |
if (!params.parent_field) { |
| 1016 |
return fetchedFields.root; |
| 1017 |
} |
| 1018 |
return fetchedFields[params.prefix]; |
| 1019 |
}); |
| 1020 |
|
| 1021 |
await mountView({ |
| 1022 |
type: "list", |
| 1023 |
resModel: "partner", |
| 1024 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 1025 |
loadActionMenus: true, |
| 1026 |
}); |
| 1027 |
|
| 1028 |
await openExportDialog(); |
| 1029 |
const firstField = ".o_left_field_panel .o_export_tree_item:first-child "; |
| 1030 |
await contains(firstField).click(); |
| 1031 |
// show then hide content for the 'partner_ids' field. |
| 1032 |
// this will load subfields and make them available to search |
| 1033 |
await contains(firstField).click(); |
| 1034 |
await contains(firstField).click(); |
| 1035 |
await contains(".o_export_search_input").edit("Attendants"); |
| 1036 |
expect(".o_export_tree_item[data-field_id='activity_ids/partner_ids']").toHaveCount(1, { |
| 1037 |
message: "subfield that was known has been found and is displayed", |
| 1038 |
}); |
| 1039 |
await contains(".o_export_tree_item[data-field_id='activity_ids/partner_ids']").click(); |
| 1040 |
// 'Company' should be shown even if the company_ids string doesn't match the search string |
| 1041 |
// since the toggle was done by the user to show subfields |
| 1042 |
expect(".o_export_tree_item[data-field_id='activity_ids/partner_ids/company_ids']").toHaveCount( |
| 1043 |
1, |
| 1044 |
{ |
| 1045 |
message: "subfield has been loaded and is displayed", |
| 1046 |
} |
| 1047 |
); |
| 1048 |
}); |
| 1049 |
|
| 1050 |
test("Export dialog: search in debug", async () => { |
| 1051 |
serverState.debug = "1"; |
| 1052 |
|
| 1053 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 1054 |
onRpc("/web/export/get_fields", async (request) => { |
| 1055 |
const { params } = await request.json(); |
| 1056 |
if (!params.parent_field) { |
| 1057 |
return fetchedFields.root; |
| 1058 |
} |
| 1059 |
return fetchedFields[params.prefix]; |
| 1060 |
}); |
| 1061 |
|
| 1062 |
await mountView({ |
| 1063 |
type: "list", |
| 1064 |
resModel: "partner", |
| 1065 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 1066 |
loadActionMenus: true, |
| 1067 |
}); |
| 1068 |
|
| 1069 |
await openExportDialog(); |
| 1070 |
await contains(".o_left_field_panel .o_export_tree_item:first-child").click(); |
| 1071 |
await contains(".o_export_tree_item:first-child .o_export_tree_item").click(); |
| 1072 |
await contains(".o_export_search_input").edit("company_ids"); |
| 1073 |
expect(".o_export_tree_item[data-field_id='activity_ids/partner_ids/company_ids']").toHaveCount( |
| 1074 |
1, |
| 1075 |
{ |
| 1076 |
message: "subfield has been found with its technical name and is displayed", |
| 1077 |
} |
| 1078 |
); |
| 1079 |
}); |
| 1080 |
|
| 1081 |
test("Export dialog: disable button during export", async () => { |
| 1082 |
let def; |
| 1083 |
patchWithCleanup(download, { |
| 1084 |
_download: () => (def = new Deferred()), |
| 1085 |
}); |
| 1086 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 1087 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 1088 |
|
| 1089 |
await mountView({ |
| 1090 |
type: "list", |
| 1091 |
resModel: "partner", |
| 1092 |
arch: `<list export_xlsx="1"><field name="foo"/></list>`, |
| 1093 |
loadActionMenus: true, |
| 1094 |
}); |
| 1095 |
|
| 1096 |
await openExportDialog(); |
| 1097 |
expect(".o_select_button").toBeEnabled(); |
| 1098 |
await contains(".o_select_button").click(); |
| 1099 |
expect(".o_select_button").not.toBeEnabled(); |
| 1100 |
def.resolve(); |
| 1101 |
await animationFrame(); |
| 1102 |
expect(".o_select_button").toBeEnabled(); |
| 1103 |
}); |
| 1104 |
|
| 1105 |
test("Export dialog: no column_invisible fields in default export list", async () => { |
| 1106 |
onRpc("/web/export/formats", () => [{ tag: "xls", label: "Excel" }]); |
| 1107 |
onRpc("/web/export/get_fields", () => fetchedFields.root); |
| 1108 |
|
| 1109 |
await mountView({ |
| 1110 |
type: "list", |
| 1111 |
resModel: "partner", |
| 1112 |
arch: ` |
| 1113 |
<list> |
| 1114 |
<field name="foo"/> |
| 1115 |
<field name="bar" column_invisible="1"/> |
| 1116 |
</list>`, |
| 1117 |
actionMenus: {}, |
| 1118 |
}); |
| 1119 |
|
| 1120 |
await openExportDialog(); |
| 1121 |
expect(".modal .o_export_field").toHaveCount(1); |
| 1122 |
expect(".modal .o_export_field").toHaveText("Foo"); |
| 1123 |
}); |
| 1124 |
|
| 1125 |
test("Export dialog: fields displayed in same Order as list view when export", async () => { |
| 1126 |
Partner._fields.abc = fields.Char(); |
| 1127 |
Partner._fields.demo = fields.Char(); |
| 1128 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 1129 |
onRpc("/web/export/get_fields", async (request) => [ |
| 1130 |
...fetchedFields.root, |
| 1131 |
{ |
| 1132 |
id: "abc", |
| 1133 |
string: "Abc", |
| 1134 |
}, |
| 1135 |
{ |
| 1136 |
id: "demo", |
| 1137 |
string: "Demo", |
| 1138 |
}, |
| 1139 |
]); |
| 1140 |
|
| 1141 |
await mountView({ |
| 1142 |
type: "list", |
| 1143 |
resModel: "partner", |
| 1144 |
arch: ` |
| 1145 |
<list> |
| 1146 |
<field name="demo"/> |
| 1147 |
<field name="abc"/> |
| 1148 |
</list>`, |
| 1149 |
loadActionMenus: true, |
| 1150 |
}); |
| 1151 |
|
| 1152 |
await openExportDialog(); |
| 1153 |
expect(".modal .o_export_field:first-child").toHaveText("Demo", { |
| 1154 |
message: "Field demo should appear first in the export list", |
| 1155 |
}); |
| 1156 |
expect(".modal .o_export_field:nth-child(2)").toHaveText("Abc", { |
| 1157 |
message: "Field abc should appear second in the export list", |
| 1158 |
}); |
| 1159 |
}); |
| 1160 |
|
| 1161 |
test("Export dialog: no raw properties fields in default export list", async () => { |
| 1162 |
User._fields.properties_definition = fields.PropertiesDefinition(); |
| 1163 |
Partner._fields.user_id = fields.Many2one({ relation: "res.users" }); |
| 1164 |
Partner._fields.properties = fields.Properties({ |
| 1165 |
definition_record: "user_id", |
| 1166 |
definition_record_field: "properties_definition", |
| 1167 |
}); |
| 1168 |
onRpc("/web/export/formats", () => [{ tag: "csv", label: "CSV" }]); |
| 1169 |
onRpc("/web/export/get_fields", async (request) => [ |
| 1170 |
...fetchedFields.root, |
| 1171 |
{ |
| 1172 |
field_type: "properties", |
| 1173 |
string: "Properties", |
| 1174 |
required: false, |
| 1175 |
value: "properties", |
| 1176 |
id: "properties", |
| 1177 |
}, |
| 1178 |
]); |
| 1179 |
|
| 1180 |
await mountView({ |
| 1181 |
type: "list", |
| 1182 |
resModel: "partner", |
| 1183 |
arch: ` |
| 1184 |
<list> |
| 1185 |
<field name="foo"/> |
| 1186 |
<field name="properties"/> |
| 1187 |
</list>`, |
| 1188 |
loadActionMenus: true, |
| 1189 |
}); |
| 1190 |
|
| 1191 |
await openExportDialog(); |
| 1192 |
expect(".modal .o_export_field").toHaveCount(1); |
| 1193 |
expect(".modal .o_export_field").toHaveText("Foo"); |
| 1194 |
}); |