修改报告二维码指向
This commit is contained in:
@@ -91,24 +91,24 @@ class QualityController(http.Controller):
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
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))
|
||||
document = request.env['documents.document'].sudo().browse(int(document_id))
|
||||
|
||||
# 安全检查:确保只有质检报告附件可以被访问
|
||||
if attachment.exists() and 'QC-' in attachment.name:
|
||||
# 解码Base64数据为二进制数据
|
||||
pdf_content = base64.b64decode(attachment.datas)
|
||||
# 安全检查:确保只有质检报告文档可以被访问
|
||||
if document.exists() and document.res_model == 'quality.check':
|
||||
# 获取PDF内容
|
||||
pdf_content = document.raw
|
||||
|
||||
# 返回解码后的PDF内容
|
||||
# 返回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()
|
||||
@@ -183,10 +183,12 @@ class QualityCheck(models.Model):
|
||||
report_number_name = fields.Char('出厂检验报告编号名称', compute='_compute_report_number_name')
|
||||
|
||||
old_report_name = fields.Char('旧出厂检验报告编号', default='')
|
||||
|
||||
@api.depends('serial_number', 'part_number')
|
||||
def _compute_report_number_name(self):
|
||||
for record in self:
|
||||
str_serial_number = '0' + str(record.serial_number) if record.serial_number < 10 else str(record.serial_number)
|
||||
str_serial_number = '0' + str(record.serial_number) if record.serial_number < 10 else str(
|
||||
record.serial_number)
|
||||
str_part_number = record.part_number if record.part_number else ''
|
||||
record.report_number_name = f'FQC{str_part_number}{str_serial_number}'
|
||||
|
||||
@@ -284,25 +286,7 @@ class QualityCheck(models.Model):
|
||||
"""实际执行发布操作的方法"""
|
||||
self.ensure_one()
|
||||
|
||||
# 1. 获取报告动作
|
||||
report_action = self.env.ref('sf_quality.action_report_quality_inspection')
|
||||
|
||||
# 2. 生成PDF报告 - 修改这里的调用方式
|
||||
pdf_content, _ = report_action._render_qweb_pdf(
|
||||
report_ref=report_action.report_name, # 添加report_ref参数
|
||||
res_ids=self.ids
|
||||
)
|
||||
|
||||
# attachment = self.env['ir.attachment'].create({
|
||||
# 'name': f'{self.name}.pdf',
|
||||
# 'type': 'binary',
|
||||
# 'datas': b64encode(pdf_content),
|
||||
# 'res_model': self._name,
|
||||
# 'res_id': self.id,
|
||||
# 'mimetype': 'application/pdf',
|
||||
# })
|
||||
|
||||
# 获取已发布的文档文件夹
|
||||
# 1. 获取已发布的文档文件夹
|
||||
workspace = self.env['documents.folder'].search(
|
||||
[('parent_folder_id', '=', self.env.ref('sf_quality.documents_purchase_contracts_folder').id),
|
||||
('name', '=', '已发布')], limit=1)
|
||||
@@ -310,11 +294,9 @@ class QualityCheck(models.Model):
|
||||
if self.serial_number > 99:
|
||||
raise UserError(_('流水号不能大于99'))
|
||||
|
||||
# 3. 创建文档记录
|
||||
# 2. 先创建空文档记录
|
||||
doc_vals = {
|
||||
'name': self.report_number_name,
|
||||
'raw': pdf_content,
|
||||
# 'attachment_id': attachment.id,
|
||||
'mimetype': 'application/pdf',
|
||||
'res_id': self.id,
|
||||
'folder_id': workspace.id,
|
||||
@@ -322,13 +304,26 @@ class QualityCheck(models.Model):
|
||||
}
|
||||
|
||||
doc = self.env['documents.document'].create(doc_vals)
|
||||
# 关联到当前质检记录
|
||||
|
||||
# 3. 关联文档到质检记录
|
||||
self.write({
|
||||
'report_number_id': doc.id,
|
||||
'quality_state': 'pass'
|
||||
})
|
||||
|
||||
# 记录发布历史
|
||||
# 4. 获取报告动作并生成PDF(此时二维码将包含正确的文档ID)
|
||||
report_action = self.env.ref('sf_quality.action_report_quality_inspection')
|
||||
pdf_content, _ = report_action._render_qweb_pdf(
|
||||
report_ref=report_action.report_name,
|
||||
res_ids=self.ids
|
||||
)
|
||||
|
||||
# 5. 更新文档内容
|
||||
doc.write({
|
||||
'raw': pdf_content
|
||||
})
|
||||
|
||||
# 6. 记录发布历史
|
||||
self.env['quality.check.report.history'].create({
|
||||
'check_id': self.id,
|
||||
'report_number_id': doc.id,
|
||||
@@ -339,7 +334,7 @@ class QualityCheck(models.Model):
|
||||
'sequence': len(self.report_history_ids) + 1
|
||||
})
|
||||
|
||||
# 更新流水号
|
||||
# 7. 更新其他信息
|
||||
self.serial_number += 1
|
||||
self.quality_manager = self.env.user.id
|
||||
|
||||
@@ -350,7 +345,6 @@ class QualityCheck(models.Model):
|
||||
'publish_status': 'published',
|
||||
})
|
||||
|
||||
# 返回成功消息
|
||||
return True
|
||||
|
||||
# 发布前检验零件图号、操机员、质检员
|
||||
@@ -461,16 +455,10 @@ class QualityCheck(models.Model):
|
||||
return attachments and attachments[0] or False
|
||||
|
||||
def get_report_url(self):
|
||||
"""生成报告访问URL,确保获取最新版本"""
|
||||
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||
report_url = f"{base_url}/web/content/ir.attachment"
|
||||
|
||||
# 获取最新附件的ID
|
||||
latest_attachment = self.get_latest_report_attachment(self.id)
|
||||
if latest_attachment:
|
||||
# 生成包含附件ID的URL
|
||||
print(f"{base_url}/quality/report/{latest_attachment.id}")
|
||||
return f"{base_url}/quality/report/{latest_attachment.id}"
|
||||
"""生成报告访问URL"""
|
||||
self.ensure_one()
|
||||
if self.report_number_id:
|
||||
return f'/quality/report/{self.report_number_id.id}'
|
||||
return False
|
||||
|
||||
def upload_factory_report(self):
|
||||
@@ -496,7 +484,8 @@ class QualityCheck(models.Model):
|
||||
payload = {
|
||||
"order_ref": order_ref,
|
||||
"model_name": self.product_id.model_name,
|
||||
"report_file": self.report_content.decode('utf-8') if isinstance(self.report_content, bytes) else self.report_content
|
||||
"report_file": self.report_content.decode('utf-8') if isinstance(self.report_content,
|
||||
bytes) else self.report_content
|
||||
}
|
||||
|
||||
# 将Python字典转换为JSON字符串
|
||||
@@ -601,7 +590,6 @@ class QualityCheck(models.Model):
|
||||
except Exception as e:
|
||||
raise UserError(_('删除过程中发生错误: %s') % str(e))
|
||||
|
||||
|
||||
@depends('product_id')
|
||||
def _compute_material_name(self):
|
||||
for record in self:
|
||||
|
||||
Reference in New Issue
Block a user