agv调度开发

This commit is contained in:
胡尧
2024-08-15 15:02:13 +08:00
parent 6c734eead4
commit 9f180e307d
4 changed files with 84 additions and 73 deletions

View File

@@ -136,8 +136,6 @@ class AgvScheduling(models.Model):
)
# 下发AGV调度任务并修改接驳站状态为占用
agv_scheduling.dispatch_scheduling(agv_site_id, agv_site_state)
# 更新接驳站状态
self.env['sf.agv.site'].update_site_state({agv_scheduling.end_site_id.name: '占用'}, False)
else:
# 如果终点接驳站变为占用,则认为任务完成
agv_scheduling = self.env['sf.agv.scheduling'].sudo().search(
@@ -244,6 +242,8 @@ class AgvScheduling(models.Model):
rec.task_delivery_time = fields.Datetime.now()
rec.site_state = agv_site_state
rec.end_site_id = agv_end_site_id
# 更新接驳站状态
rec.env['sf.agv.site'].update_site_state({rec.end_site_id.name: '占用'}, False)
class ResMrpWorkOrder(models.Model):

View File

@@ -1268,7 +1268,7 @@ class ResMrpWorkOrder(models.Model):
def button_delivery(self):
production_ids = []
workorder_ids = []
production_type = '运送空料架'
delivery_type = '运送空料架'
max_num = 4 # 最大配送数量
if len(self) > max_num:
raise UserError('仅限于拆卸1-4个制造订单请重新选择')
@@ -1287,7 +1287,7 @@ class ResMrpWorkOrder(models.Model):
'context': {
# 'default_delivery_ids': [(6, 0, delivery_ids)],
'default_production_ids': [(6, 0, production_ids)],
'default_type': production_type,
'default_delivery_type': delivery_type,
'default_workorder_ids': [(6, 0, workorder_ids)],
'default_workcenter_id': self.env.context.get('default_workcenter_id'),
'default_confirm_button': '确认拆卸'
@@ -1588,7 +1588,7 @@ class WorkPieceDelivery(models.Model):
@api.model
def create(self, vals):
if vals['route_id'] and vals.get('type') is None:
if vals.get('route_id') and vals.get('type') is None:
vals['type'] = '运送空料架'
else:
if vals.get('name', '/') == '/' or vals.get('name', '/') is False:
@@ -1640,7 +1640,7 @@ class WorkPieceDelivery(models.Model):
is_cnc_down = 0
is_not_production_line = 0
same_production_line_id = None
production_type = '上产线'
delivery_type = '上产线'
max_num = 4 # 最大配送数量
if len(self) > max_num:
raise UserError('仅限于配送1-4个制造订单请重新选择')
@@ -1670,7 +1670,7 @@ class WorkPieceDelivery(models.Model):
'context': {
# 'default_delivery_ids': [(6, 0, delivery_ids)],
'default_production_ids': [(6, 0, production_ids)],
'default_type': production_type,
'default_delivery_type': delivery_type,
'default_workorder_ids': [(6, 0, workorder_ids)],
'default_confirm_button': '确认配送'
}}

View File

@@ -8,12 +8,12 @@
<sheet>
<!-- <field name="delivery_ids" invisible="True"/>-->
<field name="workorder_ids" invisible="True"/>
<field name="type" invisible="True"/>
<field name="delivery_type" invisible="True"/>
<field name="confirm_button" invisible="1"/>
<field name="_barcode_scanned" widget="barcode_handler"/>
<group col="1">
<field name="production_ids" readonly="1" widget="many2many_tags" string="制造订单号"/>
<field name="type" readonly="1"/>
<field name="delivery_type" readonly="1"/>
<field name="feeder_station_start_id" options="{'no_create': True}" required="1"/>
<field name="workcenter_id" options="{'no_create': True}"/>
</group>

View File

@@ -22,10 +22,10 @@ class WorkpieceDeliveryWizard(models.TransientModel):
workcenter_id = fields.Many2one(string='所属区域', comodel_name='mrp.workcenter', tracking=True)
confirm_button = fields.Char('按钮名称')
@api.onchange('type')
@api.onchange('delivery_type')
def _onchange_type(self):
if self.type:
routes = self.env['sf.agv.task.route'].search([('route_type', '=', self.type)])
if self.delivery_type:
routes = self.env['sf.agv.task.route'].search([('route_type', '=', self.delivery_type)])
if self.workcenter_id:
routes = routes.filtered(lambda a: a.start_site_id.workcenter_id.id == self.workcenter_id.id)
start_site_ids = routes.mapped('start_site_id.id')
@@ -51,73 +51,78 @@ class WorkpieceDeliveryWizard(models.TransientModel):
def _get_agv_route_type_selection(self):
return self.env['sf.agv.task.route'].fields_get(['route_type'])['route_type']['selection']
type = fields.Selection(selection=_get_agv_route_type_selection, string='类型')
delivery_type = fields.Selection(selection=_get_agv_route_type_selection, string='类型')
def confirm(self):
try:
# if self.workorder_id:
# self.workorder_id.workpiece_delivery_ids[0].agv_scheduling_id()
# else:
is_not_production_line = 0
same_production_line_id = None
notsame_production_line_arr = []
for item in self.production_ids:
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:
notsame_production_line_arr.append(item.name)
notsame_production_line_str = ','.join(map(str, notsame_production_line_arr))
if is_not_production_line >= 1:
raise UserError('制造订单号为%s的目的生产线不一致' % notsame_production_line_str)
else:
self.env['sf.agv.scheduling'].add_scheduling(
agv_start_site_id=self.feeder_station_start_id.id,
agv_route_type=self.type,
workorders=self.workorder_ids,
)
# is_not_production_line = 0
# same_production_line_id = None
# notsame_production_line_arr = []
# for item in self.production_ids:
# 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:
# notsame_production_line_arr.append(item.name)
# notsame_production_line_str = ','.join(map(str, notsame_production_line_arr))
# if is_not_production_line >= 1:
# raise UserError('制造订单号为%s的目的生产线不一致' % notsame_production_line_str)
# else:
self.env['sf.agv.scheduling'].add_scheduling(
agv_start_site_id=self.feeder_station_start_id.id,
agv_route_type=self.delivery_type,
workorders=self.workorder_ids,
)
# 如果是解除装夹工单,则需要处理工单逻辑
for item in self.workorder_ids:
if item.routing_type == '解除装夹' and item.state == 'ready':
item.button_start()
item.button_finish()
except Exception as e:
logging.info('工件配送任务下发失败:%s' % e)
raise UserError('工件配送任务下发失败:%s' % e)
logging.info('%s任务下发失败:%s' % (self.delivery_type, e))
raise UserError('%s任务下发失败:%s' % (self.delivery_type, e))
def recognize_production(self):
# production_ids = []
# delivery_ids = []
# aa = self.production_ids.workorder_ids.filtered(
# lambda b: b.routing_type == "装夹预调").workpiece_delivery_ids.filtered(
# lambda c: c.rfid_code == self.rfid_code)
# logging.info('aa:%s' % aa)
if len(self.production_ids) == 4:
raise UserError('只能配送四个制造订单')
else:
if self.rfid_code:
wd = self.env['sf.workpiece.delivery'].search(
[('type', '=', self.delivery_ids[0].type), ('rfid_code', '=', self.rfid_code),
('status', '=', self.delivery_ids[0].status)])
if wd:
if wd.production_line_id.id == self.delivery_ids[0].production_line_id.id:
# production_ids.append(wd.production_id)
# delivery_ids.append(wd.id)
# 将对象添加到对应的同模型且是多对多类型里
self.production_ids |= wd.production_id
self.delivery_ids |= wd
self.rfid_code = False
# self.production_ids = [(6, 0, production_ids)]
# self.delivery_ids = [(6, 0, delivery_ids)]
else:
raise UserError('该rfid对应的制造订单号为%s的目的生产线不一致' % wd.production_id.name)
return {
'name': _('确认'),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'sf.workpiece.delivery.wizard',
'target': 'new',
'context': {
'default_delivery_ids': [(6, 0, self.delivery_ids.ids)],
'default_production_ids': [(6, 0, self.production_ids.ids)],
'default_route_id': self.delivery_ids[0].route_id.id,
'default_type': self.delivery_ids[0].type
}}
# def recognize_production(self):
# # production_ids = []
# # delivery_ids = []
# # aa = self.production_ids.workorder_ids.filtered(
# # lambda b: b.routing_type == "装夹预调").workpiece_delivery_ids.filtered(
# # lambda c: c.rfid_code == self.rfid_code)
# # logging.info('aa:%s' % aa)
# if len(self.production_ids) == 4:
# raise UserError('只能配送四个制造订单')
# else:
# if self.rfid_code:
# wd = self.env['sf.workpiece.delivery'].search(
# [('type', '=', self.delivery_ids[0].type), ('rfid_code', '=', self.rfid_code),
# ('status', '=', self.delivery_ids[0].status)])
# if wd:
# if wd.production_line_id.id == self.delivery_ids[0].production_line_id.id:
# # production_ids.append(wd.production_id)
# # delivery_ids.append(wd.id)
# # 将对象添加到对应的同模型且是多对多类型里
# self.production_ids |= wd.production_id
# self.delivery_ids |= wd
# self.rfid_code = False
# # self.production_ids = [(6, 0, production_ids)]
# # self.delivery_ids = [(6, 0, delivery_ids)]
# else:
# raise UserError('该rfid对应的制造订单号为%s的目的生产线不一致' % wd.production_id.name)
# return {
# 'name': _('确认'),
# 'type': 'ir.actions.act_window',
# 'view_mode': 'form',
# 'res_model': 'sf.workpiece.delivery.wizard',
# 'target': 'new',
# 'context': {
# 'default_delivery_ids': [(6, 0, self.delivery_ids.ids)],
# 'default_production_ids': [(6, 0, self.production_ids.ids)],
# 'default_route_id': self.delivery_ids[0].route_id.id,
# 'default_type': self.delivery_ids[0].type
# }}
@api.onchange('route_id')
def onchange_route(self):
@@ -126,9 +131,15 @@ class WorkpieceDeliveryWizard(models.TransientModel):
self.feeder_station_destination_id = self.route_id.end_site_id.id
def on_barcode_scanned(self, barcode):
workorder = self.env['mrp.workorder'].search(
[('production_line_state', '=', '上产线'), ('rfid_code', '=', barcode),
('state', '=', 'done')])
delivery_type = self.env.context.get('default_delivery_type')
if delivery_type == '上产线':
workorder = self.env['mrp.workorder'].search(
[('production_line_state', '=', '待上产线'), ('rfid_code', '=', barcode),
('state', '=', 'done')])
elif delivery_type == '运送空料架':
workorder = self.env['mrp.workorder'].search(
[('routing_type', '=', '解除装夹'), ('rfid_code', '=', barcode),
('state', '=', 'ready')])
if workorder:
if len(self.production_ids) > 0 and workorder.production_line_id.id != self.production_ids[0].production_line_id.id:
raise UserError('该rfid对应的制造订单号为%s的目的生产线不一致' % workorder.production_id.name)