Public release from ruodoo-project: 19.0 - 2026-05-10 21:19:01 UTC
This commit is contained in:
35
mklab_base_indicators/models/hg_value.py
Normal file
35
mklab_base_indicators/models/hg_value.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
class HypergraphValue(models.Model): #значения. Решил объединить временные ряды
|
||||
_name = 'hg.value'
|
||||
name = fields.Char('Имя')
|
||||
|
||||
value_float_actual = fields.Float(string='Факт')
|
||||
value_float_plan = fields.Float(string='План')
|
||||
date_due = fields.Date(string='Дата', required=True)
|
||||
index_id = fields.Many2one(comodel_name='hg.index', string='Индекс')
|
||||
type = fields.Selection(
|
||||
[
|
||||
('alone', 'Простой'),
|
||||
('formula', 'Формула')
|
||||
],
|
||||
string='Тип',
|
||||
default='alone',
|
||||
required=True
|
||||
)
|
||||
formula = fields.Char(string='Формула')
|
||||
|
||||
def calc(self):
|
||||
#метод, который вычисляет значение: или по формуле или по связанным
|
||||
for rec in self:
|
||||
if rec.type == 'formula':
|
||||
localdict = {
|
||||
'node_value': rec,
|
||||
'node_index': rec.index_id,
|
||||
'datatime': fields.Date.today(),
|
||||
}
|
||||
result = safe_eval(rec.formula or '0', localdict, mode="eval")
|
||||
rec.value_float_actual = result
|
||||
return True
|
||||
Reference in New Issue
Block a user