[IMP] kpi_dashboard: Allow to edit context using items
parent
6ae79aec8a
commit
90483ef7f4
|
@ -6,6 +6,7 @@
|
|||
<field name="widget_dimension_y">50</field>
|
||||
<field name="widget_dimension_x">250</field>
|
||||
<field name="background_color">#020202</field>
|
||||
<field name="compute_on_fly_refresh">30</field>
|
||||
</record>
|
||||
|
||||
<record id="widget_number_01" model="kpi.kpi">
|
||||
|
@ -87,6 +88,26 @@ result = {"graphs": [
|
|||
<function model="kpi.kpi" name="compute"
|
||||
eval="[[ref('widget_graph')]]"/>
|
||||
|
||||
<record id="widget_integer" model="kpi.kpi">
|
||||
<field name="name">Integer counter</field>
|
||||
<field name="computation_method">code</field>
|
||||
<field name="widget">integer</field>
|
||||
<field name="compute_on_fly" eval="True"/>
|
||||
<field name="code">
|
||||
result = {"value": self.env.context.get('counter', 990)}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="widget_counter" model="kpi.kpi">
|
||||
<field name="name">Counter</field>
|
||||
<field name="computation_method">code</field>
|
||||
<field name="widget">counter</field>
|
||||
<field name="compute_on_fly" eval="True"/>
|
||||
<field name="code">
|
||||
result = {"value": self.env.context.get('counter', 990)}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="dashboard_widget_text" model="kpi.dashboard.item">
|
||||
<field name="name">Dashboard title</field>
|
||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||
|
@ -141,6 +162,40 @@ result = {"graphs": [
|
|||
<field name="font_color">#ffffff</field>
|
||||
</record>
|
||||
|
||||
<record id="dashboard_widget_add_counter" model="kpi.dashboard.item">
|
||||
<field name="name">+1 to Counter</field>
|
||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||
<field name="column">4</field>
|
||||
<field name="row">10</field>
|
||||
<field name="size_y">3</field>
|
||||
<field name="color">#B41F1F</field>
|
||||
<field name="font_color">#EEBF77</field>
|
||||
<field name="modify_context" eval="True"/>
|
||||
<field name="modify_context_expression">{'counter': (context.counter or 990) + 1}</field>
|
||||
</record>
|
||||
|
||||
<record id="dashboard_widget_counter" model="kpi.dashboard.item">
|
||||
<field name="name">Counter</field>
|
||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||
<field name="kpi_id" ref="widget_counter"/>
|
||||
<field name="column">2</field>
|
||||
<field name="row">10</field>
|
||||
<field name="size_y">3</field>
|
||||
<field name="color">#4B0082</field>
|
||||
<field name="font_color">#ffffff</field>
|
||||
</record>
|
||||
|
||||
<record id="dashboard_widget_integer" model="kpi.dashboard.item">
|
||||
<field name="name">Integer</field>
|
||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||
<field name="kpi_id" ref="widget_integer"/>
|
||||
<field name="column">3</field>
|
||||
<field name="row">10</field>
|
||||
<field name="size_y">3</field>
|
||||
<field name="color">#ffffff</field>
|
||||
<field name="font_color">#4B0082</field>
|
||||
</record>
|
||||
|
||||
<record id="dashboard_widget_graph" model="kpi.dashboard.item">
|
||||
<field name="name">Graph</field>
|
||||
<field name="dashboard_id" ref="demo_dashboard"/>
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
<field name="size_y"/>
|
||||
<field name="color" widget="color"/>
|
||||
<field name="font_color" widget="color"/>
|
||||
<button name="technical_config" string=""
|
||||
type="object" icon="fa-edit"
|
||||
groups="base.group_no_one"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
@ -111,4 +114,53 @@
|
|||
<field name="sequence" eval="16"/> <!-- TODO -->
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="kpi_dashboard_item_form_view">
|
||||
<field name="name">kpi.dashboard.item.form (in kpi_dashboard)</field>
|
||||
<field name="model">kpi.dashboard.item</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header/>
|
||||
<sheet>
|
||||
<div name="button_box" class="oe_button_box"/>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="dashboard_id"/>
|
||||
<field name="kpi_id"/>
|
||||
<field name="column"/>
|
||||
<field name="row"/>
|
||||
<field name="size_x"/>
|
||||
<field name="size_y"/>
|
||||
<field name="color" widget="color"/>
|
||||
<field name="font_color" widget="color"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="kpi_dashboard_item_config_form_view">
|
||||
<field name="name">kpi.dashboard.item.form (in kpi_dashboard)</field>
|
||||
<field name="model">kpi.dashboard.item</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header/>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="modify_context"/>
|
||||
<field name="modify_context_expression"
|
||||
attrs="{'invisible': [('modify_context', '=', False)]}"
|
||||
widget="ace" options="{'mode': 'python'}"/>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button name="write"
|
||||
string="Save" type="object"
|
||||
class="oe_highlight"/>
|
||||
<button special="cancel" string="Cancel"
|
||||
class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
|
Loading…
Reference in New Issue