diff --git a/kpi_dashboard/demo/demo_dashboard.xml b/kpi_dashboard/demo/demo_dashboard.xml
index 958e1580..2d460cd5 100644
--- a/kpi_dashboard/demo/demo_dashboard.xml
+++ b/kpi_dashboard/demo/demo_dashboard.xml
@@ -6,6 +6,7 @@
50
250
#020202
+ 30
@@ -87,6 +88,26 @@ result = {"graphs": [
+
+ Integer counter
+ code
+ integer
+
+
+result = {"value": self.env.context.get('counter', 990)}
+
+
+
+
+ Counter
+ code
+ counter
+
+
+result = {"value": self.env.context.get('counter', 990)}
+
+
+
Dashboard title
@@ -141,6 +162,40 @@ result = {"graphs": [
#ffffff
+
+ +1 to Counter
+
+ 4
+ 10
+ 3
+ #B41F1F
+ #EEBF77
+
+ {'counter': (context.counter or 990) + 1}
+
+
+
+ Counter
+
+
+ 2
+ 10
+ 3
+ #4B0082
+ #ffffff
+
+
+
+ Integer
+
+
+ 3
+ 10
+ 3
+ #ffffff
+ #4B0082
+
+
Graph
diff --git a/kpi_dashboard/models/kpi_dashboard.py b/kpi_dashboard/models/kpi_dashboard.py
index 770a2546..244e402e 100644
--- a/kpi_dashboard/models/kpi_dashboard.py
+++ b/kpi_dashboard/models/kpi_dashboard.py
@@ -117,6 +117,8 @@ class KpiDashboardItem(models.Model):
size_y = fields.Integer(required=True, default=1)
color = fields.Char()
font_color = fields.Char()
+ modify_context = fields.Boolean()
+ modify_context_expression = fields.Char()
@api.depends('row', 'size_y')
def _compute_end_row(self):
@@ -173,7 +175,10 @@ class KpiDashboardItem(models.Model):
"sizey": self.size_y,
"color": self.color,
"font_color": self.font_color or "000000",
+ "modify_context": self.modify_context,
}
+ if self.modify_context:
+ vals['modify_context_expression'] = self.modify_context_expression
if self.kpi_id:
vals.update(
{
@@ -205,3 +210,16 @@ class KpiDashboardItem(models.Model):
for kpi in self:
result.append(kpi._read_dashboard())
return result
+
+ def technical_config(self):
+ self.ensure_one()
+ return {
+ 'name': self.display_name,
+ 'res_model': self._name,
+ 'res_id': self.id,
+ 'type': 'ir.actions.act_window',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'view_id': self.env.ref(
+ 'kpi_dashboard.kpi_dashboard_item_config_form_view').id,
+ }
diff --git a/kpi_dashboard/static/src/js/dashboard_controller.js b/kpi_dashboard/static/src/js/dashboard_controller.js
index 952077bd..a6efee0a 100644
--- a/kpi_dashboard/static/src/js/dashboard_controller.js
+++ b/kpi_dashboard/static/src/js/dashboard_controller.js
@@ -8,9 +8,14 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
var _t = core._t;
var DashboardController = BasicController.extend({
+ init: function () {
+ this._super.apply(this, arguments);
+ this.dashboard_context = {};
+ },
custom_events: _.extend({}, BasicController.prototype.custom_events, {
addDashboard: '_addDashboard',
refresh_on_fly: '_refreshOnFly',
+ modify_context: '_modifyContext',
}),
_refreshOnFly: function (event) {
var self = this;
@@ -18,11 +23,7 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
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}
- ),
+ context: this._getContext(),
}).then(function (data) {
_.each(data, function (item) {
// We will follow the same logic used on Bus Notifications
@@ -91,6 +92,27 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
this._updateButtons();
this.$buttons.appendTo($node);
},
+ _getContext: function () {
+ return _.extend(
+ {},
+ this.model.get(this.handle, {raw: true}).getContext(),
+ {bin_size: true},
+ this.dashboard_context,
+ )
+ },
+ _modifyContext: function (event) {
+ var ctx = this._getContext();
+ this.dashboard_context = _.extend(
+ this.dashboard_context,
+ py.eval(event.data.context, {context: _.extend(
+ ctx,
+ {__getattr__: function() {return false}}
+ // We need to add this in order to allow to use undefined
+ // context items
+ )}),
+ );
+ this._refreshOnFly(event);
+ }
});
return DashboardController;
diff --git a/kpi_dashboard/static/src/js/dashboard_renderer.js b/kpi_dashboard/static/src/js/dashboard_renderer.js
index b2603771..3390b5f1 100644
--- a/kpi_dashboard/static/src/js/dashboard_renderer.js
+++ b/kpi_dashboard/static/src/js/dashboard_renderer.js
@@ -16,6 +16,12 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
var widget = new Widget(this, kpi);
return widget;
},
+ _onClickModifyContext: function (modify_context_expression, event) {
+ this.trigger_up('modify_context', {
+ context: modify_context_expression,
+ event: event,
+ })
+ },
_renderView: function () {
this.$el.html($(qweb.render('dashboard_kpi.dashboard')));
this.$el.css(
@@ -31,6 +37,12 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
element.css('background-color', kpi.color);
element.css('color', kpi.font_color);
self.$grid.append(element);
+ if (kpi.modify_context) {
+ element.on("click", self._onClickModifyContext.bind(
+ self, kpi.modify_context_expression));
+ element.css('cursor', 'pointer');
+ // We want to set it show as clickable
+ }
self.kpi_widget[kpi.id] = self._getDashboardWidget(kpi);
self.kpi_widget[kpi.id].appendTo(element);
});
diff --git a/kpi_dashboard/views/kpi_dashboard.xml b/kpi_dashboard/views/kpi_dashboard.xml
index e2f841ad..f73eb9aa 100644
--- a/kpi_dashboard/views/kpi_dashboard.xml
+++ b/kpi_dashboard/views/kpi_dashboard.xml
@@ -36,6 +36,9 @@
+
@@ -111,4 +114,53 @@
+
+ kpi.dashboard.item.form (in kpi_dashboard)
+ kpi.dashboard.item
+
+
+
+
+
+
+ kpi.dashboard.item.form (in kpi_dashboard)
+ kpi.dashboard.item
+
+
+
+
+