库位变更接口优化

This commit is contained in:
mgw
2024-04-24 08:58:15 +08:00
parent ca01b055b8
commit 59c8631c15
6 changed files with 77 additions and 31 deletions

View File

@@ -65,6 +65,7 @@ class Manufacturing_Connect(http.Controller):
else:
ProductionLine = False
workorder_ids = request.env['mrp.workorder'].sudo().get_plan_workorder(ProductionLine)
# todo 需要筛选出CNC工单
logging.info('RfidCode:%s' % ret)
logging.info('workorder_ids:%s' % workorder_ids)
workorder = request.env['mrp.workorder'].sudo().search(workorder_ids)
@@ -377,37 +378,75 @@ class Manufacturing_Connect(http.Controller):
NewPosition = ret['NewPosition']
OldDeciveStart = ret['OldDeciveStart']
OldDeciveEnd = ret['OldDeciveEnd']
temp_val_sn_id = None
old_localtion = None
# Part、Tool
if ChangeType == 'Part':
workorder = request.env['mrp.workorder'].sudo().search(
[('rfid_code', '=', RfidCode)], limit=1)
if not workorder:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未根据RfidCode找到该工单'}
# if ChangeType == 'Part':
# workorder = request.env['mrp.workorder'].sudo().search(
# [('rfid_code', '=', RfidCode)], limit=1)
# if not workorder:
# res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未根据RfidCode找到该工单'}
# return json.JSONEncoder().encode(res)
# old_localtion = request.env['sf.shelf.location'].sudo().search(
# [('barcode', '=', OldPosition)], limit=1)
# new_localtion = request.env['sf.shelf.location'].sudo().search(
# [('barcode', '=', NewPosition)], limit=1)
# if not new_localtion:
# res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'}
# return json.JSONEncoder().encode(res)
# if old_localtion:
# old_localtion.location_status = '空闲'
# old_localtion.production_id = False
# new_localtion.location_status = '占用'
# new_localtion.production_id = workorder.production_id.id
# if ChangeType == 'Tool':
# old_localtion = request.env['sf.shelf.location'].sudo().search(
# [('barcode', '=', OldPosition)], limit=1)
# equipment_id = request.env['maintenance.equipment'].sudo().search(
# [('name', '=', NewPosition)], limit=1)
# equipment_id.register_equipment_tool()
# if not equipment_id:
# res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'}
# return json.JSONEncoder().encode(res)
# if old_localtion:
# old_localtion.location_status = '空闲'
# old_localtion.production_id = False
#
# # return json.JSONEncoder().encode(res)
# # else:
# # res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传RfidCode字段'}
if ChangeType == 'Part' or ChangeType == 'Tool':
stock_lot_obj = request.env['stock.lot'].sudo().search(
[('rfid', '=', RfidCode)], limit=1)
if not stock_lot_obj:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未根据RfidCode找到该产品'}
return json.JSONEncoder().encode(res)
old_localtion = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', OldPosition)], limit=1)
if OldPosition:
old_localtion = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', OldPosition)], limit=1)
new_localtion = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', NewPosition)], limit=1)
if not new_localtion:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'}
return json.JSONEncoder().encode(res)
if old_localtion:
old_localtion.location_status = '空闲'
old_localtion.production_id = False
new_localtion.location_status = '占用'
new_localtion.production_id = workorder.production_id.id
if ChangeType == 'Tool':
old_localtion = request.env['sf.shelf.location'].sudo().search(
[('barcode', '=', OldPosition)], limit=1)
equipment_id = request.env['maintenance.equipment'].sudo().search(
[('name', '=', NewPosition)], limit=1)
equipment_id.register_equipment_tool()
if not equipment_id:
res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'}
return json.JSONEncoder().encode(res)
if old_localtion:
old_localtion.location_status = '空闲'
old_localtion.production_id = False
temp_val_sn_id = old_localtion.product_sn_id
old_localtion.product_sn_id = None
new_localtion.product_sn_id = temp_val_sn_id
else:
new_localtion.product_sn_id = stock_lot_obj.id
# if ChangeType == 'Tool':
# old_localtion = request.env['sf.shelf.location'].sudo().search(
# [('barcode', '=', OldPosition)], limit=1)
# equipment_id = request.env['maintenance.equipment'].sudo().search(
# [('name', '=', NewPosition)], limit=1)
# equipment_id.register_equipment_tool()
# if not equipment_id:
# res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'}
# return json.JSONEncoder().encode(res)
# if old_localtion:
# old_localtion.product_sn_id = None
# return json.JSONEncoder().encode(res)
# else: