修改报告二维码指向

This commit is contained in:
mgw
2025-03-25 13:26:12 +08:00
parent 29f143a547
commit 4dfac9e96f
2 changed files with 64 additions and 76 deletions

View File

@@ -90,25 +90,25 @@ class QualityController(http.Controller):
('Access-Control-Allow-Headers', 'Content-Type, Authorization')
]
)
class QualityReportController(http.Controller):
@http.route('/quality/report/<int:attachment_id>', type='http', auth='public')
def get_public_report(self, attachment_id, **kw):
@http.route('/quality/report/<int:document_id>', type='http', auth='public')
def get_public_report(self, document_id, **kw):
"""提供公开访问PDF报告的控制器"""
attachment = request.env['ir.attachment'].sudo().browse(int(attachment_id))
# 安全检查:确保只有质检报告附件可以被访问
if attachment.exists() and 'QC-' in attachment.name:
# 解码Base64数据为二进制数据
pdf_content = base64.b64decode(attachment.datas)
# 返回解码后的PDF内容
document = request.env['documents.document'].sudo().browse(int(document_id))
# 安全检查:确保只有质检报告文档可以被访问
if document.exists() and document.res_model == 'quality.check':
# 获取PDF内容
pdf_content = document.raw
# 返回PDF内容
return request.make_response(
pdf_content,
headers=[
('Content-Type', 'application/pdf'),
('Content-Disposition', f'inline; filename={attachment.name}')
('Content-Disposition', f'inline; filename={document.name}.pdf')
]
)
return request.not_found()
return request.not_found()