Files
gzth/yuthon_ai_agent/models/ai_manual.py
T
2026-05-28 15:37:42 +08:00

42 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
import logging
from odoo import models, fields, api
_logger = logging.getLogger(__name__)
class AiManual(models.Model):
_name = 'ai.manual'
_description = '操作手册'
_order = 'module_name, sequence, id'
name = fields.Char('手册名称', required=True)
module_name = fields.Char('所属模块', required=True,
help='如:销售管理、采购管理、库存管理、人事管理等')
sequence = fields.Integer('排序', default=10)
content = fields.Text('手册内容', required=True,
help='AI 将直接读取此内容来指导用户操作')
attachment_ids = fields.Many2many(
'ir.attachment', 'ai_manual_attachment_rel',
'manual_id', 'attachment_id',
string='参考附件',
help='可上传 PDF/Word 等原始手册文件作为参考(AI 不会直接读取附件,请将关键内容填入上方文本框)')
active = fields.Boolean('启用', default=True)
note = fields.Text('备注')
@api.model
def get_all_manual_content(self):
"""获取所有启用的手册内容,按模块分组返回"""
manuals = self.sudo().search([('active', '=', True)])
if not manuals:
return ''
result = []
current_module = ''
for manual in manuals:
if manual.module_name != current_module:
current_module = manual.module_name
result.append(f'\n【{current_module}】')
result.append(f'● {manual.name}:\n{manual.content}')
return '\n'.join(result)