diff --git a/addons/google_drive/static/src/js/gdrive.js b/addons/google_drive/static/src/js/gdrive.js index def3e0d76a4..5855e056161 100644 --- a/addons/google_drive/static/src/js/gdrive.js +++ b/addons/google_drive/static/src/js/gdrive.js @@ -59,7 +59,7 @@ Sidebar.include({ } if (!already_there) { self._addItems('other', [{ - callback: self._onGoogleDocItemClicked.bind(self, res.id, resID), + callback: self._onGoogleDocItemClicked.bind(self, res.id), classname: 'oe_share_gdoc', config_id: res.id, label: res.name, @@ -81,8 +81,9 @@ Sidebar.include({ * @param {integer} configID * @param {integer} resID */ - _onGoogleDocItemClicked: function (configID, resID) { + _onGoogleDocItemClicked: function (configID) { var self = this; + var resID = this.env.activeIds[0]; var domain = [['id', '=', configID]]; var fields = ['google_drive_resource_id', 'google_drive_client_id']; this._rpc({ diff --git a/addons/google_drive/static/tests/gdrive_test.js b/addons/google_drive/static/tests/gdrive_test.js index edf6a0c4ca2..62c997d2d93 100644 --- a/addons/google_drive/static/tests/gdrive_test.js +++ b/addons/google_drive/static/tests/gdrive_test.js @@ -33,6 +33,9 @@ QUnit.module('gdrive_integration', { records: [{ id: 1, display_name: "Locomotive Breath", + }, { + id: 2, + display_name: "Hey Macarena", }], }, 'google.drive.config': { @@ -104,7 +107,57 @@ QUnit.module('gdrive_integration', { // Trigger opening of the dynamic link google_action.find('a:first').click(); + form.destroy(); + }); + QUnit.test('click on the google drive attachments after switching records', function (assert) { + assert.expect(3); + var self = this; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '', + res_id: 1, + viewOptions: { + hasSidebar: true, + ids: [1, 2], + index: 0, + }, + mockRPC: function (route, args) { + if (route === '/web/dataset/call_kw/google.drive.config/get_google_drive_config') { + assert.deepEqual(args.args, ['partner', 1], + 'The route to get google drive config should have been called'); + return $.when([{id: 27, name: 'Cyberdyne Systems'}]); + } + if (route === '/web/dataset/call_kw/google.drive.config/search_read'){ + return $.when([{google_drive_resource_id: "T1000", + google_drive_client_id: "cyberdyne.org", + id: 1}]); + } + if (route === '/web/dataset/call_kw/google.drive.config/get_google_drive_url') { + assert.deepEqual(args.args, [27, self.activeId, 'T1000'], + 'The route to get the Google url should have been called'); + // We don't return anything useful, otherwise it will open a new tab + return $.when(); + } + return this._super.apply(this, arguments); + }, + }); + + var nameToId = { + 'Locomotive Breath': 1, + 'Hey Macarena': 2, + } + // Trigger opening of the dynamic link + self.activeId = nameToId[$("[name='display_name']").text()]; + form.sidebar.$('.oe_share_gdoc').find('a:first').click(); + form.pager.$('.o_pager_next').click(); + self.activeId = nameToId[$("[name='display_name']").text()]; + form.sidebar.$('.oe_share_gdoc').find('a:first').click(); form.destroy(); }); });