[IMP] kpi_dashboard: Compute on fly, allow to refresh data on fly

This commit is contained in:
Enric Tobella
2020-07-16 11:04:25 +02:00
parent 44565edb49
commit aa4c93b0eb
4 changed files with 53 additions and 1 deletions

View File

@@ -10,7 +10,29 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
var DashboardController = BasicController.extend({
custom_events: _.extend({}, BasicController.prototype.custom_events, {
addDashboard: '_addDashboard',
refresh_on_fly: '_refreshOnFly',
}),
_refreshOnFly: function (event) {
var self = this;
this._rpc({
model: this.modelName,
method: 'read_dashboard_on_fly',
args: [[this.renderer.state.res_id]],
context: _.extend(
{},
this.model.get(this.handle, {raw: true}).getContext(),
{bin_size: true}
),
}).then(function (data) {
_.each(data, function (item) {
// We will follow the same logic used on Bus Notifications
self.renderer._onNotification([[
"kpi_dashboard_" + self.renderer.state.res_id,
item
]])
});
});
},
renderPager: function ($node, options) {
options = _.extend({}, options, {
validate: this.canBeDiscarded.bind(this),

View File

@@ -53,8 +53,21 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
'bus_service', 'onNotification',
this, this._onNotification
);
if (this.state.specialData.compute_on_fly_refresh > 0) {
// Setting the refresh interval
this.on_fly_interval = setInterval(function () {
self.trigger_up('refresh_on_fly');
}, this.state.specialData.compute_on_fly_refresh *1000);
};
return $.when();
},
on_detach_callback: function () {
// We want to clear the refresh interval once we exit the view
if (this.on_fly_interval) {
clearInterval(this.on_fly_interval)
}
this._super.apply(this, arguments);
},
_onNotification: function (notifications) {
var self = this;
_.each(notifications, function (notification) {