mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[IMP] kpi_dashboard: Allow to set a specific context for a KPI
This commit is contained in:
committed by
Olga Marco
parent
76dc8b2754
commit
2d45b0f5f9
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.tools.safe_eval import safe_eval
|
||||||
|
|
||||||
|
|
||||||
class KpiDashboard(models.Model):
|
class KpiDashboard(models.Model):
|
||||||
@@ -119,9 +120,11 @@ class KpiDashboardItem(models.Model):
|
|||||||
color = fields.Char()
|
color = fields.Char()
|
||||||
font_color = fields.Char()
|
font_color = fields.Char()
|
||||||
modify_context = fields.Boolean()
|
modify_context = fields.Boolean()
|
||||||
|
compute_on_fly = fields.Boolean(related="kpi_id.compute_on_fly")
|
||||||
modify_context_expression = fields.Char()
|
modify_context_expression = fields.Char()
|
||||||
modify_color = fields.Boolean()
|
modify_color = fields.Boolean()
|
||||||
modify_color_expression = fields.Char()
|
modify_color_expression = fields.Char()
|
||||||
|
special_context = fields.Char()
|
||||||
|
|
||||||
@api.depends("row", "size_y")
|
@api.depends("row", "size_y")
|
||||||
def _compute_end_row(self):
|
def _compute_end_row(self):
|
||||||
@@ -195,9 +198,17 @@ class KpiDashboardItem(models.Model):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if self.kpi_id.compute_on_fly:
|
if self.kpi_id.compute_on_fly:
|
||||||
|
kpi = self.kpi_id
|
||||||
|
if self.special_context:
|
||||||
|
try:
|
||||||
|
ctx = safe_eval(self.special_context)
|
||||||
|
if isinstance(ctx, dict):
|
||||||
|
kpi = kpi.with_context(**ctx)
|
||||||
|
except SyntaxError:
|
||||||
|
pass
|
||||||
vals.update(
|
vals.update(
|
||||||
{
|
{
|
||||||
"value": self.kpi_id._compute_value(),
|
"value": kpi._compute_value(),
|
||||||
"value_last_update": fields.Datetime.now(),
|
"value_last_update": fields.Datetime.now(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -162,15 +162,15 @@
|
|||||||
widget="ace"
|
widget="ace"
|
||||||
options="{'mode': 'python'}"
|
options="{'mode': 'python'}"
|
||||||
/>
|
/>
|
||||||
|
<field
|
||||||
|
name="special_context"
|
||||||
|
attrs="{'invisible': [('compute_on_fly', '=', False)]}"
|
||||||
|
/>
|
||||||
|
<field name="compute_on_fly" invisible="1" />
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
<footer>
|
<footer>
|
||||||
<button
|
<button string="Save" special="save" class="oe_highlight" />
|
||||||
name="store_data"
|
|
||||||
string="Save"
|
|
||||||
type="object"
|
|
||||||
class="oe_highlight"
|
|
||||||
/>
|
|
||||||
<button special="cancel" string="Cancel" class="oe_link" />
|
<button special="cancel" string="Cancel" class="oe_link" />
|
||||||
</footer>
|
</footer>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user