Files
gzth/yuthon_notice/controllers/excel_report_designer.py
T
2025-04-21 20:30:33 +08:00

60 lines
2.5 KiB
Python

# -*- coding: utf-8 -*-
################################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2024-TODAY Cybrosys Technologies (<https://www.cybrosys.com>).
# Author: Cybrosys Techno Solutions (<https://www.cybrosys.com>)
#
# This program is free software: you can modify
# it under the terms of the GNU Affero General Public License (AGPL) as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
################################################################################
import json
from odoo import http
from odoo.http import content_disposition, request
from odoo.tools import html_escape
class ReportPrintController(http.Controller):
@http.route('/print_notice_report', type='http', auth='user')
def print_notice_report(self):
"""
控制器方法,用于触发打印通知公告报表
"""
# 获取 report.generator 模型的对象(假设存在该模型)
report_generator = request.env['report.generator'].sudo().create({})
# 调用 print_fixed_report 方法
action = report_generator.print_fixed_report()
# 提取报表数据
report_data = action.get('data', {})
options = json.loads(report_data.get('options', '{}'))
report_model_name = report_data.get('model')
output_format = report_data.get('output_format')
report_name = report_data.get('report_name')
# 获取报表模型
report_model = request.env[report_model_name]
# 创建响应对象
response = request.make_response(
None,
headers=[
('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' if output_format == 'xlsx' else 'application/pdf'),
('Content-Disposition', f'attachment; filename="{report_name}.{output_format}"')
]
)
# 调用报表模型的生成报表方法
if hasattr(report_model, 'get_xlsx_report'):
report_model.get_xlsx_report(options, response)
return response