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
Brian McMaster
parent
265982fdab
commit
7e569a270d
@@ -5,7 +5,7 @@
|
||||
"name": "Kpi Dashboard",
|
||||
"summary": """
|
||||
Create Dashboards using kpis""",
|
||||
"version": "14.0.1.0.0",
|
||||
"version": "14.0.1.1.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Creu Blanca,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/reporting-engine",
|
||||
|
||||
@@ -99,6 +99,7 @@ msgid "Computation Method"
|
||||
msgstr ""
|
||||
|
||||
#. module: kpi_dashboard
|
||||
#: model:ir.model.fields,field_description:kpi_dashboard.field_kpi_dashboard_item__compute_on_fly
|
||||
#: model:ir.model.fields,field_description:kpi_dashboard.field_kpi_kpi__compute_on_fly
|
||||
msgid "Compute On Fly"
|
||||
msgstr ""
|
||||
@@ -549,6 +550,11 @@ msgstr ""
|
||||
msgid "Size Y of the widget cannot be bigger than 10"
|
||||
msgstr ""
|
||||
|
||||
#. module: kpi_dashboard
|
||||
#: model:ir.model.fields,field_description:kpi_dashboard.field_kpi_dashboard_item__special_context
|
||||
msgid "Special Context"
|
||||
msgstr ""
|
||||
|
||||
#. module: kpi_dashboard
|
||||
#: model:ir.model.fields,field_description:kpi_dashboard.field_kpi_kpi__store_history
|
||||
msgid "Store History"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
|
||||
class KpiDashboard(models.Model):
|
||||
@@ -119,9 +120,11 @@ class KpiDashboardItem(models.Model):
|
||||
color = fields.Char()
|
||||
font_color = fields.Char()
|
||||
modify_context = fields.Boolean()
|
||||
compute_on_fly = fields.Boolean(related="kpi_id.compute_on_fly")
|
||||
modify_context_expression = fields.Char()
|
||||
modify_color = fields.Boolean()
|
||||
modify_color_expression = fields.Char()
|
||||
special_context = fields.Char()
|
||||
|
||||
@api.depends("row", "size_y")
|
||||
def _compute_end_row(self):
|
||||
@@ -195,9 +198,17 @@ class KpiDashboardItem(models.Model):
|
||||
}
|
||||
)
|
||||
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(
|
||||
{
|
||||
"value": self.kpi_id._compute_value(),
|
||||
"value": kpi._compute_value(),
|
||||
"value_last_update": fields.Datetime.now(),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -162,15 +162,15 @@
|
||||
widget="ace"
|
||||
options="{'mode': 'python'}"
|
||||
/>
|
||||
<field
|
||||
name="special_context"
|
||||
attrs="{'invisible': [('compute_on_fly', '=', False)]}"
|
||||
/>
|
||||
<field name="compute_on_fly" invisible="1" />
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button
|
||||
name="store_data"
|
||||
string="Save"
|
||||
type="object"
|
||||
class="oe_highlight"
|
||||
/>
|
||||
<button string="Save" special="save" class="oe_highlight" />
|
||||
<button special="cancel" string="Cancel" class="oe_link" />
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user