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.

99 lines
3.7 KiB

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