库位变更接口优化

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

View File

@@ -113,7 +113,8 @@ class MrpProduction(models.Model):
if production.state == 'progress' and production.schedule_state == '已排': if production.state == 'progress' and production.schedule_state == '已排':
# production.state = 'pending_processing' # production.state = 'pending_processing'
production.state = 'pending_cam' production.state = 'pending_cam'
elif production.state == 'pending_cam' and production.process_state == '待加工': if production.state == 'progress' and production.schedule_state == '已排' and production.process_state == '待加工':
# if production.state == 'pending_cam' and production.process_state == '待加工':
production.state = 'pending_processing' production.state = 'pending_processing'
elif production.state == 'pending_processing' and production.process_state == '待解除装夹': elif production.state == 'pending_processing' and production.process_state == '待解除装夹':
production.state = 'pending_era_cam' production.state = 'pending_era_cam'

View File

@@ -406,9 +406,10 @@ class ResMrpWorkOrder(models.Model):
work = workorder.production_id.workorder_ids work = workorder.production_id.workorder_ids
work.compensation_value_x = eval(self.material_center_point)[0] work.compensation_value_x = eval(self.material_center_point)[0]
work.compensation_value_y = eval(self.material_center_point)[1] work.compensation_value_y = eval(self.material_center_point)[1]
work.process_state = '待加工'
self.sudo().production_id.state = 'pending_processing'
workorder.button_finish() workorder.button_finish()
self.process_state = '待加工'
# self.sudo().production_id.state = 'pending_processing'
except Exception as e: except Exception as e:
# 重新抛出捕获到的异常信息 # 重新抛出捕获到的异常信息
raise UserError(str(e)) raise UserError(str(e))

View File

@@ -70,6 +70,7 @@
<xpath expr="//sheet//group//group[2]//label" position="before"> <xpath expr="//sheet//group//group[2]//label" position="before">
<!-- <field name="process_state"/> --> <!-- <field name="process_state"/> -->
<field name="state"/> <field name="state"/>
<field name="process_state"/>
</xpath> </xpath>
<xpath expr="//sheet//group//group//div[3]" position="after"> <xpath expr="//sheet//group//group//div[3]" position="after">

View File

@@ -294,10 +294,10 @@ class sf_production_plan(models.Model):
print('时间设置失败,请检查是否为工序分配工作中心,%s' % e) print('时间设置失败,请检查是否为工序分配工作中心,%s' % e)
def cancel_production_schedule(self): def cancel_production_schedule(self):
self.date_planned_start = False self.date_planned_start = None
self.date_planned_finished = False self.date_planned_finished = None
self.state = 'draft' self.state = 'draft'
self.production_line_id = False self.production_line_id = None
aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)]) aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)])
aa.schedule_state = '未排' aa.schedule_state = '未排'
# self.env['sale.order'].browse(record.production_id.origin).schedule_status = 'to shedule' # self.env['sale.order'].browse(record.production_id.origin).schedule_status = 'to shedule'

View File

@@ -500,8 +500,12 @@ class ShelfLocation(models.Model):
# sf_secret_key = sf_sync_config['sf_secret_key'] # sf_secret_key = sf_sync_config['sf_secret_key']
# headers = Common.get_headers(self, token, sf_secret_key) # headers = Common.get_headers(self, token, sf_secret_key)
# strurl = sf_sync_config['sf_url'] + self.crea_url # strurl = sf_sync_config['sf_url'] + self.crea_url
headers = {'Authorization': 'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A'} config = self.env['res.config.settings'].get_values()
crea_url = 'https://x24467i973.zicp.fun/AutoDeviceApi/GetLocationInfos' # token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A]
headers = {'Authorization': config['center_control_Authorization']}
crea_url = config['center_control_url'] + "/AutoDeviceApi/GetLocationInfos"
# headers = {'Authorization': 'Ba F2CF5DCC-1A00-4234-9E95-65603'}
# crea_url = 'https://x24467i973.zicp.fun/AutoDeviceApi/GetLocationInfos'
# objs_all = self.env['maintenance.equipment'].search([('id', '=', self.id)]) # objs_all = self.env['maintenance.equipment'].search([('id', '=', self.id)])
# machine_tool_list = [] # machine_tool_list = []