[IMP] kpi_dashboard: edit color
parent
ff30242838
commit
bea6b45011
|
@ -165,21 +165,24 @@ result = {"value": self.env.context.get('counter', 990)}
|
||||||
<record id="dashboard_widget_add_counter" model="kpi.dashboard.item">
|
<record id="dashboard_widget_add_counter" model="kpi.dashboard.item">
|
||||||
<field name="name">+1 to Counter</field>
|
<field name="name">+1 to Counter</field>
|
||||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||||
<field name="column">4</field>
|
<field name="column">3</field>
|
||||||
<field name="row">10</field>
|
<field name="row">10</field>
|
||||||
<field name="size_y">3</field>
|
<field name="size_y">1</field>
|
||||||
|
<field name="size_x">2</field>
|
||||||
<field name="color">#B41F1F</field>
|
<field name="color">#B41F1F</field>
|
||||||
<field name="font_color">#EEBF77</field>
|
<field name="font_color">#EEBF77</field>
|
||||||
<field name="modify_context" eval="True"/>
|
<field name="modify_context" eval="True"/>
|
||||||
<field name="modify_context_expression">{'counter': (context.counter or 990) + 1}</field>
|
<field name="modify_context_expression">{'counter': (context.counter or 990) + 1}</field>
|
||||||
|
<field name="modify_color" eval="True"/>
|
||||||
|
<field name="modify_color_expression">check_if(((context.counter or 990) + 1) % 2, '#ff0000', '#00ff00')</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="dashboard_widget_counter" model="kpi.dashboard.item">
|
<record id="dashboard_widget_counter" model="kpi.dashboard.item">
|
||||||
<field name="name">Counter</field>
|
<field name="name">Counter</field>
|
||||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||||
<field name="kpi_id" ref="widget_counter"/>
|
<field name="kpi_id" ref="widget_counter"/>
|
||||||
<field name="column">2</field>
|
<field name="column">3</field>
|
||||||
<field name="row">10</field>
|
<field name="row">11</field>
|
||||||
<field name="size_y">3</field>
|
<field name="size_y">3</field>
|
||||||
<field name="color">#4B0082</field>
|
<field name="color">#4B0082</field>
|
||||||
<field name="font_color">#ffffff</field>
|
<field name="font_color">#ffffff</field>
|
||||||
|
@ -189,8 +192,8 @@ result = {"value": self.env.context.get('counter', 990)}
|
||||||
<field name="name">Integer</field>
|
<field name="name">Integer</field>
|
||||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||||
<field name="kpi_id" ref="widget_integer"/>
|
<field name="kpi_id" ref="widget_integer"/>
|
||||||
<field name="column">3</field>
|
<field name="column">4</field>
|
||||||
<field name="row">10</field>
|
<field name="row">11</field>
|
||||||
<field name="size_y">3</field>
|
<field name="size_y">3</field>
|
||||||
<field name="color">#ffffff</field>
|
<field name="color">#ffffff</field>
|
||||||
<field name="font_color">#4B0082</field>
|
<field name="font_color">#4B0082</field>
|
||||||
|
|
|
@ -119,6 +119,8 @@ class KpiDashboardItem(models.Model):
|
||||||
font_color = fields.Char()
|
font_color = fields.Char()
|
||||||
modify_context = fields.Boolean()
|
modify_context = fields.Boolean()
|
||||||
modify_context_expression = fields.Char()
|
modify_context_expression = fields.Char()
|
||||||
|
modify_color = fields.Boolean()
|
||||||
|
modify_color_expression = fields.Char()
|
||||||
|
|
||||||
@api.depends('row', 'size_y')
|
@api.depends('row', 'size_y')
|
||||||
def _compute_end_row(self):
|
def _compute_end_row(self):
|
||||||
|
@ -176,9 +178,12 @@ class KpiDashboardItem(models.Model):
|
||||||
"color": self.color,
|
"color": self.color,
|
||||||
"font_color": self.font_color or "000000",
|
"font_color": self.font_color or "000000",
|
||||||
"modify_context": self.modify_context,
|
"modify_context": self.modify_context,
|
||||||
|
"modify_color": self.modify_color,
|
||||||
}
|
}
|
||||||
if self.modify_context:
|
if self.modify_context:
|
||||||
vals['modify_context_expression'] = self.modify_context_expression
|
vals['modify_context_expression'] = self.modify_context_expression
|
||||||
|
if self.modify_color:
|
||||||
|
vals['modify_color_expression'] = self.modify_color_expression
|
||||||
if self.kpi_id:
|
if self.kpi_id:
|
||||||
vals.update(
|
vals.update(
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,7 @@ from odoo.tools.float_utils import float_compare
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
import datetime
|
import datetime
|
||||||
|
from dateutil import relativedelta
|
||||||
|
|
||||||
|
|
||||||
class KpiKpi(models.Model):
|
class KpiKpi(models.Model):
|
||||||
|
@ -137,6 +138,7 @@ class KpiKpi(models.Model):
|
||||||
"model": self.browse(),
|
"model": self.browse(),
|
||||||
"datetime": datetime,
|
"datetime": datetime,
|
||||||
"float_compare": float_compare,
|
"float_compare": float_compare,
|
||||||
|
"relativedelta": relativedelta.relativedelta,
|
||||||
}
|
}
|
||||||
|
|
||||||
def _forbidden_code(self):
|
def _forbidden_code(self):
|
||||||
|
|
|
@ -11,11 +11,14 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
|
||||||
init: function () {
|
init: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.dashboard_context = {};
|
this.dashboard_context = {};
|
||||||
|
this.dashboard_color_data = []
|
||||||
},
|
},
|
||||||
custom_events: _.extend({}, BasicController.prototype.custom_events, {
|
custom_events: _.extend({}, BasicController.prototype.custom_events, {
|
||||||
addDashboard: '_addDashboard',
|
addDashboard: '_addDashboard',
|
||||||
refresh_on_fly: '_refreshOnFly',
|
refresh_on_fly: '_refreshOnFly',
|
||||||
modify_context: '_modifyContext',
|
modify_context: '_modifyContext',
|
||||||
|
add_modify_color: '_addModifyColor',
|
||||||
|
refresh_colors: '_refreshColors',
|
||||||
}),
|
}),
|
||||||
_refreshOnFly: function (event) {
|
_refreshOnFly: function (event) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -112,7 +115,34 @@ odoo.define('kpi_dashboard.DashboardController', function (require) {
|
||||||
)}),
|
)}),
|
||||||
);
|
);
|
||||||
this._refreshOnFly(event);
|
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;
|
return DashboardController;
|
||||||
|
|
|
@ -36,7 +36,14 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
|
||||||
'kpi_dashboard.kpi', {widget: kpi}));
|
'kpi_dashboard.kpi', {widget: kpi}));
|
||||||
element.css('background-color', kpi.color);
|
element.css('background-color', kpi.color);
|
||||||
element.css('color', kpi.font_color);
|
element.css('color', kpi.font_color);
|
||||||
|
element.attr('id', _.uniqueId('kpi_'));
|
||||||
self.$grid.append(element);
|
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) {
|
if (kpi.modify_context) {
|
||||||
element.on("click", self._onClickModifyContext.bind(
|
element.on("click", self._onClickModifyContext.bind(
|
||||||
self, kpi.modify_context_expression));
|
self, kpi.modify_context_expression));
|
||||||
|
@ -71,6 +78,10 @@ odoo.define('kpi_dashboard.DashboardRenderer', function (require) {
|
||||||
self.trigger_up('refresh_on_fly');
|
self.trigger_up('refresh_on_fly');
|
||||||
}, this.state.specialData.compute_on_fly_refresh *1000);
|
}, 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();
|
return $.when();
|
||||||
},
|
},
|
||||||
on_detach_callback: function () {
|
on_detach_callback: function () {
|
||||||
|
|
|
@ -150,6 +150,10 @@
|
||||||
<field name="modify_context_expression"
|
<field name="modify_context_expression"
|
||||||
attrs="{'invisible': [('modify_context', '=', False)]}"
|
attrs="{'invisible': [('modify_context', '=', False)]}"
|
||||||
widget="ace" options="{'mode': 'python'}"/>
|
widget="ace" options="{'mode': 'python'}"/>
|
||||||
|
<field name="modify_color"/>
|
||||||
|
<field name="modify_color_expression"
|
||||||
|
attrs="{'invisible': [('modify_color', '=', False)]}"
|
||||||
|
widget="ace" options="{'mode': 'python'}"/>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
<footer>
|
<footer>
|
||||||
|
|
Loading…
Reference in New Issue