diff --git a/kpi_dashboard/demo/demo_dashboard.xml b/kpi_dashboard/demo/demo_dashboard.xml
index 2d460cd50..3a31344cc 100644
--- a/kpi_dashboard/demo/demo_dashboard.xml
+++ b/kpi_dashboard/demo/demo_dashboard.xml
@@ -165,21 +165,24 @@ result = {"value": self.env.context.get('counter', 990)}
+1 to Counter
- 4
+ 3
10
- 3
+ 1
+ 2
#B41F1F
#EEBF77
{'counter': (context.counter or 990) + 1}
+
+ check_if(((context.counter or 990) + 1) % 2, '#ff0000', '#00ff00')
Counter
- 2
- 10
+ 3
+ 11
3
#4B0082
#ffffff
@@ -189,8 +192,8 @@ result = {"value": self.env.context.get('counter', 990)}
Integer
- 3
- 10
+ 4
+ 11
3
#ffffff
#4B0082
diff --git a/kpi_dashboard/models/kpi_dashboard.py b/kpi_dashboard/models/kpi_dashboard.py
index 244e402e6..24d423017 100644
--- a/kpi_dashboard/models/kpi_dashboard.py
+++ b/kpi_dashboard/models/kpi_dashboard.py
@@ -119,6 +119,8 @@ class KpiDashboardItem(models.Model):
font_color = fields.Char()
modify_context = fields.Boolean()
modify_context_expression = fields.Char()
+ modify_color = fields.Boolean()
+ modify_color_expression = fields.Char()
@api.depends('row', 'size_y')
def _compute_end_row(self):
@@ -176,9 +178,12 @@ class KpiDashboardItem(models.Model):
"color": self.color,
"font_color": self.font_color or "000000",
"modify_context": self.modify_context,
+ "modify_color": self.modify_color,
}
if self.modify_context:
vals['modify_context_expression'] = self.modify_context_expression
+ if self.modify_color:
+ vals['modify_color_expression'] = self.modify_color_expression
if self.kpi_id:
vals.update(
{
diff --git a/kpi_dashboard/models/kpi_kpi.py b/kpi_dashboard/models/kpi_kpi.py
index 3a9506c0b..a16d613d0 100644
--- a/kpi_dashboard/models/kpi_kpi.py
+++ b/kpi_dashboard/models/kpi_kpi.py
@@ -10,6 +10,7 @@ from odoo.tools.float_utils import float_compare
import re
import json
import datetime
+from dateutil import relativedelta
class KpiKpi(models.Model):
@@ -137,6 +138,7 @@ class KpiKpi(models.Model):
"model": self.browse(),
"datetime": datetime,
"float_compare": float_compare,
+ "relativedelta": relativedelta.relativedelta,
}
def _forbidden_code(self):
diff --git a/kpi_dashboard/static/src/js/dashboard_controller.js b/kpi_dashboard/static/src/js/dashboard_controller.js
index a6efee0aa..97db1765d 100644
--- a/kpi_dashboard/static/src/js/dashboard_controller.js
+++ b/kpi_dashboard/static/src/js/dashboard_controller.js
@@ -11,11 +11,14 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
init: function () {
this._super.apply(this, arguments);
this.dashboard_context = {};
+ this.dashboard_color_data = []
},
custom_events: _.extend({}, BasicController.prototype.custom_events, {
addDashboard: '_addDashboard',
refresh_on_fly: '_refreshOnFly',
modify_context: '_modifyContext',
+ add_modify_color: '_addModifyColor',
+ refresh_colors: '_refreshColors',
}),
_refreshOnFly: function (event) {
var self = this;
@@ -112,7 +115,34 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
)}),
);
this._refreshOnFly(event);
- }
+ this._refreshColors();
+ },
+ _addModifyColor: function (event) {
+ this.dashboard_color_data.push([
+ event.data.element_id,
+ event.data.expression,
+ ]);
+ },
+ _refreshColors: function () {
+ var self = this;
+ var ctx = this._getContext();
+ _.each(this.dashboard_color_data, function (data) {
+ var color = py.eval(data[1], {
+ context: _.extend(ctx, {
+ __getattr__: function() {return false},
+
+ }),
+ check_if: function(args) {
+ if (args[0].toJSON()) {
+ return args[1];
+ }
+ return args[2];
+ }
+ });
+ var $element = self.renderer.$el.find('#' + data[0]);
+ $element.css('background-color', color);
+ });
+ },
});
return DashboardController;
diff --git a/kpi_dashboard/static/src/js/dashboard_renderer.js b/kpi_dashboard/static/src/js/dashboard_renderer.js
index 3390b5f10..6bc38c492 100644
--- a/kpi_dashboard/static/src/js/dashboard_renderer.js
+++ b/kpi_dashboard/static/src/js/dashboard_renderer.js
@@ -36,7 +36,14 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
'kpi_dashboard.kpi', {widget: kpi}));
element.css('background-color', kpi.color);
element.css('color', kpi.font_color);
+ element.attr('id', _.uniqueId('kpi_'));
self.$grid.append(element);
+ if (kpi.modify_color) {
+ self.trigger_up("add_modify_color", {
+ element_id: element.attr("id"),
+ expression: kpi.modify_color_expression,
+ })
+ }
if (kpi.modify_context) {
element.on("click", self._onClickModifyContext.bind(
self, kpi.modify_context_expression));
@@ -71,6 +78,10 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
self.trigger_up('refresh_on_fly');
}, this.state.specialData.compute_on_fly_refresh *1000);
};
+ this.trigger_up('refresh_colors');
+ this.trigger_up('refresh_on_fly');
+ // We need to refreshs data in order compute with the current
+ // context
return $.when();
},
on_detach_callback: function () {
diff --git a/kpi_dashboard/views/kpi_dashboard.xml b/kpi_dashboard/views/kpi_dashboard.xml
index f73eb9aa6..905431250 100644
--- a/kpi_dashboard/views/kpi_dashboard.xml
+++ b/kpi_dashboard/views/kpi_dashboard.xml
@@ -150,6 +150,10 @@
+
+