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