修复返工操作时工单状态及制造订单更新程序

This commit is contained in:
jinling.yang
2024-07-15 17:34:18 +08:00
parent 7885794322
commit a0bd214118
5 changed files with 76 additions and 47 deletions

View File

@@ -2,6 +2,7 @@
import base64
import logging
import json
import os
import re
import requests
from itertools import groupby
@@ -106,11 +107,6 @@ class MrpProduction(models.Model):
elif not production.workorder_ids and float_compare(production.qty_producing, production.product_qty,
precision_rounding=production.product_uom_id.rounding) >= 0:
production.state = 'to_close'
elif any(
(wo.test_results == '返工' and wo.state == 'done') or wo.state == 'rework' or (
wo.is_rework is True and wo.state == 'done') for wo in
production.workorder_ids):
production.state = 'rework'
elif any(wo_state in ('progress', 'done') for wo_state in production.workorder_ids.mapped('state')):
production.state = 'progress'
elif production.product_uom_id and not float_is_zero(production.qty_producing,
@@ -136,6 +132,12 @@ class MrpProduction(models.Model):
if production.state == 'pending_cam':
if all(wo_state in 'done' for wo_state in production.workorder_ids.mapped('state')):
production.state = 'done'
if any(
(
wo.test_results == '返工' and wo.state == 'done' and programming_state == '编程中') or wo.state == 'rework' or (
wo.is_rework is True and wo.state == 'done') for wo in
production.workorder_ids):
production.state = 'rework'
def action_check(self):
"""
@@ -781,6 +783,18 @@ class MrpProduction(models.Model):
# 更新程序
def do_update_program(self):
program_production = self
if len(program_production) >= 1:
same_product_id = None
is_not_same_product = 0
for item in program_production:
if same_product_id is None:
same_product_id = item.product_id
if item.product_id != same_product_id:
is_not_same_product += 1
if item.state != "rework" and item.programming_state != "已编程未下发":
raise UserError("请选择状态为返工且已编程未下发的制造订单")
if is_not_same_product >= 1:
raise UserError("您选择的记录中含有其他产品的制造订单,请选择同一产品的制造订单")
grouped_program_ids = {k: list(g) for k, g in groupby(program_production, key=lambda x: x.programming_no)}
program_to_production_names = {}
for programming_no, program_production in grouped_program_ids.items():
@@ -792,7 +806,7 @@ class MrpProduction(models.Model):
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(workorder[0].processing_panel)
production.get_new_program(rework_workorder[0].processing_panel)
rework_production = self.env['mrp.production'].search(
[('state', '=', 'rework'), ('programming_no', '=', production.programming_no)])
if rework_production:
@@ -813,17 +827,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:
@@ -836,8 +850,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',
# 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:
@@ -847,8 +861,8 @@ class MrpProduction(models.Model):
panel_file_path = os.path.join(program_path_tmp_panel, file)
logging.info('panel_file_path:%s' % panel_file_path)
panel_workorder.write(
{'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel, ret),
'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, ret),
{'cnc_ids': panel_workorder.cnc_ids.sudo()._json_cnc_processing(processing_panel, result),
'cmm_ids': panel_workorder.cmm_ids.sudo()._json_cmm_program(processing_panel, result),
'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())})
pre_workorder = productions.workorder_ids.filtered(lambda
ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state != 'rework')
@@ -859,7 +873,7 @@ class MrpProduction(models.Model):
raise UserError(result['message'])
except Exception as e:
logging.info('get_new_program error:%s' % e)
raise UserError("cloud获取最新程序失败,请联系管理员")
raise UserError("云平台获取最新程序失败,请联系管理员")
class sf_detection_result(models.Model):