summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2018-09-20 08:12:12 +0200
committerNicolas Martinelli <nim-odoo@users.noreply.github.com>2018-09-21 08:45:17 +0200
commit84aea12bac90e1ba8ea0a41fcbcff53cec69d229 (patch)
tree06f734bf0c02d69722f5715e4f456f2ed3e44519
parent60e9e1f738cb04e9d76fed05dda4caa1293963c4 (diff)
[FIX] google_drive: current record
- Open a partner view, click on Action > Partner Review - Switch to another partner - Click again on Action > Partner Review The Google Doc file of the second partner is the same than the first partner. This is due to `_onGoogleDocItemClicked` which is always called with the same `resID`, i.e. the `resID` used at `start`. We retrieve the active ID at each click instead. opw-1882068
-rw-r--r--addons/google_drive/static/src/js/gdrive.js5
-rw-r--r--addons/google_drive/static/tests/gdrive_test.js53
2 files changed, 56 insertions, 2 deletions
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: '<form string="Partners">' +
+ '<field name="display_name"/>' +
+ '</form>',
+ 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();
});
});