commit
a0cb94c5e3
|
@ -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):
|
||||
|
@ -113,9 +114,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):
|
||||
|
@ -189,9 +192,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,16 @@
|
|||
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="write"
|
||||
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>
|
||||
|
|
Loading…
Reference in New Issue