|
@ -1,20 +1,21 @@ |
|
|
odoo.define('account_financial_report_qweb.account_financial_report_backend', function (require) { |
|
|
odoo.define('account_financial_report_qweb.account_financial_report_backend', function (require) { |
|
|
'use strict'; |
|
|
|
|
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
|
|
|
var Widget = require('web.Widget'); |
|
|
|
|
|
var ControlPanelMixin = require('web.ControlPanelMixin'); |
|
|
|
|
|
var ReportWidget = require('account_financial_report_qweb.account_financial_report_widget'); |
|
|
|
|
|
var Model = require('web.Model'); |
|
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
|
|
|
var Widget = require('web.Widget'); |
|
|
|
|
|
var ControlPanelMixin = require('web.ControlPanelMixin'); |
|
|
|
|
|
var ReportWidget = require( |
|
|
|
|
|
'account_financial_report_qweb.account_financial_report_widget'); |
|
|
|
|
|
var Model = require('web.Model'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var report_backend = Widget.extend(ControlPanelMixin, { |
|
|
|
|
|
|
|
|
var report_backend = Widget.extend(ControlPanelMixin, { |
|
|
// Stores all the parameters of the action.
|
|
|
// Stores all the parameters of the action.
|
|
|
events: { |
|
|
events: { |
|
|
'click .o_account_financial_reports_print': 'print', |
|
|
'click .o_account_financial_reports_print': 'print', |
|
|
'click .o_account_financial_reports_export': 'export', |
|
|
'click .o_account_financial_reports_export': 'export', |
|
|
}, |
|
|
}, |
|
|
init: function(parent, action) { |
|
|
|
|
|
|
|
|
init: function (parent, action) { |
|
|
this.actionManager = parent; |
|
|
this.actionManager = parent; |
|
|
this.given_context = {}; |
|
|
this.given_context = {}; |
|
|
this.odoo_context = action.context; |
|
|
this.odoo_context = action.context; |
|
@ -22,15 +23,16 @@ var report_backend = Widget.extend(ControlPanelMixin, { |
|
|
if (action.context.context) { |
|
|
if (action.context.context) { |
|
|
this.given_context = action.context.context; |
|
|
this.given_context = action.context.context; |
|
|
} |
|
|
} |
|
|
this.given_context.active_id = action.context.active_id || action.params.active_id; |
|
|
|
|
|
|
|
|
this.given_context.active_id = action.context.active_id || |
|
|
|
|
|
action.params.active_id; |
|
|
this.given_context.model = action.context.active_model || false; |
|
|
this.given_context.model = action.context.active_model || false; |
|
|
this.given_context.ttype = action.context.ttype || false; |
|
|
this.given_context.ttype = action.context.ttype || false; |
|
|
return this._super.apply(this, arguments); |
|
|
return this._super.apply(this, arguments); |
|
|
}, |
|
|
}, |
|
|
willStart: function() { |
|
|
|
|
|
|
|
|
willStart: function () { |
|
|
return $.when(this.get_html()); |
|
|
return $.when(this.get_html()); |
|
|
}, |
|
|
}, |
|
|
set_html: function() { |
|
|
|
|
|
|
|
|
set_html: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var def = $.when(); |
|
|
var def = $.when(); |
|
|
if (!this.report_widget) { |
|
|
if (!this.report_widget) { |
|
@ -41,55 +43,57 @@ var report_backend = Widget.extend(ControlPanelMixin, { |
|
|
self.report_widget.$el.html(self.html); |
|
|
self.report_widget.$el.html(self.html); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
start: function() { |
|
|
|
|
|
|
|
|
start: function () { |
|
|
this.set_html(); |
|
|
this.set_html(); |
|
|
return this._super(); |
|
|
return this._super(); |
|
|
}, |
|
|
}, |
|
|
// Fetches the html and is previous report.context if any, else create it
|
|
|
|
|
|
get_html: function() { |
|
|
|
|
|
|
|
|
// Fetches the html and is previous report.context if any,
|
|
|
|
|
|
// else create it
|
|
|
|
|
|
get_html: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
var defs = []; |
|
|
var defs = []; |
|
|
self.model = new Model(this.given_context.model); |
|
|
self.model = new Model(this.given_context.model); |
|
|
return self.model.call('get_html', [this.given_context], {context: self.odoo_context}).then(function |
|
|
|
|
|
(result) { |
|
|
|
|
|
|
|
|
return self.model.call('get_html', [this.given_context], |
|
|
|
|
|
{context: self.odoo_context}).then(function (result) { |
|
|
self.html = result.html; |
|
|
self.html = result.html; |
|
|
defs.push(self.update_cp()); |
|
|
defs.push(self.update_cp()); |
|
|
return $.when.apply($, defs); |
|
|
return $.when.apply($, defs); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
// Updates the control panel and render the elements that have yet to be rendered
|
|
|
|
|
|
update_cp: function() { |
|
|
|
|
|
if (!this.$buttons) { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Updates the control panel and render the elements that have yet to
|
|
|
|
|
|
// be rendered
|
|
|
|
|
|
update_cp: function () { |
|
|
var status = { |
|
|
var status = { |
|
|
breadcrumbs: this.actionManager.get_breadcrumbs(), |
|
|
breadcrumbs: this.actionManager.get_breadcrumbs(), |
|
|
cp_content: {$buttons: this.$buttons}, |
|
|
cp_content: {$buttons: this.$buttons}, |
|
|
}; |
|
|
}; |
|
|
return this.update_control_panel(status); |
|
|
return this.update_control_panel(status); |
|
|
}, |
|
|
}, |
|
|
do_show: function() { |
|
|
|
|
|
|
|
|
do_show: function () { |
|
|
this._super(); |
|
|
this._super(); |
|
|
this.update_cp(); |
|
|
this.update_cp(); |
|
|
}, |
|
|
}, |
|
|
print: function() { |
|
|
|
|
|
|
|
|
print: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
self.model = new Model(this.given_context.model); |
|
|
self.model = new Model(this.given_context.model); |
|
|
self.model.call('print_report', [this.given_context.active_id, 'qweb-pdf'], {context: self.odoo_context}) |
|
|
|
|
|
.then(function(result){ |
|
|
|
|
|
|
|
|
self.model.call('print_report', [this.given_context.active_id, |
|
|
|
|
|
'qweb-pdf'], {context: self.odoo_context}) |
|
|
|
|
|
.then(function (result) { |
|
|
self.do_action(result); |
|
|
self.do_action(result); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
export: function() { |
|
|
|
|
|
|
|
|
export: function () { |
|
|
var self = this; |
|
|
var self = this; |
|
|
self.model = new Model(this.given_context.model); |
|
|
self.model = new Model(this.given_context.model); |
|
|
self.model.call('print_report', [this.given_context.active_id, 'xlsx'], {context: self.odoo_context}) |
|
|
|
|
|
.then(function(result){ |
|
|
|
|
|
|
|
|
self.model.call('print_report', [this.given_context.active_id, |
|
|
|
|
|
'xlsx'], {context: self.odoo_context}) |
|
|
|
|
|
.then(function (result) { |
|
|
self.do_action(result); |
|
|
self.do_action(result); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
core.action_registry.add("account_financial_report_backend", report_backend); |
|
|
|
|
|
return report_backend; |
|
|
|
|
|
|
|
|
core.action_registry.add("account_financial_report_backend", |
|
|
|
|
|
report_backend); |
|
|
|
|
|
return report_backend; |
|
|
}); |
|
|
}); |