diff --git a/addons/web/static/src/legacy/js/views/list/list_controller.js b/addons/web/static/src/legacy/js/views/list/list_controller.js
index 703c6c121ca..a9dddc0a7bc 100644
--- a/addons/web/static/src/legacy/js/views/list/list_controller.js
+++ b/addons/web/static/src/legacy/js/views/list/list_controller.js
@@ -137,6 +137,23 @@ var ListController = BasicController.extend({
return self.model.get(db_id, {raw: true});
});
},
+ /**
+ * Returns the list of currently selected records (with the check boxes on
+ * the left) or the whole domain records if it is selected
+ *
+ * @returns {Promise<{id, display_name}[]>}
+ */
+ getSelectedRecordsWithDomain: async function () {
+ if (this.isDomainSelected) {
+ const state = this.model.get(this.handle, {raw: true});
+ return await this._domainToRecords(state.getDomain(), session.active_ids_limit);
+ } else {
+ return Promise.resolve(this.selectedRecords.map(localId => {
+ const data = this.model.localData[localId].data;
+ return { id: data.id, display_name: data.display_name };
+ }));
+ }
+ },
/**
* Display and bind all buttons in the control panel
*
@@ -394,6 +411,25 @@ var ListController = BasicController.extend({
self.updateButtons('readonly');
});
},
+ /**
+ * Returns the records matching the given domain.
+ *
+ * @private
+ * @param {Array[]} domain
+ * @param {integer} [limit]
+ * @returns {Promise<{id, display_name}[]>}
+ */
+ _domainToRecords: function (domain, limit) {
+ return this._rpc({
+ model: this.modelName,
+ method: 'search_read',
+ args: [domain],
+ kwargs: {
+ fields: ['display_name'],
+ limit: limit,
+ },
+ });
+ },
/**
* Returns the ids of records matching the given domain.
*
diff --git a/addons/web/static/src/legacy/js/views/view_dialogs.js b/addons/web/static/src/legacy/js/views/view_dialogs.js
index 7cff8201ced..f3ffe39e7b0 100644
--- a/addons/web/static/src/legacy/js/views/view_dialogs.js
+++ b/addons/web/static/src/legacy/js/views/view_dialogs.js
@@ -476,8 +476,7 @@ var SelectCreateDialog = ViewDialog.extend({
close: true,
hotkey: 'v',
click: async () => {
- const resIds = await this.viewController.getSelectedIdsWithDomain();
- const values = resIds.map(e => ({id: e}));
+ const values = await this.viewController.getSelectedRecordsWithDomain();
this.on_selected(values);
},
});
diff --git a/addons/web/static/tests/legacy/views/view_dialogs_tests.js b/addons/web/static/tests/legacy/views/view_dialogs_tests.js
index 3f28c5b1bd7..e46f9785b1d 100644
--- a/addons/web/static/tests/legacy/views/view_dialogs_tests.js
+++ b/addons/web/static/tests/legacy/views/view_dialogs_tests.js
@@ -589,7 +589,7 @@ QUnit.module('Views', {
});
QUnit.test('SelectCreateDialog calls on_selected with every record matching the domain', async function (assert) {
- assert.expect(1);
+ assert.expect(3);
const parent = await createParent({
data: this.data,
@@ -610,7 +610,9 @@ QUnit.module('Views', {
new dialogs.SelectCreateDialog(parent, {
res_model: 'partner',
on_selected: function(records) {
- assert.equal(records.length, 3)
+ assert.equal(records.length, 3);
+ assert.strictEqual(records.map((r) => r.display_name).toString(), "blipblip,macgyver,Jack O'Neill");
+ assert.strictEqual(records.map((r) => r.id).toString(), "1,2,3");
}
}).open();
await testUtils.nextTick();
@@ -622,6 +624,42 @@ QUnit.module('Views', {
parent.destroy();
});
+ QUnit.test('SelectCreateDialog calls on_selected with every record matching without selecting a domain', async function (assert) {
+ assert.expect(3);
+
+ const parent = await createParent({
+ data: this.data,
+ archs: {
+ 'partner,false,list':
+ '' +
+ '' +
+ '' +
+ '',
+ 'partner,false,search':
+ '' +
+ '' +
+ '',
+ },
+ session: {},
+ });
+
+ new dialogs.SelectCreateDialog(parent, {
+ res_model: 'partner',
+ on_selected: function(records) {
+ assert.equal(records.length, 2);
+ assert.strictEqual(records.map((r) => r.display_name).toString(), "blipblip,macgyver");
+ assert.strictEqual(records.map((r) => r.id).toString(), "1,2");
+ }
+ }).open();
+ await testUtils.nextTick();
+
+ await testUtils.dom.click($('thead .o_list_record_selector input'));
+ await testUtils.dom.click($('.o_list_selection_box '));
+ await testUtils.dom.click($('.modal .o_select_button'));
+
+ parent.destroy();
+ });
+
QUnit.test('propagate can_create onto the search popup o2m', async function (assert) {
assert.expect(4);