108 lines
5.1 KiB
Python
108 lines
5.1 KiB
Python
import json
|
||
import requests
|
||
import logging
|
||
from odoo import fields, models, api
|
||
from odoo.exceptions import ValidationError
|
||
from datetime import datetime
|
||
from odoo.addons.sf_base.commons.common import Common
|
||
|
||
|
||
class QualityCheck(models.Model):
|
||
_inherit = "quality.check"
|
||
|
||
quality_state = fields.Selection([
|
||
('waiting', '等待'),
|
||
('none', '待处理'),
|
||
('pass', '通过的'),
|
||
('fail', '失败的')], string='状态', tracking=True, store=True,
|
||
default='none', copy=False, compute='_compute_quality_state')
|
||
|
||
processing_panel = fields.Char(related='workorder_id.processing_panel', string='加工面')
|
||
|
||
production_line_id = fields.Many2one(related='workorder_id.production_line_id',
|
||
string='生产线')
|
||
equipment_id = fields.Many2one(related='workorder_id.equipment_id', string='加工设备')
|
||
model_file = fields.Binary(related='workorder_id.glb_file', string='加工模型')
|
||
|
||
detection_report = fields.Binary(related='workorder_id.detection_report', readonly=True, string='检测报告')
|
||
test_results = fields.Selection([("合格", "合格"), ("返工", "返工"), ("报废", "报废")], string="检测结果",
|
||
default='合格')
|
||
reason = fields.Selection(
|
||
[("programming", "编程"), ("cutter", "刀具"), ("clamping", "装夹"), ("operate computer", "操机"),
|
||
("technology", "工艺"), ("customer redrawing", "客户改图")], string="原因")
|
||
detailed_reason = fields.Text('详细原因')
|
||
machining_drawings = fields.Binary('2D加工图纸', related='workorder_id.machining_drawings')
|
||
quality_standard = fields.Binary('质检标准', related='workorder_id.quality_standard')
|
||
|
||
operation_id = fields.Many2one('mrp.routing.workcenter', '作业', store=True, compute='_compute_operation_id')
|
||
is_inspect = fields.Boolean('需送检', related='point_id.is_inspect')
|
||
|
||
@api.depends('point_id.operation_id')
|
||
def _compute_operation_id(self):
|
||
for qc in self:
|
||
if qc.point_id.operation_id:
|
||
qc.operation_id = qc.point_id.operation_id.id
|
||
|
||
@api.depends('point_id.is_inspect')
|
||
def _compute_quality_state(self):
|
||
for qc in self:
|
||
if qc.point_id.is_inspect and qc.quality_state == 'none':
|
||
qc.quality_state = 'waiting'
|
||
elif not qc.point_id.is_inspect and qc.quality_state == 'waiting':
|
||
qc.quality_state = 'none'
|
||
|
||
@api.onchange('test_results')
|
||
def _onchange_test_results(self):
|
||
if self.test_results == '合格':
|
||
self.reason = False
|
||
self.detailed_reason = False
|
||
|
||
def do_pass(self):
|
||
self.ensure_one()
|
||
super().do_pass()
|
||
if self.workorder_id:
|
||
# 1)将页签“判定结果”的检测结果值同步到【工单_后置三元检测_检测结果】
|
||
if self.test_results in ['返工', '报废']:
|
||
raise ValidationError('请重新选择【判定结果】-【检测结果】')
|
||
if self.workorder_id.state not in ['done']:
|
||
self.workorder_id.write({'test_results': '合格'})
|
||
# 2)将关联的工单状态更新为“已完成”
|
||
self.workorder_id.button_finish()
|
||
|
||
def do_fail(self):
|
||
self.ensure_one()
|
||
super().do_fail()
|
||
if self.workorder_id:
|
||
# 1)将页签“判定结果”的检测结果值同步到【工单_后置三元检测_检测结果】
|
||
if not self.test_results:
|
||
raise ValidationError('请填写【判定结果】里的信息')
|
||
if self.test_results == '合格':
|
||
raise ValidationError('请重新选择【判定结果】-【检测结果】')
|
||
if self.workorder_id.state not in ['done']:
|
||
self.workorder_id.write(
|
||
{'test_results': self.test_results, 'reason': self.reason, 'detailed_reason': self.detailed_reason})
|
||
# 2)将关联的工单状态更新为“已完成”
|
||
self.workorder_id.button_finish()
|
||
|
||
# ==========零件特采接口==========
|
||
def _register_quality_check(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']}
|
||
crea_url = config['center_control_url'] + "/AutoDeviceApi/PartSpecProc"
|
||
origin = self.picking_id.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 ''
|
||
val = [rfid]
|
||
# todo 需修改
|
||
val = ['0037818516']
|
||
logging.info('获取到的工单信息%s' % val)
|
||
r = requests.post(crea_url, json=val, headers=headers)
|
||
ret = r.json()
|
||
logging.info('_register_quality_check:%s' % ret)
|
||
if ret['Succeed']:
|
||
return "零件特采发送成功"
|
||
else:
|
||
raise ValidationError("零件特采发送失败")
|
||
|