报表
This commit is contained in:
@@ -60,13 +60,13 @@ class AiReportTemplate(models.Model):
|
||||
help='自动从参数定义行生成,也可手动编辑 JSON')
|
||||
|
||||
# ===== Computed: report_config =====
|
||||
@api.depends('column_ids', 'card_ids', 'group_by_ids',
|
||||
'color_rule_ids', 'filter_ids', 'default_visible')
|
||||
@api.depends('column_ids', 'column_ids.color_rule_ids',
|
||||
'card_ids', 'group_by_ids',
|
||||
'filter_ids', 'default_visible')
|
||||
def _compute_report_config(self):
|
||||
for t in self:
|
||||
# 如果没有任何配置行,保留现有值(兼容旧数据)
|
||||
if not any([t.column_ids, t.card_ids, t.group_by_ids,
|
||||
t.color_rule_ids, t.filter_ids]):
|
||||
if not any([t.column_ids, t.card_ids, t.group_by_ids, t.filter_ids]):
|
||||
continue
|
||||
cfg = {}
|
||||
cols = [{'k': c.field_name, 'l': c.label or c.field_name, 'w': c.width or 120}
|
||||
@@ -88,12 +88,12 @@ class AiReportTemplate(models.Model):
|
||||
if gb:
|
||||
cfg['groupBy'] = gb
|
||||
cr = []
|
||||
for r in t.color_rule_ids:
|
||||
# 按 field_name 分组
|
||||
cr.append({
|
||||
'field': r.field_name,
|
||||
'rules': [{'op': r.op, 'value': r.value, 'color': r.color}],
|
||||
})
|
||||
for col in t.column_ids:
|
||||
for r in col.color_rule_ids:
|
||||
cr.append({
|
||||
'field': col.field_name,
|
||||
'rules': [{'op': r.op, 'value': r.value, 'color': r.color}],
|
||||
})
|
||||
if cr:
|
||||
# 合并相同 field 的规则
|
||||
merged = {}
|
||||
|
||||
@@ -24,6 +24,8 @@ class AiReportTemplateColumn(models.Model):
|
||||
help='不填则默认使用字段名')
|
||||
width = fields.Integer('列宽', default=120)
|
||||
sequence = fields.Integer('排序', default=10)
|
||||
color_rule_ids = fields.One2many('ai.report.template.color.rule', 'column_id',
|
||||
string='颜色规则')
|
||||
|
||||
@api.onchange('field_id')
|
||||
def _onchange_field_id(self):
|
||||
@@ -89,18 +91,15 @@ class AiReportTemplateGroupBy(models.Model):
|
||||
|
||||
|
||||
class AiReportTemplateColorRule(models.Model):
|
||||
"""报表模板 - 颜色规则"""
|
||||
"""报表模板 - 颜色规则(隶属于列定义)"""
|
||||
_name = 'ai.report.template.color.rule'
|
||||
_description = '颜色规则'
|
||||
_order = 'sequence, id'
|
||||
|
||||
template_id = fields.Many2one('ai.report.template', string='模板',
|
||||
column_id = fields.Many2one('ai.report.template.column', string='所属列',
|
||||
required=True, ondelete='cascade')
|
||||
model_id = fields.Many2one('ir.model', related='template_id.model_id', store=True)
|
||||
field_id = fields.Many2one('ir.model.fields', string='字段',
|
||||
domain="[('model_id', '=', model_id)]",
|
||||
help='选择要应用颜色规则的字段')
|
||||
field_name = fields.Char('字段名', required=True)
|
||||
template_id = fields.Many2one('ai.report.template', string='模板',
|
||||
compute='_compute_template_id', store=True)
|
||||
op = fields.Selection([
|
||||
('eq', '等于'),
|
||||
('>=', '大于等于'),
|
||||
@@ -116,10 +115,10 @@ class AiReportTemplateColorRule(models.Model):
|
||||
help='十六进制颜色代码,如 #E74C3C(红)、#5DCAA5(绿)、#F39C12(橙)')
|
||||
sequence = fields.Integer('排序', default=10)
|
||||
|
||||
@api.onchange('field_id')
|
||||
def _onchange_field_id(self):
|
||||
if self.field_id:
|
||||
self.field_name = self.field_id.name
|
||||
@api.depends('column_id.template_id')
|
||||
def _compute_template_id(self):
|
||||
for r in self:
|
||||
r.template_id = r.column_id.template_id if r.column_id else False
|
||||
|
||||
|
||||
class AiReportTemplateFilter(models.Model):
|
||||
|
||||
@@ -185,6 +185,16 @@
|
||||
options="{'no_create': True}"/>
|
||||
<field name="field_name" invisible="1"/>
|
||||
<field name="label" placeholder="显示名称(可选)"/>
|
||||
<field name="color_rule_ids" nolabel="1"
|
||||
placeholder="设置颜色规则...">
|
||||
<tree string="颜色规则" editable="bottom">
|
||||
<field name="template_id" column_invisible="1"/>
|
||||
<field name="op"/>
|
||||
<field name="value" placeholder="匹配值"/>
|
||||
<field name="color"/>
|
||||
<field name="sequence" widget="handle"/>
|
||||
</tree>
|
||||
</field>
|
||||
<field name="width"/>
|
||||
<field name="sequence" widget="handle"/>
|
||||
</tree>
|
||||
@@ -208,22 +218,6 @@
|
||||
</field>
|
||||
</page>
|
||||
|
||||
<page string="颜色规则" name="colors">
|
||||
<field name="color_rule_ids" nolabel="1">
|
||||
<tree string="颜色规则" editable="bottom">
|
||||
<field name="model_id" column_invisible="1"/>
|
||||
<field name="field_id"
|
||||
placeholder="选择字段..."
|
||||
options="{'no_create': True}"/>
|
||||
<field name="field_name" invisible="1"/>
|
||||
<field name="op"/>
|
||||
<field name="value" placeholder="匹配值"/>
|
||||
<field name="color"/>
|
||||
<field name="sequence" widget="handle"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
||||
<page string="AI 参数" name="params">
|
||||
<field name="param_def_ids" nolabel="1">
|
||||
<tree string="参数定义" editable="bottom">
|
||||
|
||||
Reference in New Issue
Block a user