优化工件配送
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# Part of YiZuo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from datetime import datetime
|
||||
from odoo import models, api, fields
|
||||
from odoo import models, api, fields, _
|
||||
|
||||
|
||||
class WorkpieceDeliveryWizard(models.TransientModel):
|
||||
@@ -10,15 +10,70 @@ class WorkpieceDeliveryWizard(models.TransientModel):
|
||||
_description = '工件配送'
|
||||
|
||||
delivery_ids = fields.Many2many('sf.workpiece.delivery', string='配送')
|
||||
rfid_code = fields.Char('rfid码')
|
||||
workorder_id = fields.Many2one('mrp.workorder', string='工单')
|
||||
production_ids = fields.Many2many('mrp.production', string='制造订单号')
|
||||
destination_production_line_id = fields.Many2one('sf.production.line', '目的生产线')
|
||||
route_id = fields.Many2one('sf.agv.task.route', '任务路线', domain=[('route_type', 'in', ['上产线', '下产线'])])
|
||||
feeder_station_start_id = fields.Many2one('sf.agv.site', '起点接驳站')
|
||||
feeder_station_destination_id = fields.Many2one('sf.agv.site', '目的接驳站')
|
||||
|
||||
type = fields.Selection(
|
||||
[('上产线', '上产线'), ('下产线', '下产线'), ('运送空料架', '运送空料架')], string='类型')
|
||||
|
||||
def confirm(self):
|
||||
if self.workorder_id:
|
||||
self.workorder_id.workpiece_delivery_ids[0]._delivery_avg()
|
||||
else:
|
||||
self.delivery_ids._delivery_avg()
|
||||
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.delivery_ids._delivery_avg()
|
||||
|
||||
def recognize_production(self):
|
||||
# production_ids = []
|
||||
# delivery_ids = []
|
||||
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
|
||||
}}
|
||||
|
||||
@api.onchange('route_id')
|
||||
def onchange_route(self):
|
||||
if self.route_id:
|
||||
self.feeder_station_start_id = self.route_id.start_site_id.id
|
||||
self.feeder_station_destination_id = self.route_id.end_site_id.id
|
||||
|
||||
Reference in New Issue
Block a user