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.

109 lines
3.6 KiB

  1. odoo.define('account_financial_report.account_financial_report_backend', function (require) {
  2. 'use strict';
  3. var core = require('web.core');
  4. var Widget = require('web.Widget');
  5. var ControlPanelMixin = require('web.ControlPanelMixin');
  6. var session = require('web.session');
  7. var ReportWidget = require('account_financial_report.account_financial_report_widget');
  8. var framework = require('web.framework');
  9. var crash_manager = require('web.crash_manager');
  10. var QWeb = core.qweb;
  11. var report_backend = Widget.extend(ControlPanelMixin, {
  12. // Stores all the parameters of the action.
  13. events: {
  14. 'click .o_account_financial_reports_print': 'print',
  15. 'click .o_account_financial_reports_export': 'export',
  16. },
  17. init: function(parent, action) {
  18. this.actionManager = parent;
  19. this.given_context = {};
  20. this.odoo_context = action.context;
  21. this.controller_url = action.context.url;
  22. if (action.context.context) {
  23. this.given_context = action.context.context;
  24. }
  25. this.given_context.active_id = action.context.active_id || action.params.active_id;
  26. this.given_context.model = action.context.active_model || false;
  27. this.given_context.ttype = action.context.ttype || false;
  28. return this._super.apply(this, arguments);
  29. },
  30. willStart: function() {
  31. return $.when(this.get_html());
  32. },
  33. set_html: function() {
  34. var self = this;
  35. var def = $.when();
  36. if (!this.report_widget) {
  37. this.report_widget = new ReportWidget(this, this.given_context);
  38. def = this.report_widget.appendTo(this.$el);
  39. }
  40. def.then(function () {
  41. self.report_widget.$el.html(self.html);
  42. });
  43. },
  44. start: function() {
  45. this.set_html();
  46. return this._super();
  47. },
  48. // Fetches the html and is previous report.context if any, else create it
  49. get_html: function() {
  50. var self = this;
  51. var defs = [];
  52. return this._rpc({
  53. model: this.given_context.model,
  54. method: 'get_html',
  55. args: [self.given_context],
  56. context: self.odoo_context,
  57. })
  58. .then(function (result) {
  59. self.html = result.html;
  60. defs.push(self.update_cp());
  61. return $.when.apply($, defs);
  62. });
  63. },
  64. // Updates the control panel and render the elements that have yet to be rendered
  65. update_cp: function() {
  66. if (!this.$buttons) {
  67. }
  68. var status = {
  69. breadcrumbs: this.actionManager.get_breadcrumbs(),
  70. cp_content: {$buttons: this.$buttons},
  71. };
  72. return this.update_control_panel(status);
  73. },
  74. do_show: function() {
  75. this._super();
  76. this.update_cp();
  77. },
  78. print: function(e) {
  79. var self = this;
  80. this._rpc({
  81. model: this.given_context.model,
  82. method: 'print_report',
  83. args: [this.given_context.active_id, 'qweb-pdf'],
  84. context: self.odoo_context,
  85. }).then(function(result){
  86. self.do_action(result);
  87. });
  88. },
  89. export: function(e) {
  90. var self = this;
  91. this._rpc({
  92. model: this.given_context.model,
  93. method: 'print_report',
  94. args: [this.given_context.active_id, 'xlsx'],
  95. context: self.odoo_context,
  96. })
  97. .then(function(result){
  98. self.do_action(result);
  99. });
  100. },
  101. });
  102. core.action_registry.add("account_financial_report_backend", report_backend);
  103. return report_backend;
  104. });