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.

120 lines
4.1 KiB

[FIX] account_financial_report: get module compatible with HomeMenu widget added by web_enterprise module Steps to reproduce: * install account_financial_report module alongside Odoo Enterpise * open General Ledger report * click on View button * click on Home button or by using the shortcut (Shift +h) Current behaviour: Uncaught TypeError: currentController.widget.on_detach_callback is not a function http://localhost:8069/web/static/src/js/chrome/action_manager.js:94 Traceback: TypeError: currentController.widget.on_detach_callback is not a function at Class.on_detach_callback (http://localhost:8069/web/static/src/js/chrome/action_manager.js:94:38) at http://localhost:8069/web/static/src/js/core/dom.js:175:26 at Function._.each._.forEach (http://localhost:8069/web/static/lib/underscore/underscore.js:145:9) at Object.detach (http://localhost:8069/web/static/src/js/core/dom.js:173:11) at http://localhost:8069/web_enterprise/static/src/js/web_client.js:289:21 at http://localhost:8069/web/static/lib/jquery/jquery.js:3276:89 at fire (http://localhost:8069/web/static/lib/jquery/jquery.js:3119:58) at Object.add [as done] (http://localhost:8069/web/static/lib/jquery/jquery.js:3165:49) at Array.<anonymous> (http://localhost:8069/web/static/lib/jquery/jquery.js:3275:77) at Function.each (http://localhost:8069/web/static/lib/jquery/jquery.js:383:58) In addition, after having implemented on_detach_callback, if I click on the icon chevron left or by using the shortcut, I get the following error: Uncaught TypeError: currentController.widget.on_attach_callback is not a function http://localhost:8069/web/static/src/js/chrome/action_manager.js:84 Traceback: TypeError: currentController.widget.on_attach_callback is not a function at Class.on_attach_callback (http://localhost:8069/web/static/src/js/chrome/action_manager.js:84:38) at http://localhost:8069/web/static/src/js/core/dom.js:38:22 at Function._.each._.forEach (http://localhost:8069/web/static/lib/underscore/underscore.js:145:9) at _notify (http://localhost:8069/web/static/src/js/core/dom.js:36:7) at Object.append (http://localhost:8069/web/static/src/js/core/dom.js:60:13) at Class.toggle_home_menu (http://localhost:8069/web_enterprise/static/src/js/web_client.js:305:17) at Class.self.toggle_home_menu (http://localhost:8069/web_enterprise/static/src/js/widgets/debug_manager.js:21:38) at Class._onHideHomeMenu (http://localhost:8069/web_enterprise/static/src/js/web_client.js:329:18) at Class.<anonymous> (http://localhost:8069/web/static/src/js/core/mixins.js:278:23) at Class.trigger (http://localhost:8069/web/static/src/js/core/mixins.js:225:31)
4 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,
  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. })
  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
  65. // to be rendered
  66. update_cp: function () {
  67. if (this.$buttons) {
  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. },
  75. do_show: function () {
  76. this._super();
  77. this.update_cp();
  78. },
  79. print: function () {
  80. var self = this;
  81. this._rpc({
  82. model: this.given_context.model,
  83. method: 'print_report',
  84. args: [this.given_context.active_id, 'qweb-pdf'],
  85. context: self.odoo_context,
  86. }).then(function (result) {
  87. self.do_action(result);
  88. });
  89. },
  90. export: function () {
  91. var self = this;
  92. this._rpc({
  93. model: this.given_context.model,
  94. method: 'print_report',
  95. args: [this.given_context.active_id, 'xlsx'],
  96. context: self.odoo_context,
  97. }).then(function (result) {
  98. self.do_action(result);
  99. });
  100. },
  101. canBeRemoved: function () {
  102. return $.when();
  103. },
  104. on_attach_callback: function () {
  105. this.isInDOM = true;
  106. },
  107. on_detach_callback: function () {
  108. this.isInDOM = false;
  109. },
  110. });
  111. core.action_registry.add(
  112. "account_financial_report_backend",
  113. report_backend
  114. );
  115. return report_backend;
  116. });