Merge branch 'develop' of https://e.coding.net/jikimo-hn/jikimo_sfs/jikimo_sf into feature/优化制造功能

This commit is contained in:
mgw
2024-07-25 14:05:49 +08:00
4 changed files with 68 additions and 47 deletions

View File

@@ -25,7 +25,8 @@ class Manufacturing_Connect(http.Controller):
{'content': ret, 'name': 'AutoDeviceApi/GetWoInfo'})
logging.info('RfidCode:%s' % ret['RfidCode'])
if 'RfidCode' in ret:
workorder = request.env['mrp.workorder'].sudo().search([('rfid_code', '=', ret['RfidCode'])])
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', ret['RfidCode']), ('state', '!=', 'rework')])
if workorder:
for item in workorder:
res['Datas'].append({
@@ -122,7 +123,8 @@ class Manufacturing_Connect(http.Controller):
logging.info('RfidCode:%s' % ret['RfidCode'])
if 'RfidCode' in ret:
workorder = request.env['mrp.workorder'].sudo().search(
[('routing_type', '=', '装夹预调'), ('rfid_code', '=', ret['RfidCode'])], limit=1, order='id asc')
[('routing_type', '=', '装夹预调'), ('rfid_code', '=', ret['RfidCode']), ('state', '!=', 'rework')],
limit=1, order='id asc')
if workorder:
for item in workorder:
if item.material_center_point:
@@ -163,7 +165,7 @@ class Manufacturing_Connect(http.Controller):
equipment_id = ret["DeviceId"]
workorder = request.env['mrp.workorder'].sudo().search(
[('production_id', '=', production_id), ('routing_type', '=', routing_type),
('rfid_code', '!=', False)], limit=1)
('rfid_code', '!=', False), ('state', '!=', 'rework')], limit=1)
if not workorder:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单不存在'}
return json.JSONEncoder().encode(res)
@@ -211,7 +213,7 @@ class Manufacturing_Connect(http.Controller):
routing_type = ret['CraftId']
workorder = request.env['mrp.workorder'].sudo().search(
[('production_id', '=', production_id), ('routing_type', '=', routing_type),
('rfid_code', '!=', False)], limit=1)
('rfid_code', '!=', False), ('state', '!=', 'rework')], limit=1)
if not workorder:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '该工单不存在'}
return json.JSONEncoder().encode(res)
@@ -260,7 +262,8 @@ class Manufacturing_Connect(http.Controller):
production_id = ret['BillId']
routing_type = ret['CraftId']
workorder = request.env['mrp.workorder'].sudo().search(
[('production_id', '=', production_id), ('routing_type', '=', routing_type)], limit=1)
[('production_id', '=', production_id), ('routing_type', '=', routing_type), ('state', '!=', 'rework')],
limit=1)
if workorder:
# workorder.test_results = ret['Quality']
logging.info('制造订单:%s' % workorder.production_id.name)
@@ -318,7 +321,7 @@ class Manufacturing_Connect(http.Controller):
if 'RfidCode' in ret:
logging.info('RfidCode:%s' % ret['RfidCode'])
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工')])
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')])
if workorder:
for item in workorder.cmm_ids:
if item.program_create_date is not False:
@@ -358,7 +361,7 @@ class Manufacturing_Connect(http.Controller):
if 'RfidCode' in ret:
logging.info('RfidCode:%s' % ret['RfidCode'])
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工')])
[('rfid_code', '=', ret['RfidCode']), ('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')])
if workorder:
for item in workorder.cnc_ids:
res['Datas'].append({
@@ -467,7 +470,7 @@ class Manufacturing_Connect(http.Controller):
if rfid_code is not None:
domain = [
('rfid_code', '=', rfid_code),
('routing_type', '=', 'CNC加工')
('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')
]
workorder = request.env['mrp.workorder'].sudo().search(domain, order='id asc')
if workorder:
@@ -476,7 +479,7 @@ class Manufacturing_Connect(http.Controller):
logging.info(
'工单产线状态:%s' % order.production_line_state)
panel_workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', rfid_code),
[('rfid_code', '=', rfid_code), ('state', '!=', 'rework'),
('processing_panel', '=', order.processing_panel)])
if panel_workorder:
panel_workorder.write({'production_line_state': '已上产线'})
@@ -528,7 +531,7 @@ class Manufacturing_Connect(http.Controller):
if rfid_code is not None:
domain = [
('rfid_code', '=', rfid_code),
('routing_type', '=', 'CNC加工')
('routing_type', '=', 'CNC加工'), ('state', '!=', 'rework')
]
workorder = request.env['mrp.workorder'].sudo().search(domain, order='id asc')
if workorder:
@@ -537,7 +540,7 @@ class Manufacturing_Connect(http.Controller):
logging.info(
'工单产线状态:%s' % order.production_line_state)
panel_workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', rfid_code),
[('rfid_code', '=', rfid_code), ('state', '!=', 'rework'),
('processing_panel', '=', order.processing_panel)])
if panel_workorder:
panel_workorder.write({'production_line_state': '已下产线'})

View File

@@ -734,6 +734,8 @@ class MrpProduction(models.Model):
for production in self:
logging.info('qty_produced:%s' % production.qty_produced)
if production.qty_produced == '0.0':
production.qty_produced = 1.0
production.write({
'date_finished': fields.Datetime.now(),
'product_qty': production.qty_produced,
@@ -869,35 +871,40 @@ class MrpProduction(models.Model):
productions = self.env['mrp.production'].search(
[('programming_no', '=', self.programming_no), ('state', 'not in', ('cancel', 'done'))])
if productions:
panel_workorder = productions.workorder_ids.filtered(
lambda
ac: ac.processing_panel == processing_panel and ac.routing_type == 'CNC加工' and ac.state not in (
for production in productions:
panel_workorder = production.workorder_ids.filtered(lambda
pw: pw.processing_panel == processing_panel and pw.routing_type == 'CNC加工' and pw.state not in (
'rework', 'done'))
if panel_workorder:
if panel_workorder.cnc_ids:
panel_workorder.cmm_ids.sudo().unlink()
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)
logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel)
files_panel = os.listdir(program_path_tmp_panel)
if files_panel:
for file in files_panel:
file_extension = os.path.splitext(file)[1]
if file_extension.lower() == '.pdf':
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, 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')
if pre_workorder:
pre_workorder.write(
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
if panel_workorder:
if panel_workorder.cmm_ids:
panel_workorder.cmm_ids.sudo().unlink()
if panel_workorder.cnc_ids:
panel_workorder.cnc_ids.sudo().unlink()
self.env['sf.cam.work.order.program.knife.plan'].sudo().unlink_cam_plan(
production)
# 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:
for file in files_panel:
file_extension = os.path.splitext(file)[1]
if file_extension.lower() == '.pdf':
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,
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 = production.workorder_ids.filtered(lambda
ap: ap.routing_type == '装夹预调' and ap.processing_panel == processing_panel and ap.state not in (
'rework', 'done'))
if pre_workorder:
pre_workorder.write(
{'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())})
logging.info('更新程序完成:%s' % production.name)
else:
raise UserError(result['message'])
except Exception as e:

View File

@@ -255,7 +255,7 @@ class ResMrpWorkOrder(models.Model):
sql = """
SELECT *
FROM mrp_workorder
WHERE
WHERE state!='rework'
to_char(date_planned_start::timestamp + '8 hour','YYYY-MM-DD HH:mm:SS')>= %s
AND to_char(date_planned_finished::timestamp + '8 hour','YYYY-MM-DD HH:mm:SS')<= %s
"""
@@ -753,10 +753,15 @@ class ResMrpWorkOrder(models.Model):
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']),
('test_results', '=', '返工')])
cnc_workorder_pending = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', 'CNC加工'), ('state', 'in', ['pending'])])
if workorder.state not in ['cancel', 'progress', 'rework']:
if workorder.production_id.state == 'rework':
logging.info('len(re_work):%s' % len(re_work))
logging.info('len(cnc_workorder):%s' % len(cnc_workorder))
logging.info('len(cnc_workorder_pending):%s' % len(cnc_workorder_pending))
logging.info('工序:%s' % workorder.routing_type)
logging.info('状态:%s' % workorder.state)
logging.info('is_rework:%s' % workorder.is_rework)
@@ -771,12 +776,14 @@ class ResMrpWorkOrder(models.Model):
# 新工单
if workorder.is_rework is False:
if workorder.production_id.programming_state == '已编程' and workorder.production_id.is_rework is False:
if re_work:
if re_work or cnc_workorder:
workorder.state = 'ready'
else:
if workorder.production_id.is_rework is True:
if re_work or cnc_workorder:
workorder.state = 'waiting'
if workorder.production_id.tool_state in ['1', '2'] and workorder.state != 'pending':
workorder.state = 'waiting'
elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'rework', 'cancel']:
pre_workorder = self.env['mrp.workorder'].search(
@@ -788,13 +795,15 @@ class ResMrpWorkOrder(models.Model):
workorder.state = 'waiting'
elif workorder.routing_type == '解除装夹' and workorder.state not in ['done', 'rework', 'cancel']:
if cnc_workorder:
workorder.state = 'waiting'
if not cnc_workorder_pending:
workorder.state = 'waiting'
# else:
# if workorder.production_id.is_rework is True:
# workorder.state = 'waiting'
elif workorder.production_id.state == 'progress':
logging.info('len(re_work):%s' % len(re_work))
logging.info('len(cnc_workorder):%s' % len(cnc_workorder))
logging.info('len(cnc_workorder_pending):%s' % len(cnc_workorder_pending))
logging.info('工序:%s' % workorder.routing_type)
logging.info('状态:%s' % workorder.state)
logging.info('is_rework:%s' % workorder.is_rework)
@@ -806,7 +815,7 @@ class ResMrpWorkOrder(models.Model):
workorder.is_rework is False and workorder.state not in [
'done', 'rework',
'cancel']:
if re_work and workorder.production_id.is_rework is False:
if (re_work or cnc_workorder) and workorder.production_id.is_rework is False:
workorder.state = 'ready'
if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']:
unclamp_workorder = self.env['mrp.workorder'].search(
@@ -815,9 +824,11 @@ class ResMrpWorkOrder(models.Model):
('state', 'in', ['done'])])
if unclamp_workorder:
workorder.state = 'ready'
# else:
# if workorder.state not in ['cancel', 'rework']:
# workorder.state = 'rework'
logging.info('工序:%s' % workorder.sequence)
logging.info('工单最终状态:%s' % workorder.state)
# else:
# if workorder.state not in ['cancel', 'rework']:
# workorder.state = 'rework'
# elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'cancel', 'progress',
# 'rework']:
# per_work = self.env['mrp.workorder'].search(

View File

@@ -165,7 +165,7 @@
<!-- groups="sf_base.group_sf_mrp_user" -->
<!-- attrs="{'invisible': ['|', '|', ('production_state', 'in', ('draft', 'done', 'cancel')), ('working_state', '!=', 'blocked'),('state','=','done')]}"/> -->
<button name="button_workpiece_delivery" type="object" string="工件配送" class="btn-primary"
attrs="{'invisible': ['|','|','|',('routing_type','!=','装夹预调'),('is_delivery','=',True),('state','!=','done'),('is_rework','=',True),('rfid_code','in',['',False])]}"/>
attrs="{'invisible': ['|','|','|','|',('routing_type','!=','装夹预调'),('is_delivery','=',True),('state','!=','done'),('is_rework','=',True),'&amp;',('rfid_code','in',['',False]),('state','=','done')]}"/>
<button name="button_rework_pre" type="object" string="返工"
class="btn-primary"
attrs="{'invisible': ['|','|',('routing_type','!=','装夹预调'),('state','!=','progress'),('is_rework','=',True)]}"/>