1、接口优化
This commit is contained in:
@@ -470,365 +470,355 @@ class ResMrpWorkOrder(models.Model):
|
|||||||
[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 _json_workorder_surface_process_str(self, production, route, process_parameter, supplier_id):
|
def button_maintenance_req(self):
|
||||||
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
|
|
||||||
})
|
|
||||||
|
|
||||||
self.ensure_one()
|
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 {
|
||||||
return True
|
'name': _('New Maintenance Request'),
|
||||||
# As button_start is automatically called in the new view
|
'view_mode': 'form',
|
||||||
if self.state in ('done', 'cancel'):
|
'views': [(self.env.ref('mrp_maintenance.maintenance_request_view_form_inherit_mrp').id, 'form')],
|
||||||
return True
|
'res_model': 'maintenance.request',
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
if self.product_tracking == 'serial':
|
'context': {
|
||||||
self.qty_producing = 1.0
|
'default_company_id': self.company_id.id,
|
||||||
else:
|
'default_workorder_id': self.id,
|
||||||
self.qty_producing = self.qty_remaining
|
'default_production_id': self.production_id.id,
|
||||||
|
'discard_on_footer_button': True,
|
||||||
self.env['mrp.workcenter.productivity'].create(
|
},
|
||||||
self._prepare_timeline_vals(self.duration, datetime.now())
|
'target': 'new',
|
||||||
)
|
'domain': [('workorder_id', '=', self.id)]
|
||||||
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)
|
|
||||||
else:
|
|
||||||
raise UserError(_('请先完成上一步工单'))
|
|
||||||
|
|
||||||
|
# tray_id = fields.Many2one('sf.tray', string="托盘信息", tracking=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:
|
|
||||||
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'
|
|
||||||
|
|
||||||
|
# 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('托盘码不能为空')
|
||||||
|
|
||||||
# 将FTP的检测报告文件下载到临时目录
|
# 验证坯料序列号是否正确
|
||||||
def download_reportfile_tmp(self, workorder, reportpath):
|
def pro_code_is_ok(self, barcode):
|
||||||
logging.info('reportpath:%s' % reportpath)
|
if barcode is not False:
|
||||||
production_no_ftp = reportpath.split('/')
|
if barcode != self.pro_code:
|
||||||
production_no = workorder.production_id.name.replace('/', '_')
|
raise UserError('坯料序列号错误')
|
||||||
# ftp地址
|
return False
|
||||||
remotepath = os.path.join('/NC', production_no_ftp[1], 'detection')
|
else:
|
||||||
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
|
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
|
||||||
|
})
|
||||||
|
|
||||||
|
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)
|
||||||
|
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
|
||||||
|
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'
|
||||||
|
|
||||||
|
# 将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):
|
class CNCprocessing(models.Model):
|
||||||
_name = 'sf.cnc.processing'
|
_name = 'sf.cnc.processing'
|
||||||
|
|||||||
@@ -12,13 +12,10 @@ class QualityCheck(models.Model):
|
|||||||
|
|
||||||
# ==========零件特采接口==========
|
# ==========零件特采接口==========
|
||||||
def _register_quality_check(self):
|
def _register_quality_check(self):
|
||||||
# create_url = '/AutoDeviceApi/PartSpecProc'
|
config = self.env['res.config.settings'].get_values()
|
||||||
# sf_sync_config = self.env['res.config.settings'].get_values()
|
# token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A]
|
||||||
# token = sf_sync_config['token']
|
headers = {'Authorization': config['center_control_Authorization']}
|
||||||
# sf_secret_key = sf_sync_config['sf_secret_key']
|
crea_url = config['center_control_url'] + "/AutoDeviceApi/GetToolInfos"
|
||||||
# headers = Common.get_headers(self, token, sf_secret_key)
|
|
||||||
headers = {'Authorization': 'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A'}
|
|
||||||
crea_url = "https://x24467i973.zicp.fun/AutoDeviceApi/PartSpecProc"
|
|
||||||
origin = self.picking_id.origin
|
origin = self.picking_id.origin
|
||||||
production_id = self.env['mrp.production'].sudo().search([('name', '=', origin)])
|
production_id = self.env['mrp.production'].sudo().search([('name', '=', origin)])
|
||||||
rfid = '' if not production_id.workorder_ids else production_id.workorder_ids[-1].rfid_code or ''
|
rfid = '' if not production_id.workorder_ids else production_id.workorder_ids[-1].rfid_code or ''
|
||||||
|
|||||||
@@ -12,18 +12,16 @@ class CNCprocessing(models.Model):
|
|||||||
|
|
||||||
# ==========MES装刀指令接口==========
|
# ==========MES装刀指令接口==========
|
||||||
def register_cnc_processing(self, knife_plan):
|
def register_cnc_processing(self, knife_plan):
|
||||||
# sf_sync_config = self.env['res.config.settings'].get_values()
|
config = self.env['res.config.settings'].get_values()
|
||||||
# token = sf_sync_config['token']
|
# token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A]
|
||||||
# sf_secret_key = sf_sync_config['sf_secret_key']
|
headers = {'Authorization': config['center_control_Authorization']}
|
||||||
# headers = Common.get_headers(self, token, sf_secret_key)
|
crea_url = config['center_control_url'] + "/AutoDeviceApi/GetToolInfos"
|
||||||
headers = {'Authorization': 'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A'}
|
|
||||||
strurl = "https://x24467i973.zicp.fun/AutoDeviceApi/ToolLoadInstruct"
|
|
||||||
val = {
|
val = {
|
||||||
'DeviceId': knife_plan.machine_table_name,
|
'DeviceId': knife_plan.machine_table_name,
|
||||||
'RfidCode': knife_plan.sf_functional_tool_assembly_id.rfid,
|
'RfidCode': knife_plan.sf_functional_tool_assembly_id.rfid,
|
||||||
'ToolId': int(knife_plan.cutter_spacing_code_id.code[1:])
|
'ToolId': int(knife_plan.cutter_spacing_code_id.code[1:])
|
||||||
}
|
}
|
||||||
r = requests.post(strurl, json=val, headers=headers)
|
r = requests.post(crea_url, json=val, headers=headers)
|
||||||
ret = r.json()
|
ret = r.json()
|
||||||
logging.info('register_cnc_processing:%s' % ret)
|
logging.info('register_cnc_processing:%s' % ret)
|
||||||
if ret['Succeed']:
|
if ret['Succeed']:
|
||||||
|
|||||||
Reference in New Issue
Block a user