优化工件配送

This commit is contained in:
jinling.yang
2024-04-25 15:43:02 +08:00
parent d4aa71975e
commit 11864feaa4
6 changed files with 120 additions and 82 deletions

View File

@@ -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: