From dd239a604aa03ef44a9759e50b6c0dee7d4e2ece Mon Sep 17 00:00:00 2001 From: Yolann Sabaux Date: Mon, 31 Jan 2022 10:51:46 +0000 Subject: [PATCH] [FIX] web: display_name in analytical tag not displayed Steps to reproduce: - Install accounting - Create more than 6 analytical tags - Create an invoice - Create a payment - Go in Accounting>Actions>Reconciliation, tab Manal Operations - In the field Analytical Tag, click on 'Search More' and selected 1 or multiple tags Issue: Void tags are displayed Solution: Fetch the field `display_name` ref commit: 84f0644802865c6454014059842eb6a9d4fd40e4 opw-2734029 closes odoo/odoo#87311 X-original-commit: 936bad32cf1024570da4880ccc5375b02b30c1c2 Related: odoo/enterprise#25631 Signed-off-by: Aaron Bohy (aab) --- .../legacy/js/views/list/list_controller.js | 36 ++++++++++++++++ .../src/legacy/js/views/view_dialogs.js | 3 +- .../tests/legacy/views/view_dialogs_tests.js | 42 ++++++++++++++++++- 3 files changed, 77 insertions(+), 4 deletions(-) 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);