[IMP] kpi_dashboard: Compute on fly, allow to refresh data on fly
parent
507f6221b3
commit
3fb5878791
|
@ -16,6 +16,10 @@ class KpiDashboard(models.Model):
|
||||||
"kpi.dashboard.item", inverse_name="dashboard_id", copy=True,
|
"kpi.dashboard.item", inverse_name="dashboard_id", copy=True,
|
||||||
)
|
)
|
||||||
number_of_columns = fields.Integer(default=5, required=True)
|
number_of_columns = fields.Integer(default=5, required=True)
|
||||||
|
compute_on_fly_refresh = fields.Integer(
|
||||||
|
default=0,
|
||||||
|
help="Seconds to refresh on fly elements"
|
||||||
|
)
|
||||||
width = fields.Integer(compute="_compute_width")
|
width = fields.Integer(compute="_compute_width")
|
||||||
margin_y = fields.Integer(default=10, required=True)
|
margin_y = fields.Integer(default=10, required=True)
|
||||||
margin_x = fields.Integer(default=10, required=True)
|
margin_x = fields.Integer(default=10, required=True)
|
||||||
|
@ -43,6 +47,15 @@ class KpiDashboard(models.Model):
|
||||||
+ rec.widget_dimension_x * rec.number_of_columns
|
+ rec.widget_dimension_x * rec.number_of_columns
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def read_dashboard_on_fly(self):
|
||||||
|
self.ensure_one()
|
||||||
|
result = []
|
||||||
|
for item in self.item_ids:
|
||||||
|
if not item.kpi_id.compute_on_fly:
|
||||||
|
continue
|
||||||
|
result.append(item._read_dashboard())
|
||||||
|
return result
|
||||||
|
|
||||||
def read_dashboard(self):
|
def read_dashboard(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
result = {
|
result = {
|
||||||
|
@ -52,6 +65,7 @@ class KpiDashboard(models.Model):
|
||||||
"max_cols": self.number_of_columns,
|
"max_cols": self.number_of_columns,
|
||||||
"margin_x": self.margin_x,
|
"margin_x": self.margin_x,
|
||||||
"margin_y": self.margin_y,
|
"margin_y": self.margin_y,
|
||||||
|
"compute_on_fly_refresh": self.compute_on_fly_refresh,
|
||||||
"widget_dimension_x": self.widget_dimension_x,
|
"widget_dimension_x": self.widget_dimension_x,
|
||||||
"widget_dimension_y": self.widget_dimension_y,
|
"widget_dimension_y": self.widget_dimension_y,
|
||||||
"background_color": self.background_color,
|
"background_color": self.background_color,
|
||||||
|
@ -167,7 +181,7 @@ class KpiDashboardItem(models.Model):
|
||||||
"kpi_id": self.kpi_id.id,
|
"kpi_id": self.kpi_id.id,
|
||||||
"suffix": self.kpi_id.suffix or "",
|
"suffix": self.kpi_id.suffix or "",
|
||||||
"prefix": self.kpi_id.prefix or "",
|
"prefix": self.kpi_id.prefix or "",
|
||||||
"compute_on_fly": self.kpi_id.compute_on_fly or "",
|
"compute_on_fly": self.kpi_id.compute_on_fly,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if self.kpi_id.compute_on_fly:
|
if self.kpi_id.compute_on_fly:
|
||||||
|
|
|
@ -10,7 +10,29 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
|
||||||
var DashboardController = BasicController.extend({
|
var DashboardController = BasicController.extend({
|
||||||
custom_events: _.extend({}, BasicController.prototype.custom_events, {
|
custom_events: _.extend({}, BasicController.prototype.custom_events, {
|
||||||
addDashboard: '_addDashboard',
|
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) {
|
renderPager: function ($node, options) {
|
||||||
options = _.extend({}, options, {
|
options = _.extend({}, options, {
|
||||||
validate: this.canBeDiscarded.bind(this),
|
validate: this.canBeDiscarded.bind(this),
|
||||||
|
|
|
@ -53,8 +53,21 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
|
||||||
'bus_service', 'onNotification',
|
'bus_service', 'onNotification',
|
||||||
this, this._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();
|
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) {
|
_onNotification: function (notifications) {
|
||||||
var self = this;
|
var self = this;
|
||||||
_.each(notifications, function (notification) {
|
_.each(notifications, function (notification) {
|
||||||
|
|
|
@ -54,6 +54,9 @@
|
||||||
<group name="color">
|
<group name="color">
|
||||||
<field name="background_color" widget="color"/>
|
<field name="background_color" widget="color"/>
|
||||||
</group>
|
</group>
|
||||||
|
<group name="config">
|
||||||
|
<field name="compute_on_fly_refresh"/>
|
||||||
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</page>
|
</page>
|
||||||
<page name="group" string="Groups">
|
<page name="group" string="Groups">
|
||||||
|
|
Loading…
Reference in New Issue