调整报告公开可访问
This commit is contained in:
@@ -89,4 +89,26 @@ class QualityController(http.Controller):
|
||||
('Access-Control-Allow-Methods', 'GET, OPTIONS'),
|
||||
('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):
|
||||
"""提供公开访问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内容
|
||||
return request.make_response(
|
||||
pdf_content,
|
||||
headers=[
|
||||
('Content-Type', 'application/pdf'),
|
||||
('Content-Disposition', f'inline; filename={attachment.name}')
|
||||
]
|
||||
)
|
||||
return request.not_found()
|
||||
@@ -445,10 +445,10 @@ class QualityCheck(models.Model):
|
||||
('name', 'like', 'QC-QC') # 根据您的命名规则调整
|
||||
], order='create_date DESC') # 按创建日期降序排序
|
||||
|
||||
# 如果附件数量大于1,则删除除最新报告外的其他报告附件
|
||||
if len(attachments) > 1:
|
||||
for attachment in attachments[1:]:
|
||||
attachment.unlink()
|
||||
# # 如果附件数量大于1,则删除除最新报告外的其他报告附件
|
||||
# if len(attachments) > 1:
|
||||
# for attachment in attachments[1:]:
|
||||
# attachment.unlink()
|
||||
|
||||
# 返回最新的附件(如果存在)
|
||||
return attachments and attachments[0] or False
|
||||
@@ -462,8 +462,8 @@ class QualityCheck(models.Model):
|
||||
latest_attachment = self.get_latest_report_attachment(self.id)
|
||||
if latest_attachment:
|
||||
# 生成包含附件ID的URL
|
||||
print(f"{report_url}/{latest_attachment.id}/datas")
|
||||
return f"{report_url}/{latest_attachment.id}/datas"
|
||||
print(f"{base_url}/quality/report/{latest_attachment.id}")
|
||||
return f"{base_url}/quality/report/{latest_attachment.id}"
|
||||
return False
|
||||
|
||||
def upload_factory_report(self):
|
||||
|
||||
Reference in New Issue
Block a user