[IMP] web: Close window when printing a report
Up until now, the execution of a report action could not be followed by
any action which prevented, for example, to automaticcaly close a modal
after printing a report from it. This has become an issue when working
on customer's invoices using the new modal introduced in 4cb9194275
This commit allows to close a modal after the download of a report.
This commit is contained in:
@@ -80,8 +80,16 @@ ActionManager.include({
|
||||
* @returns {Deferred} resolved when the action has been executed
|
||||
*/
|
||||
_triggerDownload: function (action, options, type){
|
||||
var self = this;
|
||||
var reportUrls = this._makeReportUrls(action);
|
||||
return this._downloadReport(reportUrls[type]).then(options.on_close);
|
||||
return this._downloadReport(reportUrls[type]).then(function () {
|
||||
if (action.close_on_report_download) {
|
||||
var closeAction = { type: 'ir.actions.act_window_close' };
|
||||
return self.doAction(closeAction, _.pick(options, 'on_close'));
|
||||
} else {
|
||||
return options.on_close();
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Executes actions of type 'ir.actions.report'.
|
||||
|
||||
@@ -101,6 +101,13 @@ QUnit.module('ActionManager', {
|
||||
}, {
|
||||
id: 10,
|
||||
type: 'ir.actions.act_window_close',
|
||||
}, {
|
||||
id: 11,
|
||||
name: "Another Report",
|
||||
report_name: 'another_report',
|
||||
report_type: 'qweb-pdf',
|
||||
type: 'ir.actions.report',
|
||||
close_on_report_download: true,
|
||||
}];
|
||||
|
||||
this.archs = {
|
||||
@@ -1858,6 +1865,66 @@ QUnit.module('ActionManager', {
|
||||
actionManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('report actions can close modals and reload views', function (assert) {
|
||||
assert.expect(8);
|
||||
|
||||
var actionManager = createActionManager({
|
||||
actions: this.actions,
|
||||
archs: this.archs,
|
||||
data: this.data,
|
||||
services: {
|
||||
report: ReportService,
|
||||
},
|
||||
mockRPC: function (route, args) {
|
||||
if (route === '/report/check_wkhtmltopdf') {
|
||||
return $.when('ok');
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
session: {
|
||||
get_file: function (params) {
|
||||
assert.step(params.url);
|
||||
params.success();
|
||||
params.complete();
|
||||
return true;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// load modal
|
||||
actionManager.doAction(5, {
|
||||
on_close: function () {
|
||||
assert.step('on_close');
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual($('.o_technical_modal .o_form_view').length, 1,
|
||||
"should have rendered a form view in a modal");
|
||||
|
||||
actionManager.doAction(7, {
|
||||
on_close: function () {
|
||||
assert.step('on_printed');
|
||||
},
|
||||
});
|
||||
|
||||
assert.strictEqual($('.o_technical_modal .o_form_view').length, 1,
|
||||
"The modal should still exist");
|
||||
|
||||
actionManager.doAction(11);
|
||||
|
||||
assert.strictEqual($('.o_technical_modal .o_form_view').length, 0,
|
||||
"the modal should have been closed after the action report");
|
||||
|
||||
assert.verifySteps([
|
||||
'/report/download',
|
||||
'on_printed',
|
||||
'/report/download',
|
||||
'on_close',
|
||||
]);
|
||||
|
||||
actionManager.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('should trigger a notification if wkhtmltopdf is to upgrade', function (assert) {
|
||||
assert.expect(6);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user