Accept Merge Request #963: (feature/优化agv -> develop)
Merge Request: 优化agv及站点位置和对应接口 Created By: @杨金灵 Reviewed By: @马广威 Approved By: @马广威 Accepted By: @杨金灵 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/963?initial=true
This commit is contained in:
@@ -432,7 +432,7 @@ class Manufacturing_Connect(http.Controller):
|
||||
logging.info('DeviceId:%s' % ret['DeviceId'])
|
||||
workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(
|
||||
[('feeder_station_start_id.name', '=', ret['DeviceId']),
|
||||
('status', '=', '待配送')], limit=1, order='id asc')
|
||||
('status', '=', '已配送'), ('type', '=', '上产线')], order='id asc')
|
||||
if workpiece_delivery:
|
||||
for wd in workpiece_delivery:
|
||||
logging.info('wd.production_id:%s' % wd.production_id.name)
|
||||
@@ -441,7 +441,7 @@ class Manufacturing_Connect(http.Controller):
|
||||
wd.production_id.write({'production_line_state': '已上产线'})
|
||||
wd.write({'production_line_state': '已上产线'})
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的工件配送数据'}
|
||||
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该DeviceId没有对应的已配送工件数据'}
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 201, 'Error': '未传DeviceId字段'}
|
||||
except Exception as e:
|
||||
@@ -466,26 +466,16 @@ class Manufacturing_Connect(http.Controller):
|
||||
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', '=', '待配送')], limit=1, order='id asc')
|
||||
[('feeder_station_start_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)
|
||||
workpiece_delivery_off = request.env['sf.workpiece.delivery'].sudo().create({
|
||||
'production_id': wd.production_id.id,
|
||||
'feeder_station_start_id': workpiece_delivery.feeder_station_start_id.id,
|
||||
'feeder_station_destination_id': '',
|
||||
'workorder_id': workpiece_delivery.workorder_id.id,
|
||||
'workpiece_code': workpiece_delivery.workpiece_code,
|
||||
'production_line_id': workpiece_delivery.production_line_id.id,
|
||||
'task_delivery_time': datetime.now(),
|
||||
'production_line_state': '已下产线'
|
||||
})
|
||||
wd.production_id.write({'production_line_state': '已下产线'})
|
||||
logging.info('开始向agv下发下产线任务')
|
||||
workpiece_delivery_off._delivery_avg()
|
||||
wd._delivery_avg()
|
||||
logging.info('agv下发下产线任务已配送')
|
||||
|
||||
else:
|
||||
|
||||
@@ -28,6 +28,11 @@ class Workpiece(http.Controller):
|
||||
[('production_id.name', '=', ret['reqCode']), ('agv_task_code'), '=', ret['taskCode']])
|
||||
if workpiece_delivery:
|
||||
workpiece_delivery.write({'status': '已配送', 'task_completion_time': ret['reqTime']})
|
||||
if workpiece_delivery.type == '下产线':
|
||||
workpiece_delivery_clear = request.env['sf.workpiece.delivery'].sudo().search(
|
||||
[('production_id.name', '=', ret['reqCode']), ('type', '=', '运送空料架')])
|
||||
if workpiece_delivery_clear:
|
||||
workpiece_delivery_clear._delivery_avg()
|
||||
else:
|
||||
res = {'Succeed': False, 'ErrorCode': 203, 'Error': '该reqCode暂未查到对应的工件配送记录'}
|
||||
else:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import requests
|
||||
import logging
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
@@ -13,6 +15,23 @@ class AgvSetting(models.Model):
|
||||
('占用', '占用'),
|
||||
('空闲', '空闲')], string='状态')
|
||||
divide_the_work = fields.Char('主要分工')
|
||||
active = fields.Boolean('有效', default=True)
|
||||
|
||||
def update_site_state(self):
|
||||
# 调取中控的接驳站接口并修改对应站点的状态
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
# token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A]
|
||||
headers = {'Authorization': config['center_control_Authorization']}
|
||||
center_control_url = config['center_control_url'] + "/AutoDeviceApi/GetAgvStationState"
|
||||
center_control_r = requests.get(center_control_url, params={}, headers=headers)
|
||||
ret = center_control_r.json()
|
||||
logging.info('工件配送-请求中控站点信息:%s' % ret)
|
||||
datas = ret['Datas']
|
||||
for item in self:
|
||||
for da in datas:
|
||||
if da['DeviceId'] == item.name:
|
||||
if da['AtHome'] is True:
|
||||
item.state = '占用'
|
||||
|
||||
|
||||
class AgvTaskRoute(models.Model):
|
||||
|
||||
@@ -458,360 +458,376 @@ class ResMrpWorkOrder(models.Model):
|
||||
'date_planned_finished': False,
|
||||
'duration_expected': duration_expected,
|
||||
'duration': 0,
|
||||
'workpiece_delivery_ids': False if not route.routing_type == '装夹预调' else self.env[
|
||||
'sf.workpiece.delivery'].create(
|
||||
{'production_id': production.id})
|
||||
'workpiece_delivery_ids': False if not route.routing_type == '装夹预调' else self._json_workpiece_delivery_list(
|
||||
production)
|
||||
}]
|
||||
return workorders_values_str
|
||||
|
||||
# 拼接工单对象属性值(表面工艺)
|
||||
def _json_workorder_surface_process_str(self, production, route, process_parameter, supplier_id):
|
||||
workorders_values_str = [0, '', {
|
||||
'product_uom_id': production.product_uom_id.id,
|
||||
'qty_producing': 0,
|
||||
'operation_id': False,
|
||||
'name': '%s-%s' % (route.name, process_parameter.name),
|
||||
'processing_panel': '',
|
||||
'routing_type': '表面工艺',
|
||||
'surface_technics_parameters_id': process_parameter.id,
|
||||
'work_state': '',
|
||||
'supplier_id': supplier_id,
|
||||
'is_subcontract': True if process_parameter.gain_way == '外协' else False,
|
||||
'workcenter_id': self.env[
|
||||
'mrp.workcenter'].get_process_outsourcing_workcenter() if process_parameter.gain_way == '外协' else
|
||||
self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
|
||||
route.routing_type,
|
||||
production.product_id),
|
||||
'date_planned_start': False,
|
||||
'date_planned_finished': False,
|
||||
'duration_expected': 60,
|
||||
'duration': 0
|
||||
}]
|
||||
return workorders_values_str
|
||||
def _json_workpiece_delivery_list(self, production):
|
||||
return [
|
||||
[0, '', {'production_id': production.id, 'type': '上产线'}],
|
||||
[0, '', {'production_id': production.id, 'type': '下产线'}],
|
||||
[0, '', {'production_id': production.id, 'type': '运送空料架'}],
|
||||
]
|
||||
|
||||
|
||||
# 拼接工单对象属性值(表面工艺)
|
||||
def _json_workorder_surface_process_str(self, production, route, process_parameter, supplier_id):
|
||||
workorders_values_str = [0, '', {
|
||||
'product_uom_id': production.product_uom_id.id,
|
||||
'qty_producing': 0,
|
||||
'operation_id': False,
|
||||
'name': '%s-%s' % (route.name, process_parameter.name),
|
||||
'processing_panel': '',
|
||||
'routing_type': '表面工艺',
|
||||
'surface_technics_parameters_id': process_parameter.id,
|
||||
'work_state': '',
|
||||
'supplier_id': supplier_id,
|
||||
'is_subcontract': True if process_parameter.gain_way == '外协' else False,
|
||||
'workcenter_id': self.env[
|
||||
'mrp.workcenter'].get_process_outsourcing_workcenter() if process_parameter.gain_way == '外协' else
|
||||
self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
|
||||
route.routing_type,
|
||||
production.product_id),
|
||||
'date_planned_start': False,
|
||||
'date_planned_finished': False,
|
||||
'duration_expected': 60,
|
||||
'duration': 0
|
||||
}]
|
||||
return workorders_values_str
|
||||
|
||||
|
||||
# 维修模块按钮
|
||||
def button_maintenance_req(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': _('New Maintenance Request'),
|
||||
'view_mode': 'form',
|
||||
'views': [(self.env.ref('mrp_maintenance.maintenance_request_view_form_inherit_mrp').id, 'form')],
|
||||
'res_model': 'maintenance.request',
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {
|
||||
'default_company_id': self.company_id.id,
|
||||
'default_workorder_id': self.id,
|
||||
'default_production_id': self.production_id.id,
|
||||
'discard_on_footer_button': True,
|
||||
},
|
||||
'target': 'new',
|
||||
'domain': [('workorder_id', '=', self.id)]
|
||||
}
|
||||
|
||||
|
||||
# tray_id = fields.Many2one('sf.tray', string="托盘信息", tracking=True)
|
||||
|
||||
# 扫码绑定托盘方法
|
||||
|
||||
# def gettray(self):
|
||||
# if self.tray_code != False:
|
||||
# values = self.env['sf.tray'].search([("code", "=", self.tray_code)])
|
||||
# if values:
|
||||
# if values.state == "占用":
|
||||
# raise UserError('该托盘已占用')
|
||||
# if values.state == "报损":
|
||||
# raise UserError('该托盘已损坏')
|
||||
# else:
|
||||
# values.update({
|
||||
# 'workorder_id': self,
|
||||
# 'production_id': self.production_id,
|
||||
# 'state': '占用',
|
||||
# })
|
||||
# self.work_state = "已绑定"
|
||||
# orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
|
||||
# for a in orders:
|
||||
# a.tray_id = values
|
||||
# else:
|
||||
# raise UserError('该托盘编码已失效')
|
||||
# else:
|
||||
# raise UserError('托盘码不能为空')
|
||||
|
||||
# 验证坯料序列号是否正确
|
||||
def pro_code_is_ok(self, barcode):
|
||||
if barcode is not False:
|
||||
if barcode != self.pro_code:
|
||||
raise UserError('坯料序列号错误')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
pro_code = fields.Char(string='坯料序列号')
|
||||
|
||||
pro_code_ok = fields.Boolean(default=False)
|
||||
|
||||
|
||||
# 托盘扫码绑定
|
||||
# def gettray_auto(self, barcode):
|
||||
# if barcode != False:
|
||||
# values = self.env['sf.tray'].search([("code", "=", barcode)])
|
||||
#
|
||||
# if values:
|
||||
# if values.state == "占用":
|
||||
# raise UserError('该托盘已占用')
|
||||
# if values.state == "报损":
|
||||
# raise UserError('该托盘已损坏')
|
||||
# else:
|
||||
# values.update({
|
||||
# 'workorder_id': self,
|
||||
# 'production_id': self.production_id,
|
||||
# 'state': '占用',
|
||||
# })
|
||||
# self.work_state = "已绑定"
|
||||
# orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
|
||||
# for a in orders:
|
||||
# a.tray_id = values
|
||||
#
|
||||
# return values
|
||||
#
|
||||
# # return {
|
||||
# # 'name': _('New Maintenance Request'),
|
||||
# # 'view_mode': 'form',
|
||||
# # 'res_model': 'maintenance.request',
|
||||
# # 'type': 'ir.actions.act_window',
|
||||
# # 'context': {
|
||||
# # 'default_company_id': self.company_id.id,
|
||||
# # 'default_production_id': self.id,
|
||||
# # },
|
||||
# # 'domain': [('production_id', '=', self.id)],
|
||||
# # }
|
||||
# else:
|
||||
# raise UserError('该托盘编码已失效')
|
||||
# else:
|
||||
# raise UserError('托盘码不能为空')
|
||||
|
||||
# 解除托盘绑定
|
||||
# def unbindtray(self):
|
||||
# tray = self.env['sf.tray'].search([("production_id", "=", self.production_id.id)])
|
||||
# if tray:
|
||||
# tray.unclamp()
|
||||
# self.tray_id = False
|
||||
|
||||
# return {
|
||||
# 'name': _('New Maintenance Request'),
|
||||
# 'view_mode': 'form',
|
||||
# 'res_model': 'maintenance.request',
|
||||
# 'res_id':self.id,
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# 'context': {
|
||||
# 'default_company_id': self.company_id.id,
|
||||
# 'default_production_id': self.id,
|
||||
# },
|
||||
# 'domain': [('production_id', '=', self.id)],
|
||||
# 'target':'new'
|
||||
# }
|
||||
|
||||
def recreateManufacturingOrWorkerOrder(self):
|
||||
"""
|
||||
重新生成制造订单或者重新生成工单
|
||||
"""
|
||||
if self.test_results == '报废':
|
||||
values = self.env['mrp.production'].create_production1_values(self.production_id)
|
||||
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
|
||||
self.production_id.company_id).create(
|
||||
values)
|
||||
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
productions._create_workorder()
|
||||
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
|
||||
(
|
||||
p.move_dest_ids.procure_method != 'make_to_order' and
|
||||
not p.move_raw_ids and not p.workorder_ids)).action_confirm()
|
||||
|
||||
for production in productions:
|
||||
origin_production = production.move_dest_ids and production.move_dest_ids[
|
||||
0].raw_material_production_id or False
|
||||
orderpoint = production.orderpoint_id
|
||||
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
|
||||
production.message_post(
|
||||
body=_('This production order has been created from Replenishment Report.'),
|
||||
message_type='comment',
|
||||
subtype_xmlid='mail.mt_note')
|
||||
elif orderpoint:
|
||||
production.message_post_with_view(
|
||||
'mail.message_origin_link',
|
||||
values={'self': production, 'origin': orderpoint},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
elif origin_production:
|
||||
production.message_post_with_view(
|
||||
'mail.message_origin_link',
|
||||
values={'self': production, 'origin': origin_production},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
if self.test_results == '返工':
|
||||
productions = self.production_id
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
productions._create_workorder2(self.processing_panel)
|
||||
else:
|
||||
self.results = '合格'
|
||||
|
||||
|
||||
def json_workorder_str1(self, k, production, route):
|
||||
workorders_values_str = [0, '', {
|
||||
'product_uom_id': production.product_uom_id.id,
|
||||
'qty_producing': 0,
|
||||
'operation_id': False,
|
||||
'name': '%s(返工)' % route.route_workcenter_id.name,
|
||||
'processing_panel': k,
|
||||
'routing_type': route.routing_type,
|
||||
'work_state': '' if not route.routing_type == '获取CNC加工程序' else '待发起',
|
||||
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
|
||||
route.routing_type,
|
||||
production.product_id),
|
||||
'date_planned_start': False,
|
||||
'date_planned_finished': False,
|
||||
'duration_expected': 60,
|
||||
'duration': 0,
|
||||
|
||||
}]
|
||||
return workorders_values_str
|
||||
|
||||
|
||||
# 重写工单开始按钮方法
|
||||
def button_start(self):
|
||||
if self.routing_type == '装夹预调' and self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name:
|
||||
self.pro_code = self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name
|
||||
# 外协出库单,从“正在等待”变为“就绪”状态
|
||||
if self.is_subcontract is True:
|
||||
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
|
||||
if picking_out.state == 'confirmed':
|
||||
picking_out.write({'state': 'assigned'})
|
||||
if self.state == 'waiting' or self.state == 'ready' or self.state == 'progress':
|
||||
self.move_raw_ids = self.production_id.move_raw_ids
|
||||
self.move_raw_ids[0].write({
|
||||
'materiel_length': self.move_raw_ids[0].product_id.length,
|
||||
'materiel_width': self.move_raw_ids[0].product_id.width,
|
||||
'materiel_height': self.move_raw_ids[0].product_id.height
|
||||
})
|
||||
|
||||
# 维修模块按钮
|
||||
def button_maintenance_req(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': _('New Maintenance Request'),
|
||||
'view_mode': 'form',
|
||||
'views': [(self.env.ref('mrp_maintenance.maintenance_request_view_form_inherit_mrp').id, 'form')],
|
||||
'res_model': 'maintenance.request',
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': {
|
||||
'default_company_id': self.company_id.id,
|
||||
'default_workorder_id': self.id,
|
||||
'default_production_id': self.production_id.id,
|
||||
'discard_on_footer_button': True,
|
||||
},
|
||||
'target': 'new',
|
||||
'domain': [('workorder_id', '=', self.id)]
|
||||
}
|
||||
if any(not time.date_end for time in self.time_ids.filtered(lambda t: t.user_id.id == self.env.user.id)):
|
||||
return True
|
||||
# As button_start is automatically called in the new view
|
||||
if self.state in ('done', 'cancel'):
|
||||
return True
|
||||
|
||||
# tray_id = fields.Many2one('sf.tray', string="托盘信息", tracking=True)
|
||||
|
||||
# 扫码绑定托盘方法
|
||||
|
||||
# def gettray(self):
|
||||
# if self.tray_code != False:
|
||||
# values = self.env['sf.tray'].search([("code", "=", self.tray_code)])
|
||||
# if values:
|
||||
# if values.state == "占用":
|
||||
# raise UserError('该托盘已占用')
|
||||
# if values.state == "报损":
|
||||
# raise UserError('该托盘已损坏')
|
||||
# else:
|
||||
# values.update({
|
||||
# 'workorder_id': self,
|
||||
# 'production_id': self.production_id,
|
||||
# 'state': '占用',
|
||||
# })
|
||||
# self.work_state = "已绑定"
|
||||
# orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
|
||||
# for a in orders:
|
||||
# a.tray_id = values
|
||||
# else:
|
||||
# raise UserError('该托盘编码已失效')
|
||||
# else:
|
||||
# raise UserError('托盘码不能为空')
|
||||
|
||||
# 验证坯料序列号是否正确
|
||||
def pro_code_is_ok(self, barcode):
|
||||
if barcode is not False:
|
||||
if barcode != self.pro_code:
|
||||
raise UserError('坯料序列号错误')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
pro_code = fields.Char(string='坯料序列号')
|
||||
|
||||
pro_code_ok = fields.Boolean(default=False)
|
||||
|
||||
# 托盘扫码绑定
|
||||
# def gettray_auto(self, barcode):
|
||||
# if barcode != False:
|
||||
# values = self.env['sf.tray'].search([("code", "=", barcode)])
|
||||
#
|
||||
# if values:
|
||||
# if values.state == "占用":
|
||||
# raise UserError('该托盘已占用')
|
||||
# if values.state == "报损":
|
||||
# raise UserError('该托盘已损坏')
|
||||
# else:
|
||||
# values.update({
|
||||
# 'workorder_id': self,
|
||||
# 'production_id': self.production_id,
|
||||
# 'state': '占用',
|
||||
# })
|
||||
# self.work_state = "已绑定"
|
||||
# orders = self.env['mrp.workorder'].search([('production_id', '=', self.production_id.id)])
|
||||
# for a in orders:
|
||||
# a.tray_id = values
|
||||
#
|
||||
# return values
|
||||
#
|
||||
# # return {
|
||||
# # 'name': _('New Maintenance Request'),
|
||||
# # 'view_mode': 'form',
|
||||
# # 'res_model': 'maintenance.request',
|
||||
# # 'type': 'ir.actions.act_window',
|
||||
# # 'context': {
|
||||
# # 'default_company_id': self.company_id.id,
|
||||
# # 'default_production_id': self.id,
|
||||
# # },
|
||||
# # 'domain': [('production_id', '=', self.id)],
|
||||
# # }
|
||||
# else:
|
||||
# raise UserError('该托盘编码已失效')
|
||||
# else:
|
||||
# raise UserError('托盘码不能为空')
|
||||
|
||||
# 解除托盘绑定
|
||||
# def unbindtray(self):
|
||||
# tray = self.env['sf.tray'].search([("production_id", "=", self.production_id.id)])
|
||||
# if tray:
|
||||
# tray.unclamp()
|
||||
# self.tray_id = False
|
||||
|
||||
# return {
|
||||
# 'name': _('New Maintenance Request'),
|
||||
# 'view_mode': 'form',
|
||||
# 'res_model': 'maintenance.request',
|
||||
# 'res_id':self.id,
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# 'context': {
|
||||
# 'default_company_id': self.company_id.id,
|
||||
# 'default_production_id': self.id,
|
||||
# },
|
||||
# 'domain': [('production_id', '=', self.id)],
|
||||
# 'target':'new'
|
||||
# }
|
||||
|
||||
def recreateManufacturingOrWorkerOrder(self):
|
||||
"""
|
||||
重新生成制造订单或者重新生成工单
|
||||
"""
|
||||
if self.test_results == '报废':
|
||||
values = self.env['mrp.production'].create_production1_values(self.production_id)
|
||||
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
|
||||
self.production_id.company_id).create(
|
||||
values)
|
||||
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
productions._create_workorder()
|
||||
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
|
||||
(
|
||||
p.move_dest_ids.procure_method != 'make_to_order' and
|
||||
not p.move_raw_ids and not p.workorder_ids)).action_confirm()
|
||||
|
||||
for production in productions:
|
||||
origin_production = production.move_dest_ids and production.move_dest_ids[
|
||||
0].raw_material_production_id or False
|
||||
orderpoint = production.orderpoint_id
|
||||
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
|
||||
production.message_post(
|
||||
body=_('This production order has been created from Replenishment Report.'),
|
||||
message_type='comment',
|
||||
subtype_xmlid='mail.mt_note')
|
||||
elif orderpoint:
|
||||
production.message_post_with_view(
|
||||
'mail.message_origin_link',
|
||||
values={'self': production, 'origin': orderpoint},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
elif origin_production:
|
||||
production.message_post_with_view(
|
||||
'mail.message_origin_link',
|
||||
values={'self': production, 'origin': origin_production},
|
||||
subtype_id=self.env.ref('mail.mt_note').id)
|
||||
if self.test_results == '返工':
|
||||
productions = self.production_id
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
|
||||
# self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
|
||||
productions._create_workorder2(self.processing_panel)
|
||||
if self.product_tracking == 'serial':
|
||||
self.qty_producing = 1.0
|
||||
else:
|
||||
self.results = '合格'
|
||||
self.qty_producing = self.qty_remaining
|
||||
|
||||
def json_workorder_str1(self, k, production, route):
|
||||
workorders_values_str = [0, '', {
|
||||
'product_uom_id': production.product_uom_id.id,
|
||||
'qty_producing': 0,
|
||||
'operation_id': False,
|
||||
'name': '%s(返工)' % route.route_workcenter_id.name,
|
||||
'processing_panel': k,
|
||||
'routing_type': route.routing_type,
|
||||
'work_state': '' if not route.routing_type == '获取CNC加工程序' else '待发起',
|
||||
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
|
||||
route.routing_type,
|
||||
production.product_id),
|
||||
'date_planned_start': False,
|
||||
'date_planned_finished': False,
|
||||
'duration_expected': 60,
|
||||
'duration': 0,
|
||||
|
||||
}]
|
||||
return workorders_values_str
|
||||
|
||||
# 重写工单开始按钮方法
|
||||
def button_start(self):
|
||||
if self.routing_type == '装夹预调' and self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name:
|
||||
self.pro_code = self.production_id.move_raw_ids[0].move_line_ids[0].lot_id.name
|
||||
# 外协出库单,从“正在等待”变为“就绪”状态
|
||||
if self.is_subcontract is True:
|
||||
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
|
||||
if picking_out.state == 'confirmed':
|
||||
picking_out.write({'state': 'assigned'})
|
||||
if self.state == 'waiting' or self.state == 'ready' or self.state == 'progress':
|
||||
self.move_raw_ids = self.production_id.move_raw_ids
|
||||
self.move_raw_ids[0].write({
|
||||
'materiel_length': self.move_raw_ids[0].product_id.length,
|
||||
'materiel_width': self.move_raw_ids[0].product_id.width,
|
||||
'materiel_height': self.move_raw_ids[0].product_id.height
|
||||
self.env['mrp.workcenter.productivity'].create(
|
||||
self._prepare_timeline_vals(self.duration, datetime.now())
|
||||
)
|
||||
if self.production_id.state != 'progress':
|
||||
self.production_id.write({
|
||||
'date_start': datetime.now(),
|
||||
})
|
||||
|
||||
self.ensure_one()
|
||||
if any(not time.date_end for time in self.time_ids.filtered(lambda t: t.user_id.id == self.env.user.id)):
|
||||
return True
|
||||
# As button_start is automatically called in the new view
|
||||
if self.state in ('done', 'cancel'):
|
||||
return True
|
||||
|
||||
if self.product_tracking == 'serial':
|
||||
self.qty_producing = 1.0
|
||||
else:
|
||||
self.qty_producing = self.qty_remaining
|
||||
|
||||
self.env['mrp.workcenter.productivity'].create(
|
||||
self._prepare_timeline_vals(self.duration, datetime.now())
|
||||
)
|
||||
if self.production_id.state != 'progress':
|
||||
self.production_id.write({
|
||||
'date_start': datetime.now(),
|
||||
})
|
||||
if self.state == 'progress':
|
||||
return True
|
||||
start_date = datetime.now()
|
||||
vals = {
|
||||
'state': 'progress',
|
||||
'date_start': start_date,
|
||||
}
|
||||
if not self.leave_id:
|
||||
leave = self.env['resource.calendar.leaves'].create({
|
||||
'name': self.display_name,
|
||||
'calendar_id': self.workcenter_id.resource_calendar_id.id,
|
||||
'date_from': start_date,
|
||||
'date_to': start_date + relativedelta(minutes=self.duration_expected),
|
||||
'resource_id': self.workcenter_id.resource_id.id,
|
||||
'time_type': 'other'
|
||||
})
|
||||
vals['leave_id'] = leave.id
|
||||
return self.write(vals)
|
||||
else:
|
||||
if self.date_planned_start > start_date:
|
||||
vals['date_planned_start'] = start_date
|
||||
if self.date_planned_finished and self.date_planned_finished < start_date:
|
||||
vals['date_planned_finished'] = start_date
|
||||
return self.write(vals)
|
||||
if self.state == 'progress':
|
||||
return True
|
||||
start_date = datetime.now()
|
||||
vals = {
|
||||
'state': 'progress',
|
||||
'date_start': start_date,
|
||||
}
|
||||
if not self.leave_id:
|
||||
leave = self.env['resource.calendar.leaves'].create({
|
||||
'name': self.display_name,
|
||||
'calendar_id': self.workcenter_id.resource_calendar_id.id,
|
||||
'date_from': start_date,
|
||||
'date_to': start_date + relativedelta(minutes=self.duration_expected),
|
||||
'resource_id': self.workcenter_id.resource_id.id,
|
||||
'time_type': 'other'
|
||||
})
|
||||
vals['leave_id'] = leave.id
|
||||
return self.write(vals)
|
||||
else:
|
||||
raise UserError(_('请先完成上一步工单'))
|
||||
if self.date_planned_start > start_date:
|
||||
vals['date_planned_start'] = start_date
|
||||
if self.date_planned_finished and self.date_planned_finished < start_date:
|
||||
vals['date_planned_finished'] = start_date
|
||||
return self.write(vals)
|
||||
else:
|
||||
raise UserError(_('请先完成上一步工单'))
|
||||
|
||||
def button_finish(self):
|
||||
if self.routing_type == '装夹预调':
|
||||
if not self.material_center_point and self.X_deviation_angle > 0:
|
||||
raise UserError("请对前置三元检测定位参数进行计算定位")
|
||||
if not self.rfid_code:
|
||||
raise UserError("请扫RFID码进行绑定")
|
||||
if self.picking_out_id:
|
||||
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
|
||||
if picking_out.workorder_out_id:
|
||||
order_line_ids = []
|
||||
for item in picking_out.workorder_out_id:
|
||||
server_product = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
|
||||
('detailed_type', '=', 'service')])
|
||||
if server_product:
|
||||
order_line_ids.append((0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': 1,
|
||||
'product_uom': server_product.uom_id.id
|
||||
}))
|
||||
else:
|
||||
raise UserError(
|
||||
'请先在产品中配置表面工艺为%s相关的外协服务产品' % item.surface_technics_parameters_id.name)
|
||||
self.env['purchase.order'].create({
|
||||
'partner_id': server_product.seller_ids.partner_id.id,
|
||||
'state': 'draft',
|
||||
'order_line': order_line_ids,
|
||||
})
|
||||
super().button_finish()
|
||||
is_production_id = True
|
||||
|
||||
def button_finish(self):
|
||||
if self.routing_type == '装夹预调':
|
||||
if not self.material_center_point and self.X_deviation_angle > 0:
|
||||
raise UserError("请对前置三元检测定位参数进行计算定位")
|
||||
if not self.rfid_code:
|
||||
raise UserError("请扫RFID码进行绑定")
|
||||
if self.picking_out_id:
|
||||
picking_out = self.env['stock.picking'].search([('id', '=', self.picking_out_id.id)])
|
||||
if picking_out.workorder_out_id:
|
||||
order_line_ids = []
|
||||
for item in picking_out.workorder_out_id:
|
||||
server_product = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', item.surface_technics_parameters_id.id),
|
||||
('detailed_type', '=', 'service')])
|
||||
if server_product:
|
||||
order_line_ids.append((0, 0, {
|
||||
'product_id': server_product.product_variant_id.id,
|
||||
'product_qty': 1,
|
||||
'product_uom': server_product.uom_id.id
|
||||
}))
|
||||
else:
|
||||
raise UserError(
|
||||
'请先在产品中配置表面工艺为%s相关的外协服务产品' % item.surface_technics_parameters_id.name)
|
||||
self.env['purchase.order'].create({
|
||||
'partner_id': server_product.seller_ids.partner_id.id,
|
||||
'state': 'draft',
|
||||
'order_line': order_line_ids,
|
||||
})
|
||||
super().button_finish()
|
||||
is_production_id = True
|
||||
for workorder in self.production_id.workorder_ids:
|
||||
if workorder.state != 'done':
|
||||
is_production_id = False
|
||||
if is_production_id == True and self.name == '解除装夹':
|
||||
for workorder in self.production_id.workorder_ids:
|
||||
if workorder.state != 'done':
|
||||
is_production_id = False
|
||||
if is_production_id == True and self.name == '解除装夹':
|
||||
for workorder in self.production_id.workorder_ids:
|
||||
workorder.rfid_code_old = workorder.rfid_code
|
||||
workorder.rfid_code = None
|
||||
for move_raw_id in self.production_id.move_raw_ids:
|
||||
move_raw_id.quantity_done = move_raw_id.product_uom_qty
|
||||
self.production_id.button_mark_done1()
|
||||
# self.production_id.state = 'done'
|
||||
workorder.rfid_code_old = workorder.rfid_code
|
||||
workorder.rfid_code = None
|
||||
for move_raw_id in self.production_id.move_raw_ids:
|
||||
move_raw_id.quantity_done = move_raw_id.product_uom_qty
|
||||
self.production_id.button_mark_done1()
|
||||
# self.production_id.state = 'done'
|
||||
|
||||
# 将FTP的检测报告文件下载到临时目录
|
||||
def download_reportfile_tmp(self, workorder, reportpath):
|
||||
logging.info('reportpath:%s' % reportpath)
|
||||
production_no_ftp = reportpath.split('/')
|
||||
production_no = workorder.production_id.name.replace('/', '_')
|
||||
# ftp地址
|
||||
remotepath = os.path.join('/NC', production_no_ftp[1], 'detection')
|
||||
logging.info('ftp地址:%s' % remotepath)
|
||||
if reportpath.find(production_no) != -1:
|
||||
# 服务器内临时地址
|
||||
serverdir = os.path.join('/tmp', production_no_ftp[1], 'detection')
|
||||
ftp_resconfig = self.env['res.config.settings'].get_values()
|
||||
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']),
|
||||
ftp_resconfig['ftp_user'],
|
||||
ftp_resconfig['ftp_password'])
|
||||
download_state = ftp.download_reportfile_tree(remotepath, serverdir, reportpath)
|
||||
logging.info('download_state:%s' % download_state)
|
||||
else:
|
||||
download_state = 2
|
||||
return download_state
|
||||
|
||||
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
|
||||
def get_detection_file(self, workorder, reportPath):
|
||||
if reportPath.startswith('/'):
|
||||
reportPath = reportPath[1:]
|
||||
serverdir = os.path.join('/tmp', reportPath)
|
||||
logging.info('get_detection_file-serverdir:%s' % serverdir)
|
||||
serverdir_prefix = os.path.dirname(serverdir)
|
||||
for root, dirs, files in os.walk(serverdir_prefix):
|
||||
for filename in files:
|
||||
if filename == os.path.basename(reportPath):
|
||||
report_file_path = os.path.join(root, filename)
|
||||
logging.info('get_detection_file-report_file_path:%s' % report_file_path)
|
||||
workorder.detection_report = base64.b64encode(open(report_file_path, 'rb').read())
|
||||
return True
|
||||
# 将FTP的检测报告文件下载到临时目录
|
||||
def download_reportfile_tmp(self, workorder, reportpath):
|
||||
logging.info('reportpath:%s' % reportpath)
|
||||
production_no_ftp = reportpath.split('/')
|
||||
production_no = workorder.production_id.name.replace('/', '_')
|
||||
# ftp地址
|
||||
remotepath = os.path.join('/NC', production_no_ftp[1], 'detection')
|
||||
logging.info('ftp地址:%s' % remotepath)
|
||||
if reportpath.find(production_no) != -1:
|
||||
# 服务器内临时地址
|
||||
serverdir = os.path.join('/tmp', production_no_ftp[1], 'detection')
|
||||
ftp_resconfig = self.env['res.config.settings'].get_values()
|
||||
ftp = FtpController(str(ftp_resconfig['ftp_host']), int(ftp_resconfig['ftp_port']),
|
||||
ftp_resconfig['ftp_user'],
|
||||
ftp_resconfig['ftp_password'])
|
||||
download_state = ftp.download_reportfile_tree(remotepath, serverdir, reportpath)
|
||||
logging.info('download_state:%s' % download_state)
|
||||
else:
|
||||
download_state = 2
|
||||
return download_state
|
||||
|
||||
|
||||
# 根据中控系统提供的检测文件地址去ftp里对应的制造订单里获取
|
||||
def get_detection_file(self, workorder, reportPath):
|
||||
if reportPath.startswith('/'):
|
||||
reportPath = reportPath[1:]
|
||||
serverdir = os.path.join('/tmp', reportPath)
|
||||
logging.info('get_detection_file-serverdir:%s' % serverdir)
|
||||
serverdir_prefix = os.path.dirname(serverdir)
|
||||
for root, dirs, files in os.walk(serverdir_prefix):
|
||||
for filename in files:
|
||||
if filename == os.path.basename(reportPath):
|
||||
report_file_path = os.path.join(root, filename)
|
||||
logging.info('get_detection_file-report_file_path:%s' % report_file_path)
|
||||
workorder.detection_report = base64.b64encode(open(report_file_path, 'rb').read())
|
||||
return True
|
||||
|
||||
|
||||
class CNCprocessing(models.Model):
|
||||
@@ -1084,6 +1100,8 @@ class WorkPieceDelivery(models.Model):
|
||||
feeder_station_destination_id = fields.Many2one('sf.agv.site', '目的接驳站')
|
||||
task_delivery_time = fields.Datetime('任务下发时间')
|
||||
task_completion_time = fields.Datetime('任务完成时间')
|
||||
type = fields.Selection(
|
||||
[('上产线', '上产线'), ('下产线', '下产线'), ('运送空料架', '运送空料架')], string='类型')
|
||||
delivery_duration = fields.Float('配送时长', compute='_compute_delivery_duration')
|
||||
status = fields.Selection(
|
||||
[('待下发', '待下发'), ('待配送', '待配送'), ('已配送', '已配送')], string='状态',
|
||||
@@ -1124,6 +1142,9 @@ class WorkPieceDelivery(models.Model):
|
||||
|
||||
# 配送至avg小车
|
||||
def _delivery_avg(self):
|
||||
agv_site = self.env['sf.agv.site'].search([])
|
||||
if agv_site:
|
||||
agv_site.update_site_state()
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
positionCode_Arr = []
|
||||
if self.feeder_station_start_id:
|
||||
@@ -1143,7 +1164,7 @@ class WorkPieceDelivery(models.Model):
|
||||
'podDir': '', 'materialLot': '', 'priority': '', 'taskCode': '', 'agvCode': '', 'materialLot': '',
|
||||
'data': ''}
|
||||
try:
|
||||
config['agv_rcs_url'] = 'http://172.16.10.114:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask'
|
||||
# config['agv_rcs_url'] = 'http://172.16.10.114:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask'
|
||||
logging.info('AGV请求路径:%s' % config['agv_rcs_url'])
|
||||
logging.info('AGV-json:%s' % res)
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
@@ -7,8 +7,8 @@ import os
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.modules import get_resource_path
|
||||
# from OCC.Extend.DataExchange import read_step_file
|
||||
# from OCC.Extend.DataExchange import write_stl_file
|
||||
from OCC.Extend.DataExchange import read_step_file
|
||||
from OCC.Extend.DataExchange import write_stl_file
|
||||
|
||||
|
||||
class ResProductMo(models.Model):
|
||||
|
||||
@@ -5,18 +5,11 @@
|
||||
<field name="model">sf.workpiece.delivery.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<field name="delivery_id" invisible="True"/>
|
||||
<field name="workorder_id" invisible="True"/>
|
||||
<field name="route_id" required="1" options="{'no_create': True}"/>
|
||||
</group>
|
||||
<div>
|
||||
<field name="is_ok"/>
|
||||
确认上述信息正确无误.
|
||||
</div>
|
||||
<div>是否确定配送?</div>
|
||||
<footer>
|
||||
<button string="确认配送" name="confirm" type="object" class="oe_highlight"
|
||||
attrs="{'invisible':[('is_ok','=',False)]}"/>
|
||||
<button string="确认" name="confirm" type="object" class="oe_highlight"/>
|
||||
<button string="取消" class="btn btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
@@ -11,8 +11,6 @@ class WorkpieceDeliveryWizard(models.TransientModel):
|
||||
|
||||
delivery_id = fields.Many2one('sf.workpiece.delivery', string='配送')
|
||||
workorder_id = fields.Many2one('mrp.workorder', string='工单')
|
||||
route_id = fields.Many2one('sf.agv.task.route', '任务路线')
|
||||
is_ok = fields.Boolean('确认上述信息正确无误.')
|
||||
|
||||
def confirm(self):
|
||||
if self.workorder_id:
|
||||
|
||||
@@ -17,6 +17,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
default='http://172.16.10.114:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask')
|
||||
center_control_url = fields.Char(string='中控访问地址',
|
||||
default='http://172.16.21.50:8001')
|
||||
center_control_Authorization = fields.Char(string='中控访问认证')
|
||||
wbcode = fields.Char('地码')
|
||||
agv_code = fields.Char(string='agv编号')
|
||||
task_type_no = fields.Char('任务单类型编号')
|
||||
@@ -102,6 +103,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
wbcode = config.get_param('wbcode', default='')
|
||||
agv_code = config.get_param('agv_code', default='')
|
||||
center_control_url = config.get_param('center_control_url', default='')
|
||||
center_control_Authorization = config.get_param('center_control_Authorization', default='')
|
||||
ftp_host = config.get_param('ftp_host', default='')
|
||||
ftp_port = config.get_param('ftp_port', default='')
|
||||
ftp_user = config.get_param('ftp_user', default='')
|
||||
@@ -115,6 +117,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
wbcode=wbcode,
|
||||
agv_code=agv_code,
|
||||
center_control_url=center_control_url,
|
||||
center_control_Authorization=center_control_Authorization,
|
||||
ftp_host=ftp_host,
|
||||
ftp_port=ftp_port,
|
||||
ftp_user=ftp_user,
|
||||
@@ -132,6 +135,7 @@ class ResConfigSettings(models.TransientModel):
|
||||
ir_config.set_param("wbcode", self.wbcode or "")
|
||||
ir_config.set_param("agv_code", self.agv_code or "")
|
||||
ir_config.set_param("center_control_url", self.center_control_url or "")
|
||||
ir_config.set_param("center_control_Authorization", self.center_control_Authorization or "")
|
||||
ir_config.set_param("ftp_host", self.ftp_host or "")
|
||||
ir_config.set_param("ftp_port", self.ftp_port or "")
|
||||
ir_config.set_param("ftp_user", self.ftp_user or "")
|
||||
|
||||
@@ -106,6 +106,10 @@
|
||||
<label for="center_control_url" string="访问地址"/>
|
||||
<field name="center_control_url"/>
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
<label for="center_control_Authorization" string="身份认证"/>
|
||||
<field name="center_control_Authorization"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,8 +8,8 @@ from datetime import datetime
|
||||
import requests
|
||||
from odoo import http
|
||||
from odoo.http import request
|
||||
# from OCC.Extend.DataExchange import read_step_file
|
||||
# from OCC.Extend.DataExchange import write_stl_file
|
||||
from OCC.Extend.DataExchange import read_step_file
|
||||
from OCC.Extend.DataExchange import write_stl_file
|
||||
from odoo import models, fields, api
|
||||
from odoo.modules import get_resource_path
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
@@ -6,8 +6,8 @@ import os
|
||||
from datetime import datetime
|
||||
from stl import mesh
|
||||
# from OCC.Core.GProp import GProp_GProps
|
||||
# from OCC.Extend.DataExchange import read_step_file
|
||||
# from OCC.Extend.DataExchange import write_stl_file
|
||||
from OCC.Extend.DataExchange import read_step_file
|
||||
from OCC.Extend.DataExchange import write_stl_file
|
||||
from odoo.addons.sf_base.commons.common import Common
|
||||
from odoo import models, fields, api
|
||||
from odoo.modules import get_resource_path
|
||||
|
||||
@@ -43,12 +43,10 @@ class SfMaintenanceEquipment(models.Model):
|
||||
|
||||
# ==========机床当前刀库实时信息接口==========
|
||||
def register_equipment_tool(self):
|
||||
# sf_sync_config = self.env['res.config.settings'].get_values()
|
||||
# token = sf_sync_config['token']
|
||||
# sf_secret_key = sf_sync_config['sf_secret_key']
|
||||
# headers = Common.get_headers(self, token, sf_secret_key)
|
||||
headers = {'Authorization': 'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A'}
|
||||
crea_url = "https://x24467i973.zicp.fun/AutoDeviceApi/GetToolInfos"
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
# token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A]
|
||||
headers = {'Authorization': config['center_control_Authorization']}
|
||||
crea_url = config['center_control_url'] + "/AutoDeviceApi/GetToolInfos"
|
||||
params = {"DeviceId": self.name}
|
||||
r = requests.get(crea_url, params=params, headers=headers)
|
||||
ret = r.json()
|
||||
|
||||
Reference in New Issue
Block a user