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.9 KiB

  1. odoo.define("account_financial_report.account_financial_report_backend", function(
  2. require
  3. ) {
  4. "use strict";
  5. var core = require("web.core");
  6. var Widget = require("web.Widget");
  7. var ControlPanelMixin = require("web.ControlPanelMixin");
  8. var ReportWidget = require("account_financial_report.account_financial_report_widget");
  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 =
  24. action.context.active_id || 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. return this._rpc({
  53. model: this.given_context.model,
  54. method: "get_html",
  55. args: [self.given_context],
  56. context: self.odoo_context,
  57. }).then(function(result) {
  58. self.html = result.html;
  59. defs.push(self.update_cp());
  60. return $.when.apply($, defs);
  61. });
  62. },
  63. // Updates the control panel and render the elements that have yet
  64. // to be rendered
  65. update_cp: function() {
  66. if (this.$buttons) {
  67. var status = {
  68. breadcrumbs: this.actionManager.get_breadcrumbs(),
  69. cp_content: {$buttons: this.$buttons},
  70. };
  71. return this.update_control_panel(status);
  72. }
  73. },
  74. do_show: function() {
  75. this._super();
  76. this.update_cp();
  77. },
  78. print: function() {
  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() {
  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. }).then(function(result) {
  97. self.do_action(result);
  98. });
  99. },
  100. canBeRemoved: function() {
  101. return $.when();
  102. },
  103. });
  104. core.action_registry.add("account_financial_report_backend", report_backend);
  105. return report_backend;
  106. });