修复返工bug

This commit is contained in:
jinling.yang
2024-07-18 16:17:19 +08:00
parent 7163e025d2
commit 33bf88968c
5 changed files with 75 additions and 41 deletions

View File

@@ -136,7 +136,8 @@ class MrpProduction(models.Model):
# production.state = 'done'
if any(
(
wo.test_results == '返工' and wo.state == 'done' and production.programming_state == '已编程') or (
wo.test_results == '返工' and wo.state == 'done' and production.programming_state in [
'已编程', '已下发']) or (
wo.state == 'rework' and production.programming_state == '编程中') or (
wo.is_rework is True and wo.state == 'done' and production.programming_state in ['编程中',
'已编程'])
@@ -203,7 +204,7 @@ class MrpProduction(models.Model):
production.write({'programming_state': '已编程未下发' if item[
'programming_state'] == '已编程' else '编程中'})
else:
return item['programming_state']
return item
else:
raise UserError(ret['message'])
@@ -744,10 +745,12 @@ class MrpProduction(models.Model):
# 返工
def button_rework(self):
cloud_programming_state = None
if self.programming_state != '已编程' and self.reprogramming_num >= 1:
cloud_programming_state = self._cron_get_programming_state()
logging.info('cloud_programming_state:%s' % cloud_programming_state)
cloud_programming = None
if self.programming_state == '已编程' and self.reprogramming_num >= 0:
cloud_programming = self._cron_get_programming_state()
if self.reprogramming_num == 0:
self.reprogramming_num = cloud_programming['reprogramming_num']
logging.info('cloud_programming_state:%s' % cloud_programming['programming_state'])
logging.info('programming_state:%s' % self.programming_state)
return {
'name': _('返工'),
@@ -757,12 +760,14 @@ class MrpProduction(models.Model):
'target': 'new',
'context': {
'default_production_id': self.id,
'default_product_id': self.product_id.id,
'default_programming_state': self.programming_state if cloud_programming_state is not None else cloud_programming_state,
'default_is_reprogramming': False if (cloud_programming_state in ['编程中',
'待编程'] and self.programming_state in [
'default_reprogramming_num': self.reprogramming_num,
'default_programming_state': self.programming_state if cloud_programming[
'programming_state'] is None else
cloud_programming['programming_state'],
'default_is_reprogramming': False if (cloud_programming['programming_state'] in ['编程中',
'待编程'] and self.programming_state in [
'编程中'])
or (cloud_programming_state in [
or (cloud_programming['programming_state'] in [
'已编程'] and self.programming_state in ['已编程未下发']) else True
}
}
@@ -790,11 +795,13 @@ class MrpProduction(models.Model):
if production.programming_no in program_to_production_names:
rework_workorder = production.workorder_ids.filtered(lambda m: m.state == 'rework')
if rework_workorder:
new_pancel_workorder = production.workorder_ids.filtered(
lambda m1: m1.state != 'rework' and m1.processing_panel == rework_workorder[0].processing_panel)
if not new_pancel_workorder.cnc_ids:
production.get_new_program(rework_workorder[0].processing_panel)
production.write({'state': 'progress', 'programming_state': '已下发'})
for rework_item in rework_workorder:
pending_workorder = production.workorder_ids.filtered(
lambda m1: m1.state in [
'pending'] and m1.processing_panel == rework_item.processing_panel and m1.routing_type == 'CNC加工')
if not pending_workorder.cnc_ids:
production.get_new_program(rework_item.processing_panel)
production.write({'state': 'progress', 'programming_state': '已编程'})
# 从cloud获取重新编程过的最新程序
def get_new_program(self, processing_panel):
@@ -808,17 +815,17 @@ class MrpProduction(models.Model):
r = r.json()
result = json.loads(r['result'])
if result['status'] == 1:
program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel)
if os.path.exists(program_path_tmp_panel):
files_r = os.listdir(program_path_tmp_panel)
if files_r:
for file_name in files_r:
file_path = os.path.join(program_path_tmp_panel, file_name)
os.remove(file_path)
download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'],
processing_panel)
if download_state is False:
raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no))
# program_path_tmp_panel = os.path.join('/tmp', result['folder_name'], 'return', processing_panel)
# if os.path.exists(program_path_tmp_panel):
# files_r = os.listdir(program_path_tmp_panel)
# if files_r:
# for file_name in files_r:
# file_path = os.path.join(program_path_tmp_panel, file_name)
# os.remove(file_path)
# download_state = self.env['sf.cnc.processing'].download_file_tmp(result['folder_name'],
# processing_panel)
# if download_state is False:
# raise UserError('编程单号为%s的CNC程序文件从FTP拉取失败' % (self.programming_no))
productions = self.env['mrp.production'].search(
[('programming_no', '=', self.programming_no), ('state', 'not in', ['cancel,done'])])
if productions:
@@ -831,8 +838,8 @@ class MrpProduction(models.Model):
panel_workorder.cnc_ids.sudo().unlink()
self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(
productions)
# program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
# processing_panel)
program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test',
processing_panel)
logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
files_panel = os.listdir(program_path_tmp_panel)
if files_panel:
@@ -985,7 +992,6 @@ class MrpProduction(models.Model):
return production_values_str
class sf_detection_result(models.Model):
_name = 'sf.detection.result'
_description = "检测结果"