40 lines
1.8 KiB
Python
40 lines
1.8 KiB
Python
from odoo import models, fields
|
|
|
|
|
|
class BrainNode(models.Model):
|
|
"""脑图节点。父子关系通过 parent_id 自引用表达(等价于 menu.parent_id)。"""
|
|
_name = 'yuthon.brain.node'
|
|
_description = '脑图节点'
|
|
_rec_name = 'label'
|
|
_order = 'sequence, id'
|
|
|
|
source_id = fields.Many2one(
|
|
'yuthon.brain.source', string='数据源', required=True, ondelete='cascade',
|
|
)
|
|
parent_id = fields.Many2one(
|
|
'yuthon.brain.node', string='父节点', ondelete='cascade',
|
|
)
|
|
rel_type = fields.Selection(
|
|
[('parent', '父级'), ('child', '子级'), ('jump', '跳转')],
|
|
string='关系类型', default='child',
|
|
)
|
|
label = fields.Char(string='显示文字', required=True)
|
|
color = fields.Char(string='颜色', default='#1E6FFF', help='节点主题色,十六进制')
|
|
icon = fields.Char(string='图标', help='可选,前端展示用')
|
|
extra = fields.Text(string='扩展数据(JSON)', help='前端自由展示的额外字段,JSON 字符串')
|
|
auto = fields.Boolean(
|
|
string='自动同步', default=False,
|
|
help='由 source.action_sync() 生成;重同步时会被清理,手动维护的节点不会被清。',
|
|
)
|
|
sequence = fields.Integer(default=10)
|
|
level = fields.Integer(string='层级', default=0, help='可选;前端按 parent_id 链推导真实深度')
|
|
|
|
child_ids = fields.One2many('yuthon.brain.node', 'parent_id', string='子节点')
|
|
edge_from_ids = fields.One2many('yuthon.brain.edge', 'from_id', string='出边')
|
|
edge_to_ids = fields.One2many('yuthon.brain.edge', 'to_id', string='入边')
|
|
|
|
_sql_constraints = [
|
|
('src_parent_label_uniq', 'unique(source_id, parent_id, label)',
|
|
'同一数据源内、同一父节点下显示文字不能重复'),
|
|
]
|