From d8bade64e13c2f4ae2b4cdde63a50234c60caad6 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Fri, 11 Oct 2024 17:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B4=A8=E9=87=8F=EF=BC=9A?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=A0=E5=B7=A5=E8=B4=A8=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 13 +- sf_manufacturing/views/mrp_workorder_view.xml | 4 +- sf_message/data/template_data.xml | 82 ++++++------ sf_quality/__init__.py | 1 + sf_quality/__manifest__.py | 5 +- sf_quality/controller/__init__.py | 1 + sf_quality/controller/workorder.py | 28 ++++ sf_quality/models/__init__.py | 1 + sf_quality/models/quality_cnc_test.py | 47 +++++++ sf_quality/security/ir.model.access.csv | 3 + sf_quality/views/quality_cnc_test_view.xml | 126 ++++++++++++++++++ sf_quality/views/view.xml | 62 ++++----- 12 files changed, 287 insertions(+), 86 deletions(-) create mode 100644 sf_quality/controller/__init__.py create mode 100644 sf_quality/controller/workorder.py create mode 100644 sf_quality/models/quality_cnc_test.py create mode 100644 sf_quality/views/quality_cnc_test_view.xml diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index 48144622..fa35836d 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -595,14 +595,6 @@ class Manufacturing_Connect(http.Controller): if panel_workorder: panel_workorder.write({'production_line_state': '已下产线'}) workorder.write({'state': 'to be detected'}) - # workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search( - # [ - # ('rfid_code', '=', rfid_code), ('type', '=', '下产线'), - # ('production_id', '=', order.production_id.id), - # ('workorder_id', '=', order.id), - # ('workorder_state', '=', 'done')]) - # if workpiece_delivery: - # delivery_Arr.append(workpiece_delivery.id) else: res = {'Succeed': False, 'ErrorCode': 204, 'Error': 'DeviceId为%s没有对应的已配送工件数据' % ret['DeviceId']} @@ -623,13 +615,14 @@ class Manufacturing_Connect(http.Controller): if ret['IsComplete'] is True: # 向AGV任务调度下发下产线任务 workorders = request.env['mrp.workorder'].browse(workorder_ids) + res['workorder_ids'] = workorder_ids request.env['sf.agv.scheduling'].add_scheduling(ret['DeviceId'], '下产线', workorders) else: res = {'Succeed': False, 'ErrorCode': 203, 'Error': '未传IsComplete字段'} except RepeatTaskException as e: logging.info('AGVToProduct error:%s' % e) except Exception as e: - res = {'Succeed': False, 'ErrorCode': 202, 'Error': str(e)} + res = {'Succeed': False, 'ErrorCode': 202, 'Error': str(e), 'workorder_ids': workorder_ids} logging.info('AGVDownProduct error:%s' % e) return json.JSONEncoder().encode(res) @@ -695,4 +688,4 @@ class Manufacturing_Connect(http.Controller): except Exception as e: res = {'Succeed': False, 'ErrorCode': 202, 'Error': str(e)} logging.info('AGVDownProduct error:%s' % e) - return json.JSONEncoder().encode(res) \ No newline at end of file + return json.JSONEncoder().encode(res) diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 6b54e914..758ca417 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -229,7 +229,7 @@ decoration-danger="tag_type == '重新加工'"/> - + @@ -265,7 +265,7 @@ attrs='{"invisible": [("routing_type","in",("获取CNC加工程序","切割","装夹预调"))]}'/> - diff --git a/sf_message/data/template_data.xml b/sf_message/data/template_data.xml index 1ff06b72..835ff7ab 100644 --- a/sf_message/data/template_data.xml +++ b/sf_message/data/template_data.xml @@ -113,7 +113,7 @@ - CNC工单逾期预警 + CNC加工工单逾期预警 mrp.workorder @@ -125,7 +125,7 @@ - CNC工单已逾期 + CNC加工工单已逾期 mrp.workorder @@ -186,46 +186,46 @@ - - - - 调拨入库 - - stock.picking - - markdown - normal - ### 调拨入库通知: -单号:调拨入库单[{{name}}]({{request_url}}) -事项:完成刀具物料上架入库 - + + + + + + + + + + + + + - - - - 功能刀具寿命到期 - - sf.functional.tool.dismantle - - markdown - normal - ### 功能刀具寿命到期提醒: -单号:拆解单[{{code}}]({{request_url}}) -事项:{{functional_tool_id.tool_name_id.name}}寿命已到期,需拆解 - + + + + + + + + + + + + + - - - - 功能刀具组装 - - sf.functional.tool.assembly - - markdown - normal - ### 功能刀具组装通知: -单号:组装任务单[{{name}}]({{request_url}}) -事项:{{use_tool_time}}前完成组装 - + + + + + + + + + + + + + \ No newline at end of file diff --git a/sf_quality/__init__.py b/sf_quality/__init__.py index 8134f974..4dc6605a 100644 --- a/sf_quality/__init__.py +++ b/sf_quality/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import models +from . import controller diff --git a/sf_quality/__manifest__.py b/sf_quality/__manifest__.py index c41e1a24..b1151b6d 100644 --- a/sf_quality/__manifest__.py +++ b/sf_quality/__manifest__.py @@ -13,10 +13,11 @@ 'author': 'jikimo', 'website': 'https://sf.cs.jikimo.com', # 此处依赖sf_manufacturing是因为我要重写其中的一个字段operation_id的string,故需要sf_manufacturing先安装 - 'depends': ['quality_control'], + 'depends': ['quality_control', 'web_widget_model_viewer', 'sf_manufacturing'], 'data': [ 'security/ir.model.access.csv', - 'views/view.xml' + 'views/view.xml', + 'views/quality_cnc_test_view.xml' ], 'assets': { diff --git a/sf_quality/controller/__init__.py b/sf_quality/controller/__init__.py new file mode 100644 index 00000000..82545660 --- /dev/null +++ b/sf_quality/controller/__init__.py @@ -0,0 +1 @@ +from . import workorder diff --git a/sf_quality/controller/workorder.py b/sf_quality/controller/workorder.py new file mode 100644 index 00000000..37e1903b --- /dev/null +++ b/sf_quality/controller/workorder.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +import json +import requests +import logging +from odoo import http +from odoo.http import request +from odoo.addons.sf_manufacturing.controllers.controllers import Manufacturing_Connect +from odoo.addons.sf_base.commons.common import Common + +_logger = logging.getLogger(__name__) + + +class SfQualityConnect(Manufacturing_Connect): + + @http.route('/AutoDeviceApi/AGVDownProduct', type='json', auth='none', methods=['GET', 'POST'], csrf=False, + cors="*") + def AGVDownProduct(self, **kw): + res = super(SfQualityConnect, self).AGVDownProduct(**kw) + res = json.loads(res) + if res.get('workorder_ids'): + try: + _logger.info('已下产线的工单:%s' % res.get('workorder_ids')) + for order_id in res['workorder_ids']: + request.env['quality.cnc.test'].sudo().create( + {'workorder_id': order_id, 'write_uid': False, 'write_date': False}) + except Exception as e: + _logger.info('AGV运送下产线接口:%s' % e) + return json.JSONEncoder().encode(res) diff --git a/sf_quality/models/__init__.py b/sf_quality/models/__init__.py index 71468786..248f7fb2 100644 --- a/sf_quality/models/__init__.py +++ b/sf_quality/models/__init__.py @@ -3,3 +3,4 @@ from . import custom_quality from . import quality +from . import quality_cnc_test diff --git a/sf_quality/models/quality_cnc_test.py b/sf_quality/models/quality_cnc_test.py new file mode 100644 index 00000000..89aa4500 --- /dev/null +++ b/sf_quality/models/quality_cnc_test.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields, api, _ +from odoo.exceptions import UserError + + +class SfQualityCncTest(models.Model): + _name = 'quality.cnc.test' + _description = 'CNC加工质检' + + name = fields.Char('单号', default=lambda self: self.env['ir.sequence'].next_by_code('quality.cnc.test')) + workorder_id = fields.Many2one('mrp.workorder') + production_id = fields.Many2one(related='workorder_id.production_id', string='制造订单') + product_id = fields.Many2one(related='workorder_id.product_id', string='产品') + model_file = fields.Binary(related='workorder_id.glb_file', string='加工模型') + processing_panel = fields.Char(related='workorder_id.processing_panel', string='加工面') + equipment_id = fields.Many2one(related='workorder_id.equipment_id', string='加工设备') + production_line_id = fields.Many2one(related='workorder_id.production_line_id', + string='生产线') + part_number = fields.Char(related='workorder_id.part_number', string='成品零件图号') + detection_report = fields.Binary(related='workorder_id.detection_report', readonly=True, string='检测报告') + state = fields.Selection([ + ('waiting', '待判定'), + ('done', '已完成')], string='状态', default='waiting') + result = fields.Selection([ + ('pass', '合格'), + ('fail', '不合格')], string='判定结果') + number = fields.Integer('数量', default=1) + test_results = fields.Selection([("合格", "合格"), ("返工", "返工"), ("报废", "报废")], default='合格', + string="检测结果") + reason = fields.Selection( + [("programming", "编程"), ("cutter", "刀具"), ("clamping", "装夹"), ("operate computer", "操机"), + ("technology", "工艺"), ("customer redrawing", "客户改图")], string="原因") + detailed_reason = fields.Text('详细原因') + + def submit_pass(self): + self.write({'result': 'pass', 'test_results': '合格', 'state': 'done'}) + self.workorder_id.write({'test_results': self.test_results}) + self.workorder_id.button_finish() + + def submit_fail(self): + if not self.reason and not self.detailed_reason: + raise UserError(_('请填写【检测情况】里的信息')) + else: + self.write({'result': 'fail', 'test_results': '合格', 'state': 'done'}) + self.workorder_id.write( + {'test_results': self.test_results, 'reason': self.reason, 'detailed_reason': self.detailed_reason}) + self.workorder_id.button_finish() diff --git a/sf_quality/security/ir.model.access.csv b/sf_quality/security/ir.model.access.csv index b147a1df..20d1a68e 100644 --- a/sf_quality/security/ir.model.access.csv +++ b/sf_quality/security/ir.model.access.csv @@ -67,5 +67,8 @@ access_quality_alert_stage,quality.alert.stage,quality.model_quality_alert_stage access_stock_move_group_quality,stock_move_group_quality,stock.model_stock_move,sf_base.group_quality,1,1,0,0 access_stock_move_group_quality_director,stock_move_group_quality_director,stock.model_stock_move,sf_base.group_quality_director,1,1,0,0 +access_quality_cnc_test_group_quality,quality_cnc_test_group_quality,model_quality_cnc_test,sf_base.group_quality,1,1,0,0 +access_quality_cnc_test_group_quality_director,quality_cnc_test_group_quality_director,model_quality_cnc_test,sf_base.group_quality_director,1,1,0,0 + diff --git a/sf_quality/views/quality_cnc_test_view.xml b/sf_quality/views/quality_cnc_test_view.xml new file mode 100644 index 00000000..d14d3233 --- /dev/null +++ b/sf_quality/views/quality_cnc_test_view.xml @@ -0,0 +1,126 @@ + + + + + 加工质检单编码规则 + quality.cnc.test + QCT + 4 + + + + + quality.cnc.test.view.tree + quality.cnc.test + + + + + + + + + + + + + + + + + + search.quality.cnc.test + quality.cnc.test + + + + + + + + + + + + + 加工质检 + quality.cnc.test + tree,form + { 'search_default_filter_waiting':1} + +

+ 请先创建一个加工质检单 +

+
+
+ + + quality.cnc.test.form. + quality.cnc.test + +
+
+
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + +
diff --git a/sf_quality/views/view.xml b/sf_quality/views/view.xml index 1edbca05..b5fff367 100644 --- a/sf_quality/views/view.xml +++ b/sf_quality/views/view.xml @@ -34,36 +34,36 @@
- - quality.point.form.inherit.sf - quality.point - - - - - - - custom_required - 1 - - - custom_required - 1 - - - + + + + + + + + + + + + + + + + + + - - sf.quality.point.form.inherit.sf - quality.point - - - - custom_required - - - custom_required - - - + + + + + + + + + + + + +