[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
This commit is contained in:
Nicolas Martinelli
2018-09-21 08:45:17 +02:00
committed by Nicolas Martinelli
parent 60e9e1f738
commit 84aea12bac
2 changed files with 56 additions and 2 deletions
+3 -2
View File
@@ -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({
@@ -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();
});
});