调整发布业务逻辑
This commit is contained in:
@@ -233,6 +233,7 @@ class QualityCheck(models.Model):
|
||||
def do_publish(self):
|
||||
"""发布出厂检验报告"""
|
||||
self.ensure_one()
|
||||
self._check_part_number()
|
||||
# self._check_measure_line()
|
||||
# self._check_check_qty_and_total_qty()
|
||||
|
||||
@@ -266,14 +267,14 @@ class QualityCheck(models.Model):
|
||||
res_ids=self.ids
|
||||
)
|
||||
|
||||
attachment = self.env['ir.attachment'].create({
|
||||
'name': self.name,
|
||||
'type': 'binary',
|
||||
'datas': pdf_content,
|
||||
'res_model': self._name,
|
||||
'res_id': self.id,
|
||||
'mimetype': 'application/pdf',
|
||||
})
|
||||
# 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',
|
||||
# })
|
||||
|
||||
# 获取已发布的文档文件夹
|
||||
workspace = self.env['documents.folder'].search(
|
||||
@@ -288,9 +289,9 @@ class QualityCheck(models.Model):
|
||||
# 3. 创建文档记录
|
||||
doc_vals = {
|
||||
'name': f'FQC{str_part_number}{str_serial_number}',
|
||||
# 'raw': pdf_content,
|
||||
'attachment_id': attachment.id,
|
||||
# 'mimetype': 'application/pdf',
|
||||
'raw': pdf_content,
|
||||
# 'attachment_id': attachment.id,
|
||||
'mimetype': 'application/pdf',
|
||||
'res_id': self.id,
|
||||
'folder_id': workspace.id,
|
||||
'res_model': self._name,
|
||||
@@ -320,6 +321,13 @@ class QualityCheck(models.Model):
|
||||
# 返回成功消息
|
||||
return True
|
||||
|
||||
# 发布前检验零件图号、操机员、质检员
|
||||
def _check_part_number(self):
|
||||
if not self.part_number:
|
||||
raise UserError(_('零件图号不能为空'))
|
||||
if not self.measure_operator:
|
||||
raise UserError(_('操机员不能为空'))
|
||||
|
||||
# 发布前校验明细行列均非空
|
||||
def _check_measure_line(self):
|
||||
for record in self:
|
||||
@@ -357,8 +365,7 @@ class QualityCheck(models.Model):
|
||||
self.report_number_id.write({
|
||||
'folder_id': self.env.ref('sf_quality.documents_purchase_contracts_folder_canceled').id,
|
||||
})
|
||||
# 3. 更新发布状态
|
||||
self.publish_status = 'canceled'
|
||||
|
||||
# 3. 记录发布历史
|
||||
self.env['quality.check.report.history'].create({
|
||||
'check_id': self.id,
|
||||
@@ -369,6 +376,12 @@ class QualityCheck(models.Model):
|
||||
'document_status': 'canceled',
|
||||
'sequence': len(self.report_history_ids) + 1
|
||||
})
|
||||
|
||||
# 3. 更新发布状态
|
||||
self.write({
|
||||
'publish_status': 'canceled',
|
||||
'report_number_id': False
|
||||
})
|
||||
return True
|
||||
|
||||
def do_re_publish(self):
|
||||
|
||||
Reference in New Issue
Block a user