工单异常处理
This commit is contained in:
4
jikimo_workorder_exception/__init__.py
Normal file
4
jikimo_workorder_exception/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from . import models
|
||||||
|
from . import controllers
|
||||||
22
jikimo_workorder_exception/__manifest__.py
Normal file
22
jikimo_workorder_exception/__manifest__.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||||
|
{
|
||||||
|
'name': '机企猫 工单异常记录',
|
||||||
|
'version': '1.0',
|
||||||
|
'summary': '记录工单的异常日志',
|
||||||
|
'sequence': 1,
|
||||||
|
'category': 'sf',
|
||||||
|
'website': 'https://www.sf.jikimo.com',
|
||||||
|
'depends': ['sf_manufacturing', 'sf_mrs_connect'],
|
||||||
|
'data': [
|
||||||
|
# 'views/jikimo_workorder_exception_views.xml',
|
||||||
|
'views/mrp_workorder_views.xml',
|
||||||
|
'security/ir.model.access.csv',
|
||||||
|
],
|
||||||
|
'demo': [
|
||||||
|
],
|
||||||
|
'license': 'LGPL-3',
|
||||||
|
'installable': True,
|
||||||
|
'application': False,
|
||||||
|
'auto_install': False,
|
||||||
|
}
|
||||||
1
jikimo_workorder_exception/controllers/__init__.py
Normal file
1
jikimo_workorder_exception/controllers/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import main
|
||||||
106
jikimo_workorder_exception/controllers/main.py
Normal file
106
jikimo_workorder_exception/controllers/main.py
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
from odoo import http, fields
|
||||||
|
from odoo.http import request
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
from odoo.addons.sf_mrs_connect.controllers.controllers import Sf_Mrs_Connect
|
||||||
|
from odoo.addons.sf_manufacturing.controllers.controllers import Manufacturing_Connect
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class WorkorderExceptionConroller(http.Controller):
|
||||||
|
|
||||||
|
@http.route('/AutoDeviceApi/BillError', type='json', auth='public', methods=['GET', 'POST'], csrf=False,
|
||||||
|
cors="*")
|
||||||
|
def workder_exception(self, **kw):
|
||||||
|
"""
|
||||||
|
记录工单异常
|
||||||
|
:param kw:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
_logger.info('workder_exception:%s' % kw)
|
||||||
|
try:
|
||||||
|
res = {'Succeed': True, 'ErrorCode': 0, 'Error': ''}
|
||||||
|
datas = request.httprequest.data
|
||||||
|
ret = json.loads(datas)['Datas']
|
||||||
|
if not ret.get('RfidCode') or not ret.get('ErrorType'):
|
||||||
|
res = {'Succeed': False, 'ErrorCode': 400, 'Error': '参数错误'}
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
|
|
||||||
|
# 通过RfidCode获取就绪的CNC工单
|
||||||
|
workorder = request.env['mrp.workorder'].sudo().search([
|
||||||
|
('rfid_code', '=', ret['RfidCode']),
|
||||||
|
('routing_type', '=', 'CNC加工'),
|
||||||
|
])
|
||||||
|
if not workorder:
|
||||||
|
res = {'Succeed': False, 'ErrorCode': 401, 'Error': '无效的工单'}
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
|
|
||||||
|
# 创建工单异常记录,关联工单
|
||||||
|
request.env['jikimo.workorder.exception'].sudo().create({
|
||||||
|
'workorder_id': workorder.id,
|
||||||
|
'exception_code': ret.get('ErrorType'),
|
||||||
|
'exception_content': ret.get('Error', '')
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||||
|
_logger.info('workder_exception error:%s' % e)
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
|
|
||||||
|
|
||||||
|
class SfMrsConnectController(Sf_Mrs_Connect):
|
||||||
|
|
||||||
|
@http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
||||||
|
cors="*")
|
||||||
|
def get_cnc_processing_create(self, **kw):
|
||||||
|
"""
|
||||||
|
更新工单异常记录【'YC001', 'YC004'】
|
||||||
|
"""
|
||||||
|
res = super(SfMrsConnectController, self).get_cnc_processing_create(**kw)
|
||||||
|
# 如果有未完成的YC0001、YC0004异常记录,则标记为完成
|
||||||
|
res = json.loads(res)
|
||||||
|
_logger.info('已进入工单异常:%s' % res)
|
||||||
|
if res.get('production_ids'):
|
||||||
|
try:
|
||||||
|
productions = request.env['mrp.production'].sudo().search([('id', 'in', res.get('production_ids'))])
|
||||||
|
if productions.workorder_ids.exception_ids:
|
||||||
|
pending_exception = productions.workorder_ids.exception_ids.filtered(
|
||||||
|
lambda exc: exc.state == 'pending' and exc.exception_code in ['YC0001', 'YC0004']
|
||||||
|
)
|
||||||
|
if pending_exception:
|
||||||
|
pending_exception.write({
|
||||||
|
'completion_time': fields.Datetime.now(),
|
||||||
|
'state': 'done'
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
_logger.info('更新工单异常记录失败:%s' % e)
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
|
|
||||||
|
class ManufactruingController(Manufacturing_Connect):
|
||||||
|
|
||||||
|
@http.route('/AutoDeviceApi/FeedBackStart', type='json', auth='none', methods=['GET', 'POST'], csrf=False,
|
||||||
|
cors="*")
|
||||||
|
def button_Work_START(self, **kw):
|
||||||
|
"""
|
||||||
|
更新工单异常记录【'YC0002', 'YC0003'】
|
||||||
|
"""
|
||||||
|
res = super(ManufactruingController, self).button_Work_START(**kw)
|
||||||
|
res = json.loads(res)
|
||||||
|
_logger.info('已进入工单异常:%s' % res)
|
||||||
|
if res.get('workorder_id'):
|
||||||
|
try:
|
||||||
|
workorder = request.env['mrp.workorder'].sudo().browse(int(res.get('workorder_id')))
|
||||||
|
if workorder.exception_ids:
|
||||||
|
_logger.info('workorder.exception_ids:%s' % workorder.exception_ids)
|
||||||
|
pending_exception = workorder.exception_ids.filtered(
|
||||||
|
lambda exc: exc.state == 'pending' and exc.exception_code in ['YC0002', 'YC0003']
|
||||||
|
)
|
||||||
|
_logger.info('pending_exception:%s' % pending_exception)
|
||||||
|
if pending_exception:
|
||||||
|
pending_exception.write({
|
||||||
|
'completion_time': fields.Datetime.now(),
|
||||||
|
'state': 'done'
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
_logger.info('更新工单异常记录失败:%s' % e)
|
||||||
|
return json.JSONEncoder().encode(res)
|
||||||
3
jikimo_workorder_exception/models/__init__.py
Normal file
3
jikimo_workorder_exception/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from . import jikimo_workorder_exception
|
||||||
|
from . import mrp_workorder
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
|
class JikimoWorkorderException(models.Model):
|
||||||
|
_name = 'jikimo.workorder.exception'
|
||||||
|
_description = '工单异常记录'
|
||||||
|
_order = 'id desc'
|
||||||
|
|
||||||
|
workorder_id = fields.Many2one('mrp.workorder', string='工单')
|
||||||
|
exception_code = fields.Char('异常编码')
|
||||||
|
exception_content = fields.Char('反馈的异常/问题信息')
|
||||||
|
completion_time = fields.Datetime('处理完成时间')
|
||||||
|
state = fields.Selection([('pending', '进行中'), ('done', '已处理')], string='状态', default='pending')
|
||||||
|
|
||||||
18
jikimo_workorder_exception/models/mrp_workorder.py
Normal file
18
jikimo_workorder_exception/models/mrp_workorder.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from odoo import models, fields
|
||||||
|
|
||||||
|
class MrpWorkorder(models.Model):
|
||||||
|
_inherit = 'mrp.workorder'
|
||||||
|
|
||||||
|
exception_ids = fields.One2many('jikimo.workorder.exception', 'workorder_id', string='工单异常记录')
|
||||||
|
|
||||||
|
def write(self, values):
|
||||||
|
if values.get('test_results') and self.exception_ids:
|
||||||
|
pending_exception = self.exception_ids.filtered(
|
||||||
|
lambda exc: exc.state == 'pending' and exc.exception_code == 'YC0005'
|
||||||
|
)
|
||||||
|
if pending_exception:
|
||||||
|
pending_exception.write({
|
||||||
|
'completion_time': fields.Datetime.now(),
|
||||||
|
'state': 'done'
|
||||||
|
})
|
||||||
|
return super(MrpWorkorder, self).write(values)
|
||||||
2
jikimo_workorder_exception/security/ir.model.access.csv
Normal file
2
jikimo_workorder_exception/security/ir.model.access.csv
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
|
||||||
|
"access_jikimo_workorder_exception","access.jikimo.workorder.exception","model_jikimo_workorder_exception","mrp.group_mrp_user",1,1,1,0
|
||||||
|
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<data>
|
||||||
|
<record id="jikimo_workorder_exception_list_view" model="ir.ui.view">
|
||||||
|
<field name="name">jikimo.workorder.exception.tree</field>
|
||||||
|
<field name="model">jikimo.workorder.exception</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
23
jikimo_workorder_exception/views/mrp_workorder_views.xml
Normal file
23
jikimo_workorder_exception/views/mrp_workorder_views.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<data>
|
||||||
|
<record id="jikimo_workorder_exception_form_view_inherit" model="ir.ui.view">
|
||||||
|
<field name="name">mrp.workorder.form</field>
|
||||||
|
<field name="model">mrp.workorder</field>
|
||||||
|
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//notebook/page[last()]" position="after">
|
||||||
|
<page string="异常记录" name="workorder_exception">
|
||||||
|
<field name="exception_ids" nolabel="1" readonly="1">
|
||||||
|
<tree create="false" delete="false" edit="false">
|
||||||
|
<field name="exception_content" string="反馈的异常/问题信息"/>
|
||||||
|
<field name="create_date" string="时间"/>
|
||||||
|
<field name="completion_time"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</page>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
@@ -38,3 +38,14 @@ class Manufacturing_Connect(http.Controller):
|
|||||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||||
logging.info('get_maintenance_tool_groups_Info error:%s' % e)
|
logging.info('get_maintenance_tool_groups_Info error:%s' % e)
|
||||||
return json.JSONEncoder().encode(res)
|
return json.JSONEncoder().encode(res)
|
||||||
|
|
||||||
|
|
||||||
|
class MultiInheritController():
|
||||||
|
_sub_classes = []
|
||||||
|
|
||||||
|
def __init_subclass__(cls):
|
||||||
|
super().__init_subclass__()
|
||||||
|
if len(cls._sub_classes) > 0 and cls not in cls._sub_classes:
|
||||||
|
cls.__bases__ = (cls._sub_classes[-1],)
|
||||||
|
if cls not in cls._sub_classes:
|
||||||
|
cls._sub_classes.append(cls)
|
||||||
|
|||||||
@@ -189,6 +189,7 @@ class Manufacturing_Connect(http.Controller):
|
|||||||
request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
|
request.env['sf.production.plan'].sudo().search([('production_id', '=', production_id)]).write(
|
||||||
{'actual_start_time': workorder.date_start,
|
{'actual_start_time': workorder.date_start,
|
||||||
'state': 'processing'})
|
'state': 'processing'})
|
||||||
|
res.update({'workorder_id': workorder.id})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
res = {'Succeed': False, 'ErrorCode': 202, 'Error': e}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class MessageSfMrsConnect(Sf_Mrs_Connect):
|
|||||||
def get_cnc_processing_create(self, **kw):
|
def get_cnc_processing_create(self, **kw):
|
||||||
res = super(MessageSfMrsConnect, self).get_cnc_processing_create(**kw)
|
res = super(MessageSfMrsConnect, self).get_cnc_processing_create(**kw)
|
||||||
res = json.loads(res)
|
res = json.loads(res)
|
||||||
|
_logger.info('已进入消息推送:%s' % res)
|
||||||
if res.get('production_ids'):
|
if res.get('production_ids'):
|
||||||
try:
|
try:
|
||||||
_logger.info('已编程的制造订单:%s' % res.get('production_ids'))
|
_logger.info('已编程的制造订单:%s' % res.get('production_ids'))
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
from odoo import http
|
from odoo import http, fields, models
|
||||||
from odoo.http import request
|
from odoo.http import request
|
||||||
|
from odoo.addons.sf_base.controllers.controllers import MultiInheritController
|
||||||
|
|
||||||
|
|
||||||
class Sf_Mrs_Connect(http.Controller):
|
class Sf_Mrs_Connect(http.Controller, MultiInheritController):
|
||||||
|
|
||||||
@http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
@http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False,
|
||||||
cors="*")
|
cors="*")
|
||||||
|
|||||||
Reference in New Issue
Block a user