OCA reporting engine fork for dev and update.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.1 KiB

  1. /* Copyright 2017 ACSONE SA/NV
  2. * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
  3. odoo.define('report_py3o.report', function (require) {
  4. var ActionManager = require('web.ActionManager');
  5. var core = require('web.core');
  6. var crash_manager = require('web.crash_manager');
  7. var framework = require('web.framework');
  8. var session = require('web.session');
  9. var _t = core._t;
  10. var trigger_download = function(session, response, c, action, options) {
  11. session.get_file({
  12. url: '/report/download',
  13. data: {data: JSON.stringify(response)},
  14. complete: framework.unblockUI,
  15. error: c.rpc_error.bind(c),
  16. success: function(){
  17. if (action && options && !action.dialog) {
  18. options.on_close();
  19. }
  20. },
  21. });
  22. };
  23. ActionManager.include({
  24. _executeReportAction: function (action, options) {
  25. // Py3o reports
  26. if ('report_type' in action && action.report_type === 'py3o' ) {
  27. return this._triggerDownload(action, options, 'py3o');
  28. } else {
  29. return this._super.apply(this, arguments);
  30. }
  31. },
  32. _makeReportUrls: function(action) {
  33. var reportUrls = this._super.apply(this, arguments);
  34. reportUrls.py3o = '/report/py3o/' + action.report_name;
  35. // We may have to build a query string with `action.data`. It's the place
  36. // were report's using a wizard to customize the output traditionally put
  37. // their options.
  38. if (_.isUndefined(action.data) || _.isNull(action.data) ||
  39. (_.isObject(action.data) && _.isEmpty(action.data))) {
  40. if (action.context.active_ids) {
  41. var activeIDsPath = '/' + action.context.active_ids.join(',');
  42. reportUrls.py3o += activeIDsPath;;
  43. }
  44. } else {
  45. var serializedOptionsPath = '?options=' + encodeURIComponent(JSON.stringify(action.data));
  46. serializedOptionsPath += '&context=' + encodeURIComponent(JSON.stringify(action.context));
  47. reportUrls.py3o += serializedOptionsPath;
  48. }
  49. return reportUrls;
  50. }
  51. });
  52. });