Public release from ruodoo-project: 19.0 - 2026-05-10 21:19:01 UTC
This commit is contained in:
8
mklab_base_indicators/models/__init__.py
Normal file
8
mklab_base_indicators/models/__init__.py
Normal file
@ -0,0 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import hg_link
|
||||
from . import hg_node
|
||||
from . import hg_index
|
||||
from . import hg_mixin
|
||||
from . import hg_value
|
||||
from . import hg_index_code
|
||||
29
mklab_base_indicators/models/hg_index.py
Normal file
29
mklab_base_indicators/models/hg_index.py
Normal file
@ -0,0 +1,29 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class HypergraphIndex(models.Model):
|
||||
_name = 'hg.index'
|
||||
|
||||
name = fields.Char(string='Название')
|
||||
internal_code_id = fields.Many2one(comodel_name='hg.index.code', string='Внутренний код')
|
||||
external_code = fields.Char(string='Внешний код')
|
||||
public = fields.Boolean(string='Публичный')
|
||||
value_ids = fields.One2many(comodel_name='hg.value', inverse_name='index_id', string='Значения')
|
||||
node_id = fields.Many2one(comodel_name='hg.node', string='Вершина графа')
|
||||
current_value = fields.Float(string='Текущее значение', compute='_compute_current_value', store=True)
|
||||
|
||||
@api.depends('value_ids.date_due')
|
||||
def _compute_current_value(self):
|
||||
today = fields.Date.today()
|
||||
for rec in self:
|
||||
valid_values = rec.value_ids.filtered(lambda v: (v.date_due or today) <= today)
|
||||
if valid_values:
|
||||
last_value = valid_values.sorted(lambda r: r.date_due, reverse=True)[0]
|
||||
rec.current_value = last_value.value_float_actual
|
||||
else:
|
||||
rec.current_value = 0
|
||||
|
||||
def calc(self):
|
||||
#метод, который вычисляет значение: или по формуле или по связанным
|
||||
return True
|
||||
11
mklab_base_indicators/models/hg_index_code.py
Normal file
11
mklab_base_indicators/models/hg_index_code.py
Normal file
@ -0,0 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
|
||||
class HypergraphIndexCode(models.Model):
|
||||
_name = 'hg.index.code'
|
||||
name = fields.Char('Имя')
|
||||
|
||||
name = fields.Char(string='Название кода')
|
||||
index_ids = fields.One2many(comodel_name='hg.index', inverse_name='internal_code_id',string="Показатели")
|
||||
|
||||
11
mklab_base_indicators/models/hg_link.py
Normal file
11
mklab_base_indicators/models/hg_link.py
Normal file
@ -0,0 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class HypergraphLinks(models.Model):
|
||||
_name = 'hg.link'
|
||||
_description = 'Строка матрицы связности'
|
||||
|
||||
name = fields.Char(string='Имя строки')
|
||||
source_id = fields.Many2one(comodel_name='hg.node', string='Источник')
|
||||
target_ids = fields.Many2many(comodel_name='hg.node', string='Множество-приемник')
|
||||
41
mklab_base_indicators/models/hg_mixin.py
Normal file
41
mklab_base_indicators/models/hg_mixin.py
Normal file
@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api
|
||||
|
||||
class HypergraphMixin(models.AbstractModel): #абстракт для миксина
|
||||
_name = 'hg.hg_mixin'
|
||||
|
||||
node_id = fields.Many2one(comodel_name='hg.node', string='Вершина графа')
|
||||
related_ids = fields.Many2many(comodel_name='hg.node', string='Связанные сущности', compute='_compute_related')
|
||||
index_ids = fields.Many2many(comodel_name='hg.index', string='Показатели', compute='_compute_indexes')
|
||||
|
||||
def _compute_indexes(self):
|
||||
for s in self:
|
||||
indexes = self.env['hg.index'].search([('node_id', '=', s.node_id.id)])
|
||||
s.index_ids = [fields.Command.set(indexes.ids)]
|
||||
|
||||
def _compute_related(self):
|
||||
for s in self:
|
||||
links = self.env['hg.link'].search([('source_id', '=', s.node_id.id)])
|
||||
nodes = set()
|
||||
for link in links:
|
||||
for target in link.target_ids:
|
||||
nodes.add(target.id)
|
||||
if nodes:
|
||||
s.related_ids = [fields.Command.set(list(nodes))]
|
||||
else:
|
||||
s.related_ids = False
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super(HypergraphMixin, self).create(vals_list)
|
||||
for res in records:
|
||||
new_node = self.env['hg.node'].create(
|
||||
{
|
||||
'name': res.name or 'Нет имени',
|
||||
'res_id': res.id,
|
||||
'res_model': res._name,
|
||||
}
|
||||
)
|
||||
res.node_id = new_node
|
||||
return records
|
||||
#todo написать unlink и чистку графа
|
||||
24
mklab_base_indicators/models/hg_node.py
Normal file
24
mklab_base_indicators/models/hg_node.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class HypergraphNode(models.Model): #узлы и вершины гиперграфа
|
||||
_name = 'hg.node'
|
||||
_description = 'Вершина графа'
|
||||
|
||||
name = fields.Char(string='Имя вершины')
|
||||
res_id = fields.Integer(string='ID ресурса')
|
||||
res_model = fields.Char(string='Модель')
|
||||
|
||||
def goto_related(self):
|
||||
vals= {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': self.res_model,
|
||||
'res_id': self.res_id,
|
||||
'views': [(False, 'form')],
|
||||
'view_id': False,
|
||||
'target': 'new',
|
||||
'view_mode': 'form',
|
||||
|
||||
}
|
||||
return vals
|
||||
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