From 5d0acb9589b8cb49e014303527764b85517349f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= Date: Fri, 29 May 2026 11:01:16 +0800 Subject: [PATCH] =?UTF-8?q?ai=E5=8A=A8=E6=80=81=E6=8A=A5=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/ai_report_template_config.py | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 yuthon_ai_agent/models/ai_report_template_config.py diff --git a/yuthon_ai_agent/models/ai_report_template_config.py b/yuthon_ai_agent/models/ai_report_template_config.py new file mode 100644 index 000000000..cffa03850 --- /dev/null +++ b/yuthon_ai_agent/models/ai_report_template_config.py @@ -0,0 +1,128 @@ +# -*- coding: utf-8 -*- +import json +import logging + +from odoo import models, fields, api + +_logger = logging.getLogger(__name__) + + +class AiReportTemplateColumn(models.Model): + """报表模板 - 列定义""" + _name = 'ai.report.template.column' + _description = '列定义' + _order = 'sequence, id' + + template_id = fields.Many2one('ai.report.template', string='模板', + required=True, ondelete='cascade') + field_name = fields.Char('字段名', required=True) + label = fields.Char('显示名称', + help='不填则默认使用字段名') + width = fields.Integer('列宽', default=120) + sequence = fields.Integer('排序', default=10) + + +class AiReportTemplateCard(models.Model): + """报表模板 - 汇总卡片""" + _name = 'ai.report.template.card' + _description = '汇总卡片' + _order = 'sequence, id' + + template_id = fields.Many2one('ai.report.template', string='模板', + required=True, ondelete='cascade') + label = fields.Char('卡片标签', required=True) + field_name = fields.Char('统计字段', required=True) + calc = fields.Selection([ + ('sum', '求和'), + ('count', '计数'), + ('distinct', '去重'), + ], string='计算方式', default='sum') + prefix = fields.Char('前缀', help='如 ¥、$ 等') + unit = fields.Char('单位', help='如 万、% 等') + sequence = fields.Integer('排序', default=10) + + +class AiReportTemplateGroupBy(models.Model): + """报表模板 - 分组设置""" + _name = 'ai.report.template.group.by' + _description = '分组设置' + _order = 'sequence, id' + + template_id = fields.Many2one('ai.report.template', string='模板', + required=True, ondelete='cascade') + field_name = fields.Char('分组字段', required=True) + label = fields.Char('显示名称') + sequence = fields.Integer('排序', default=10) + + +class AiReportTemplateColorRule(models.Model): + """报表模板 - 颜色规则""" + _name = 'ai.report.template.color.rule' + _description = '颜色规则' + _order = 'sequence, id' + + template_id = fields.Many2one('ai.report.template', string='模板', + required=True, ondelete='cascade') + field_name = fields.Char('字段名', required=True) + op = fields.Selection([ + ('eq', '等于'), + ('>=', '大于等于'), + ('<=', '小于等于'), + ('>', '大于'), + ('<', '小于'), + ('contains', '包含'), + ], string='操作符', default='eq') + value = fields.Char('值') + color = fields.Char('颜色', default='#5DCAA5', + help='十六进制颜色代码') + sequence = fields.Integer('排序', default=10) + + +class AiReportTemplateFilter(models.Model): + """报表模板 - 筛选器""" + _name = 'ai.report.template.filter' + _description = '筛选器' + _order = 'sequence, id' + + template_id = fields.Many2one('ai.report.template', string='模板', + required=True, ondelete='cascade') + field_name = fields.Char('字段名', required=True) + filter_type = fields.Selection([ + ('input', '输入框'), + ('select', '下拉选择'), + ], string='筛选类型', default='input') + label = fields.Char('显示名称') + options = fields.Char('选项', + help='下拉选择时,逗号分隔的选项列表。如:草稿,已确认,已完成') + sequence = fields.Integer('排序', default=10) + + +class AiReportTemplateParamDef(models.Model): + """报表模板 - AI参数定义""" + _name = 'ai.report.template.param.def' + _description = 'AI参数定义' + _order = 'sequence, id' + + template_id = fields.Many2one('ai.report.template', string='模板', + required=True, ondelete='cascade') + name = fields.Char('参数名', required=True, + help='AI 识别参数用的键名,如 date_from') + label = fields.Char('显示名', + help='给 AI 看的说明,如"开始日期"') + param_type = fields.Selection([ + ('date', '日期'), + ('char', '文本'), + ('select', '选择'), + ('float', '数字'), + ('int', '整数'), + ], string='参数类型', default='char') + domain_field = fields.Char('映射字段', + help='映射到模型字段名,如 date_order') + op = fields.Char('操作符', default='=', + help='Odoo domain 操作符,如 >=、<=、ilike、=') + description = fields.Text('说明', + help='详细说明 AI 如何提取此参数') + options = fields.Char('选项', + help='select 类型时,逗号分隔的选项') + required = fields.Boolean('必填') + sequence = fields.Integer('排序', default=10)