完善出厂报告需求功能
This commit is contained in:
@@ -211,6 +211,9 @@ class QualityCheck(models.Model):
|
|||||||
('canceled', '已撤销')
|
('canceled', '已撤销')
|
||||||
], string='发布状态', default='draft')
|
], string='发布状态', default='draft')
|
||||||
|
|
||||||
|
# 出厂检验报告是否已上传
|
||||||
|
is_factory_report_uploaded = fields.Boolean(string='出厂检验报告是否已上传', default=False)
|
||||||
|
|
||||||
def add_measure_line(self):
|
def add_measure_line(self):
|
||||||
"""
|
"""
|
||||||
新增测量值,如果测量值有5列了,则提示“最多只能有5列测量值”
|
新增测量值,如果测量值有5列了,则提示“最多只能有5列测量值”
|
||||||
@@ -316,7 +319,6 @@ class QualityCheck(models.Model):
|
|||||||
# 关联到当前质检记录
|
# 关联到当前质检记录
|
||||||
self.write({
|
self.write({
|
||||||
'report_number_id': doc.id,
|
'report_number_id': doc.id,
|
||||||
'publish_status': 'published',
|
|
||||||
'quality_state': 'pass'
|
'quality_state': 'pass'
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -335,6 +337,13 @@ class QualityCheck(models.Model):
|
|||||||
self.serial_number += 1
|
self.serial_number += 1
|
||||||
self.quality_manager = self.env.user.id
|
self.quality_manager = self.env.user.id
|
||||||
|
|
||||||
|
if self.publish_status == 'canceled':
|
||||||
|
self.upload_factory_report()
|
||||||
|
|
||||||
|
self.write({
|
||||||
|
'publish_status': 'published',
|
||||||
|
})
|
||||||
|
|
||||||
# 返回成功消息
|
# 返回成功消息
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -404,6 +413,10 @@ class QualityCheck(models.Model):
|
|||||||
'report_number_id': False,
|
'report_number_id': False,
|
||||||
'quality_state': 'none'
|
'quality_state': 'none'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# 4. 删除加工订单明细中的出厂检验报告
|
||||||
|
self.delete_factory_report()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def do_re_publish(self):
|
def do_re_publish(self):
|
||||||
@@ -499,6 +512,7 @@ class QualityCheck(models.Model):
|
|||||||
result = response.json()
|
result = response.json()
|
||||||
if result.get('success'):
|
if result.get('success'):
|
||||||
# 上传成功,显示成功消息
|
# 上传成功,显示成功消息
|
||||||
|
self.is_factory_report_uploaded = True
|
||||||
return {
|
return {
|
||||||
'type': 'ir.actions.client',
|
'type': 'ir.actions.client',
|
||||||
'tag': 'display_notification',
|
'tag': 'display_notification',
|
||||||
@@ -518,6 +532,62 @@ class QualityCheck(models.Model):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise UserError(_('上传过程中发生错误: %s') % str(e))
|
raise UserError(_('上传过程中发生错误: %s') % str(e))
|
||||||
|
|
||||||
|
def delete_factory_report(self):
|
||||||
|
"""
|
||||||
|
删除加工订单明细中的出厂检验报告
|
||||||
|
"""
|
||||||
|
# 获取订单号(从调拨单的来源字段获取)
|
||||||
|
order_ref = self.picking_id.retrospect_ref
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 准备请求数据
|
||||||
|
payload = {
|
||||||
|
"order_ref": order_ref,
|
||||||
|
"part_number": self.part_number
|
||||||
|
}
|
||||||
|
|
||||||
|
# 将Python字典转换为JSON字符串
|
||||||
|
json_data = json.dumps(payload)
|
||||||
|
|
||||||
|
# 获取服务器URL
|
||||||
|
base_url = self.env['ir.config_parameter'].sudo().get_param('bfm_url_new')
|
||||||
|
api_url = f"{base_url}/api/report/delete"
|
||||||
|
|
||||||
|
# 设置请求头
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
# 发送POST请求
|
||||||
|
response = requests.post(api_url, data=json_data, headers=headers)
|
||||||
|
|
||||||
|
# 处理响应
|
||||||
|
if response.status_code == 200:
|
||||||
|
result = response.json()
|
||||||
|
if result.get('success'):
|
||||||
|
# 删除成功,显示成功消息
|
||||||
|
self.is_factory_report_uploaded = False
|
||||||
|
return {
|
||||||
|
'type': 'ir.actions.client',
|
||||||
|
'tag': 'display_notification',
|
||||||
|
'params': {
|
||||||
|
'title': _('删除成功'),
|
||||||
|
'message': _('出厂检验报告已成功删除'),
|
||||||
|
'type': 'success',
|
||||||
|
'sticky': False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# API返回失败信息
|
||||||
|
raise UserError(_('删除失败: %s') % result.get('message', '未知错误'))
|
||||||
|
else:
|
||||||
|
# HTTP请求失败
|
||||||
|
raise UserError(_('请求失败,状态码: %s') % response.status_code)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
raise UserError(_('删除过程中发生错误: %s') % str(e))
|
||||||
|
|
||||||
|
|
||||||
@depends('product_id')
|
@depends('product_id')
|
||||||
def _compute_material_name(self):
|
def _compute_material_name(self):
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ class StockPicking(models.Model):
|
|||||||
# }
|
# }
|
||||||
|
|
||||||
out_quality_check = self.env['quality.check'].search([('picking_id', '=', self.id), ('test_type_id.name', '=', '出厂检验报告')])
|
out_quality_check = self.env['quality.check'].search([('picking_id', '=', self.id), ('test_type_id.name', '=', '出厂检验报告')])
|
||||||
|
if not out_quality_check.is_factory_report_uploaded:
|
||||||
out_quality_check.upload_factory_report()
|
if out_quality_check and self.state == 'assigned':
|
||||||
|
out_quality_check.upload_factory_report()
|
||||||
|
|
||||||
return super(StockPicking, self).button_validate()
|
return super(StockPicking, self).button_validate()
|
||||||
|
|||||||
Reference in New Issue
Block a user