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.

111 lines
3.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  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 ReportWidget = require(
  7. 'account_financial_report.account_financial_report_widget'
  8. );
  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, else create it
  48. get_html: function() {
  49. var self = this;
  50. var defs = [];
  51. return this._rpc({
  52. model: this.given_context.model,
  53. method: 'get_html',
  54. args: [self.given_context],
  55. context: self.odoo_context,
  56. })
  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. })
  97. .then(function(result){
  98. self.do_action(result);
  99. });
  100. },
  101. });
  102. core.action_registry.add(
  103. "account_financial_report_backend",
  104. report_backend
  105. );
  106. return report_backend;
  107. });