Accept Merge Request #1291: (feature/流程用扫码完成 -> develop)

Merge Request: 工件配送,解除装夹使用扫码完成

Created By: @胡尧
Accepted By: @胡尧
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1291
This commit is contained in:
胡尧
2024-09-11 09:15:48 +08:00
committed by Coding
5 changed files with 56 additions and 48 deletions

View File

@@ -668,7 +668,7 @@ class Manufacturing_Connect(http.Controller):
logging.info('AGVDownProduct error:%s' % e)
return json.JSONEncoder().encode(res)
@http.route('/AutoDeviceApi/AgvStationState', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
@http.route('/AutoDeviceApi/AgvStationState', type='json', auth='public', methods=['GET', 'POST'], csrf=False,
cors="*")
def AGVStationState(self, **kw):
"""

View File

@@ -270,6 +270,7 @@ class ResMrpWorkOrder(models.Model):
"""
获取关联的制造订单下产线的agv任务
"""
self.ensure_one()
workorder_ids = self.production_id.workorder_ids
cnc_workorder = workorder_ids.filtered(
lambda w: w.routing_type == 'CNC加工' and w.state == 'done' and w.processing_panel == self.processing_panel

View File

@@ -1351,23 +1351,23 @@ class ResMrpWorkOrder(models.Model):
return res
def button_delivery(self):
production_ids = []
workorder_ids = []
# production_ids = []
# workorder_ids = []
delivery_type = '运送空料架'
max_num = 4 # 最大配送数量
feeder_station_start_id = False
if len(self) > max_num:
raise UserError('仅限于拆卸1-4个制造订单请重新选择')
for item in self:
if item.state != 'ready':
raise UserError('请选择状态为【就绪】的工单进行解除装夹')
production_ids.append(item.production_id.id)
workorder_ids.append(item.id)
if not feeder_station_start_id:
down_product_agv_scheduling = self.get_down_product_agv_scheduling()
if down_product_agv_scheduling:
feeder_station_start_id = down_product_agv_scheduling.end_site_id.id
# max_num = 4 # 最大配送数量
# feeder_station_start_id = False
# if len(self) > max_num:
# raise UserError('仅限于拆卸1-4个制造订单请重新选择')
# for item in self:
# if item.state != 'ready':
# raise UserError('请选择状态为【就绪】的工单进行解除装夹')
#
# production_ids.append(item.production_id.id)
# workorder_ids.append(item.id)
# if not feeder_station_start_id:
# down_product_agv_scheduling = item.get_down_product_agv_scheduling()
# if down_product_agv_scheduling:
# feeder_station_start_id = down_product_agv_scheduling.end_site_id.id
return {
'name': _('确认'),
'type': 'ir.actions.act_window',
@@ -1376,12 +1376,12 @@ class ResMrpWorkOrder(models.Model):
'target': 'new',
'context': {
# 'default_delivery_ids': [(6, 0, delivery_ids)],
'default_production_ids': [(6, 0, production_ids)],
# 'default_production_ids': [(6, 0, production_ids)],
'default_delivery_type': delivery_type,
'default_workorder_ids': [(6, 0, workorder_ids)],
# 'default_workorder_ids': [(6, 0, workorder_ids)],
'default_workcenter_id': self.env.context.get('default_workcenter_id'),
'default_confirm_button': '确认解除',
'default_feeder_station_start_id': feeder_station_start_id,
# 'default_feeder_station_start_id': feeder_station_start_id,
}}

View File

@@ -18,8 +18,8 @@
<field name="workcenter_id" options="{'no_create': True}"/>
</group>
<footer>
<button string="确认配送" name="dispatch_confirm" type="object" class="oe_highlight o_wizard_confirm_button jikimo_button_confirm" attrs="{'invisible': [('confirm_button', '!=', '确认配送')]}"/>
<button string="确认解除" name="dispatch_confirm" type="object" class="oe_highlight o_wizard_confirm_button jikimo_button_confirm" attrs="{'invisible': [('confirm_button', '!=', '确认解除')]}"/>
<button string="确认配送" name="confirm" type="object" class="oe_highlight o_wizard_confirm_button jikimo_button_confirm" attrs="{'invisible': [('confirm_button', '!=', '确认配送')]}"/>
<button string="确认解除" name="confirm" type="object" class="oe_highlight o_wizard_confirm_button jikimo_button_confirm" attrs="{'invisible': [('confirm_button', '!=', '确认解除')]}"/>
<button string="取消" class="btn btn-secondary" special="cancel"/>
</footer>
</sheet>

View File

@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
# Part of YiZuo. See LICENSE file for full copyright and licensing details.
import json
import logging
from odoo.exceptions import UserError, ValidationError
from datetime import datetime, date
from odoo.exceptions import UserError
from odoo import models, api, fields
@@ -79,29 +78,18 @@ class WorkpieceDeliveryWizard(models.TransientModel):
'tag': 'display_notification',
'target': 'new',
'params': {
'message': '任务下发成功AGV任务调度编号为【%s' % scheduling['name'],
'message': f'任务下发成功AGV任务调度编号为【{scheduling["name"]}',
'type': 'success',
'sticky': False,
'next': {'type': 'ir.actions.act_window_close'},
}
}
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:
if not self.workorder_ids:
raise UserError('制造订单不能为空')
scheduling = self.env['sf.agv.scheduling'].add_scheduling(
agv_start_site_name=self.feeder_station_start_id.name,
agv_route_type=self.delivery_type,
@@ -129,10 +117,21 @@ class WorkpieceDeliveryWizard(models.TransientModel):
item.button_start()
item.button_finish()
return scheduling.read()[0]
# return scheduling.read()[0]
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'target': 'new',
'params': {
'message': f'任务下发成功AGV任务调度编号为【{scheduling.name}',
'type': 'success',
'sticky': False,
'next': {'type': 'ir.actions.act_window_close'},
}
}
except Exception as e:
logging.info('%s任务下发失败:%s' % (self.delivery_type, e))
raise UserError('%s任务下发失败:%s' % (self.delivery_type, e))
logging.info('%s任务下发失败:%s', self.delivery_type, e)
raise UserError(f'{self.delivery_type}任务下发失败:{e}') from e
# def recognize_production(self):
# # production_ids = []
@@ -185,7 +184,11 @@ class WorkpieceDeliveryWizard(models.TransientModel):
# 判断是否是AGV接驳站名称
agv_site = self.env['sf.agv.site'].search([('name', '=', barcode)])
if agv_site:
self.feeder_station_start_id = agv_site.id
if not self.feeder_station_start_id:
self.feeder_station_start_id = agv_site.id
else:
if self.feeder_station_start_id.id != agv_site.id:
raise UserError('起点接驳站不匹配!')
return
delivery_type = self.env.context.get('default_delivery_type')
if delivery_type == '上产线':
@@ -205,16 +208,20 @@ class WorkpieceDeliveryWizard(models.TransientModel):
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)
raise UserError(f'该rfid对应的制造订单号为{workorder.production_id.name}的目的生产线不一致')
# 将对象添加到对应的同模型且是多对多类型里
self.production_ids |= workorder.production_id
self.workorder_ids |= workorder
if not self.feeder_station_start_id:
down_product_agv_scheduling = self.get_down_product_agv_scheduling()
if down_product_agv_scheduling:
down_product_agv_scheduling = self.get_down_product_agv_scheduling()
if down_product_agv_scheduling:
if not self.feeder_station_start_id:
self.feeder_station_start_id = down_product_agv_scheduling.end_site_id.id
else:
if self.feeder_station_start_id.id != down_product_agv_scheduling.end_site_id.id:
raise UserError(f'该rfid不在{self.feeder_station_start_id.name}接驳站内')
else:
raise UserError('该rfid码对应的工单不存在')
return