diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index 42efa95b..9354c503 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -430,16 +430,23 @@ class Manufacturing_Connect(http.Controller): ret = json.loads(datas) if 'DeviceId' in ret: logging.info('DeviceId:%s' % ret['DeviceId']) - workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search( - [('feeder_station_destination_id.name', '=', ret['DeviceId']), - ('status', '=', '已配送'), ('type', '=', '上产线')], order='id asc') - if workpiece_delivery: - for wd in workpiece_delivery: - logging.info('wd.production_id:%s' % wd.production_id.name) - if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '待上产线': - logging.info('wd.production_line_state:%s' % wd.production_id.production_line_state) - wd.production_id.write({'production_line_state': '已上产线'}) - wd.write({'production_line_state': '已上产线'}) + for i in range(1, 5): + if f'RfidCode{i}' in ret: + rfid_code = ret[f'RfidCode{i}'] + domain = [ + ('feeder_station_destination_id.name', '=', ret['DeviceId']), + ('workorder_id.rfid_code', '=', rfid_code), + ('status', '=', '已配送'), + ('type', '=', '上产线') + ] + workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(domain, order='id asc') + if workpiece_delivery: + for wd in workpiece_delivery: + logging.info('wd.production_id:%s' % wd.production_id.name) + if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '待上产线': + logging.info('wd.production_line_state:%s' % wd.production_id.production_line_state) + wd.production_id.write({'production_line_state': '已上产线'}) + wd.write({'production_line_state': '已上产线'}) else: res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的已配送工件数据'} else: @@ -465,23 +472,25 @@ class Manufacturing_Connect(http.Controller): ret = json.loads(datas) if 'DeviceId' in ret: logging.info('DeviceId:%s' % ret['DeviceId']) - workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search( - [('feeder_station_destination_id.name', '=', ret['DeviceId']), - ('status', '=', '已配送'), ('type', '=', '下产线')], order='id asc') - if workpiece_delivery: - for wd in workpiece_delivery: - logging.info('wd.production_id:%s' % wd.production_id.name) - if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '已上产线': - logging.info('wd.production_line_state:%s' % wd.production_id.production_line_state) - wd.production_id.write({'production_line_state': '已下产线'}) - logging.info('开始向agv下发下产线任务') - wd._delivery_avg() - logging.info('agv下发下产线任务已配送') - - else: - res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的工件配送数据'} - else: - res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传DeviceId字段'} + for i in range(1, 5): + if f'RfidCode{i}' in ret: + rfid_code = ret[f'RfidCode{i}'] + domain = [ + ('feeder_station_destination_id.name', '=', ret['DeviceId']), + ('workorder_id.rfid_code', '=', rfid_code), + ('status', '=', '待下发'), + ('type', '=', '下产线') + ] + workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(domain, order='id asc') + if workpiece_delivery: + for wd in workpiece_delivery: + logging.info('wd.production_id:%s' % wd.production_id.name) + if wd.workorder_id.state == 'done' and wd.production_id.production_line_state == '已上产线': + logging.info('wd.production_line_state:%s' % wd.production_id.production_line_state) + wd.production_id.write({'production_line_state': '已下产线'}) + logging.info('开始向agv下发下产线任务') + wd._delivery_avg() + logging.info('agv下发下产线任务已配送') except Exception as e: res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} logging.info('AGVDownProduct error:%s' % e) diff --git a/sf_manufacturing/controllers/workpiece.py b/sf_manufacturing/controllers/workpiece.py index 04a4bbab..4dfb254c 100644 --- a/sf_manufacturing/controllers/workpiece.py +++ b/sf_manufacturing/controllers/workpiece.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import logging import json +from datetime import datetime from odoo import http from odoo.http import request @@ -29,6 +30,12 @@ class Workpiece(http.Controller): [('production_id.name', '=', ret['reqCode'].rsplit('-', 1)[0]), ('delivery_num', '=', ret['reqCode'])]) if workpiece_delivery: + # for item in workpiece_delivery.sametransport_production_ids: + # sametransport_workpiece = request.env['sf.workpiece.delivery'].search( + # [('production_id', '=', item.id), ('type', '=', workpiece_delivery.type)]) + # if sametransport_workpiece: + # sametransport_workpiece.write( + # {'task_delivery_time': datetime.now(), 'status': '已配送'}) workpiece_delivery.write({'status': '已配送', 'task_completion_time': ret['reqTime']}) else: res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该reqCode暂未查到对应的工件配送记录'} diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 0a1bbdac..cce3db16 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -155,6 +155,7 @@ class ResMrpWorkOrder(models.Model): is_delivery = fields.Boolean('是否配送完成', default=False) rfid_code = fields.Char('RFID码') rfid_code_old = fields.Char('RFID码(已解除)') + production_line_id = fields.Many2one('sf.production.line', related='production_id.production_line_id', string='生产线', store=True) production_line_state = fields.Selection(related='production_id.production_line_state', @@ -402,7 +403,7 @@ class ResMrpWorkOrder(models.Model): # if not item.workpiece_code: # raise UserError('请对【同运工件】进行扫描') else: - if self.cnc_program_down_state == '已下发': + if self.is_cnc_program_down is True: if item.status == '待下发': return { 'name': _('确认'), @@ -875,6 +876,11 @@ class CNCprocessing(models.Model): # cnc_workorder.state = 'done' cnc_workorder.work_state = '已编程' cnc_workorder.programming_state = '已编程' + workpiece_delivery = self.env['sf.workpiece.delivery'].search( + [('production_id', '=', cnc_workorder.id)]) + if workpiece_delivery: + for item in workpiece_delivery: + item.is_cnc_program_down = True # cnc_workorder.time_ids.date_end = datetime.now() # cnc_workorder.button_finish() @@ -1059,12 +1065,11 @@ class WorkPieceDelivery(models.Model): delivery_num = fields.Char('工件配送编码') workorder_id = fields.Many2one('mrp.workorder', string='工单', readonly=True) - production_id = fields.Many2one('mrp.production', string='制造订单', readonly=True) + production_id = fields.Many2one('mrp.production', string='制造订单号', readonly=True) production_line_id = fields.Many2one('sf.production.line', compute='_compute_production_line_id', string='目的生产线', readonly=True, store=True) plan_start_processing_time = fields.Datetime('计划开始加工时间', readonly=True) - sametransport_production_ids = fields.Many2many('mrp.production', 'rel_workpiece_production', string='同运工件编码') route_id = fields.Many2one('sf.agv.task.route', '任务路线') feeder_station_start_id = fields.Many2one('sf.agv.site', '起点接驳站') @@ -1077,57 +1082,83 @@ class WorkPieceDelivery(models.Model): status = fields.Selection( [('待下发', '待下发'), ('待配送', '待配送'), ('已配送', '已配送')], string='状态', default='待下发') - production_line_state = fields.Selection( - [('待上产线', '待上产线'), ('已上产线', '已上产线'), ('已下产线', '已下产线')], - string='上/下产线', default='待上产线') - cnc_program_down_state = fields.Selection([('待下发', '待下发'), ('已下发', '已下发')], - string='CNC程序下发状态', default='待下发') + is_cnc_program_down = fields.Boolean('程序是否下发', default=False) @api.onchange('route_id') - def onchage_route(self): + def onchange_route(self): if self.route_id: self.feeder_station_start_id = self.route_id.start_site_id self.feeder_station_destination_id = self.route_id.end_site_id # 工件配送 def button_delivery(self): - if self.cnc_program_down_state == '待下发': - if self.route_id: - if self.status == '待下发': - return { - 'name': _('确认'), - 'type': 'ir.actions.act_window', - 'view_mode': 'form', - 'res_model': 'sf.workpiece.delivery.wizard', - 'target': 'new', - 'context': { - 'default_delivery_id': self.id, - }} - else: - raise UserError('状态为【待下发】的工件记录可进行配送') + delivery_ids = [] + is_cnc_down = 0 + is_not_production_line = 0 + is_not_route = 0 + same_production_line_id = None + same_route_id = None + for item in self: + if item.route_id: + if same_route_id is None: + same_route_id = item.route_id.id + if item.route_id.id != same_route_id: + is_not_route += 1 else: raise UserError('请选择任务路线再进行配送') - else: - raise UserError(_("该制造订单还未下发CNC程序单,无法进行工件配送")) + if same_production_line_id is None: + same_production_line_id = item.production_line_id.id + if item.production_line_id.id != same_production_line_id: + is_not_production_line += 1 + if item.is_cnc_program_down is False: + is_cnc_down += 1 + if is_cnc_down == 0 and is_not_production_line == 0 and is_not_route == 0: + delivery_ids.append(item.production_id.id) + if is_cnc_down >= 1: + raise UserError('您所选择制造订单的CNC程序暂未下发,请在程序下发后再进行配送') + if is_not_production_line >= 1: + raise UserError('您所选择制造订单的目的生产线不一致,请重新确认') + if is_not_route >= 1: + raise UserError('您所选择制造订单的任务路线不一致,请重新确认') + if delivery_ids: + return { + 'name': _('确认'), + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'sf.workpiece.delivery.wizard', + 'target': 'new', + 'context': { + 'default_delivery_ids': [(6, 0, delivery_ids)], + }} # 配送至avg小车 def _delivery_avg(self): agv_site = self.env['sf.agv.site'].search([]) - # if agv_site: - # agv_site.update_site_state() + if agv_site: + agv_site.update_site_state() config = self.env['res.config.settings'].get_values() positionCode_Arr = [] - if self.feeder_station_start_id: + delivery_Arr = [] + feeder_station_start = None + feeder_station_destination = None + for item in self: + if feeder_station_start is None: + feeder_station_start = item.feeder_station_start_id.name + if feeder_station_destination is None: + feeder_station_destination = item.feeder_station_start_id.name + delivery_Arr.append(item.delivery_num) + delivery_str = ', '.join(map(str, delivery_Arr)) + if feeder_station_start is not None: positionCode_Arr.append({ - 'positionCode': self.feeder_station_start_id.name, + 'positionCode': feeder_station_start, 'code': '00' }) - if self.feeder_station_destination_id: + if feeder_station_destination is not None: positionCode_Arr.append({ - 'positionCode': self.feeder_station_destination_id.name, + 'positionCode': feeder_station_destination, 'code': '00' }) - res = {'reqCode': self.delivery_num, 'reqTime': '', 'clientCode': '', 'tokenCode': '', + res = {'reqCode': delivery_str, 'reqTime': '', 'clientCode': '', 'tokenCode': '', 'taskTyp': 'F01', 'ctnrTyp': '', 'ctnrCode': '', 'wbCode': config['wbcode'], 'positionCodePath': positionCode_Arr, 'podCode': '', @@ -1142,16 +1173,14 @@ class WorkPieceDelivery(models.Model): ret = ret.json() logging.info('config-ret:%s' % ret) if ret['code'] == 0: - if self.delivery_num == ret['reqCode']: - if self.sametransport_production_ids: - for item in self.sametransport_production_ids: - sametransport_workpiece = self.search( - [('production_id', '=', item.id), ('type', '=', '上产线')]) - if sametransport_workpiece: - sametransport_workpiece.write( - {'task_delivery_time': fields.Datetime.now(), 'status': '待配送'}) - self.write( - {'task_delivery_time': fields.Datetime.now(), 'status': '待配送'}) + req_codes = ret['reqCode'].split(',') + for delivery_item in self: + for req_code in req_codes: + if delivery_item.delivery_num == req_code: + delivery_item.write({ + 'task_delivery_time': fields.Datetime.now(), + 'status': '待配送' + }) else: raise UserError(ret['message']) except Exception as e: diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 06dcd5bd..6ba7c691 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -185,7 +185,6 @@ attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/> - @@ -424,11 +423,10 @@ - - + @@ -567,14 +565,13 @@ decoration-success="status == '已配送'" decoration-warning="status == '待下发'" decoration-danger="status == '待配送'"/> - - + - + @@ -588,7 +585,6 @@ - @@ -599,9 +595,6 @@ - - - diff --git a/sf_manufacturing/wizard/workpiece_delivery_views.xml b/sf_manufacturing/wizard/workpiece_delivery_views.xml index 83cfb89f..a65593d7 100644 --- a/sf_manufacturing/wizard/workpiece_delivery_views.xml +++ b/sf_manufacturing/wizard/workpiece_delivery_views.xml @@ -5,7 +5,7 @@ sf.workpiece.delivery.wizard
- +
是否确定配送?