diff --git a/quality_control/models/quality.py b/quality_control/models/quality.py
index 01ffe3fd..e7ad73ba 100644
--- a/quality_control/models/quality.py
+++ b/quality_control/models/quality.py
@@ -419,6 +419,36 @@ class QualityCheck(models.Model):
width=140, height=140)
)
)
+
+ def get_latest_report_attachment(self, check_id):
+ """获取指定质检记录的最新报告附件,并删除旧的报告附件"""
+ # 查找特定质检记录的所有附件
+ attachments = self.env['ir.attachment'].search([
+ ('res_model', '=', 'quality.check'),
+ ('res_id', '=', check_id),
+ ('name', 'like', 'QC-QC') # 根据您的命名规则调整
+ ], order='create_date DESC') # 按创建日期降序排序
+
+ # 如果附件数量大于1,则删除除最新报告外的其他报告附件
+ if len(attachments) > 1:
+ for attachment in attachments[1:]:
+ attachment.unlink()
+
+ # 返回最新的附件(如果存在)
+ 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"{report_url}/{latest_attachment.id}/datas")
+ return f"{report_url}/{latest_attachment.id}/datas"
+ return False
@depends('product_id')
def _compute_material_name(self):
diff --git a/sf_quality/data/report_actions.xml b/sf_quality/data/report_actions.xml
index b65a4b55..7ee44f63 100644
--- a/sf_quality/data/report_actions.xml
+++ b/sf_quality/data/report_actions.xml
@@ -9,7 +9,8 @@
'QC-' + object.name + '.pdf'
report
- False
+ 'QC-'+object.name+'-'+str(object.write_date)+'.pdf'
+ True