From 191bd65d698524ca2fb9395186e8c5298ca38e4c Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Wed, 16 Nov 2022 17:39:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=8E=A5=E6=94=B6=E4=BB=8E=E6=99=BA?= =?UTF-8?q?=E8=83=BD=E5=B7=A5=E5=8E=82=E4=BC=A0=E8=BF=87=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=AD=89=E6=95=B0=E6=8D=AE=E5=B9=B6=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=BC=96=E7=A8=8B=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/process.py | 1 + sf_base/models/product_template.py | 61 ++++++++++-------------- sf_base/views/mrs_base_view.xml | 6 ++- sf_manufacturing_orders/__manifest__.py | 3 +- sf_route_workcenter/models/workcenter.py | 36 ++++++++++++++ 5 files changed, 70 insertions(+), 37 deletions(-) diff --git a/sf_base/models/process.py b/sf_base/models/process.py index e6ef6348..ec793560 100644 --- a/sf_base/models/process.py +++ b/sf_base/models/process.py @@ -6,6 +6,7 @@ class ModelType(models.Model): _description = '模型类型' name = fields.Char('名称') + embryo_tolerance = fields.Integer('胚料的容余量') routing_tmpl_ids = fields.One2many('sf.model.type.routing.sort', 'model_type_id', '工序模板') diff --git a/sf_base/models/product_template.py b/sf_base/models/product_template.py index 4bfb9eae..348f1b91 100644 --- a/sf_base/models/product_template.py +++ b/sf_base/models/product_template.py @@ -1,4 +1,4 @@ -from odoo import models, fields,api +from odoo import models, fields, api from odoo.exceptions import ValidationError @@ -9,7 +9,7 @@ class ResProductTemplate(models.Model): model_long = fields.Float('模型长[mm]', digits=(16, 3)) model_width = fields.Float('模型宽[mm]', digits=(16, 3)) model_height = fields.Float('模型高[mm]', digits=(16, 3)) - model_volume = fields.Float('模型体积[mm³]', digits=(16, 3)) + model_volume = fields.Float('模型体积[mm³]', digits=(16, 3), compute='_compute_model_volume', store=True) model_precision = fields.Float('精度要求', digits=(16, 3)) model_type_id = fields.Many2one('sf.model.type', string='模型类型') model_processing_panel = fields.Char('模型加工面板') @@ -20,19 +20,22 @@ class ResProductTemplate(models.Model): model_number = fields.Integer('模型数量', default=1) model_remark = fields.Char('模型备注说明') - long = fields.Float('长[mm]', digits=(16, 3), onchange='count_embryo_size') - width = fields.Float('宽[mm]', digits=(16, 3), onchange='count_embryo_size') - height = fields.Float('高[mm]', digits=(16, 3), onchange='count_embryo_size') + long = fields.Float('长[mm]', digits=(16, 3), onchange='add_product_size') + width = fields.Float('宽[mm]', digits=(16, 3), onchange='add_product_size') + height = fields.Float('高[mm]', digits=(16, 3), onchange='add_product_size') materials_id = fields.Many2one('mrs.production.materials', string='材料') materials_type_id = fields.Many2one('mrs.materials.model', string='材料型号') - volume = fields.Float(compute='_compute_volume', store=True) @api.depends('long', 'width', 'height') def _compute_volume(self): self.volume = self.long * self.width * self.height + @api.depends('model_long', 'model_width', 'model_height') + def _compute_model_volume(self): + self.model_volume = self.model_long * self.model_width * self.model_height + # 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品 def product_create(self, product_id, item, order_id, order_number, i): copy_product_id = product_id.with_user(self.env.ref("base.user_admin")).copy() @@ -63,24 +66,23 @@ class ResProductTemplate(models.Model): copy_product_id.sudo().write(vals) return copy_product_id - # 在产品上增加模型类型和加工的面(例如:A、B) , - # 并根据模型类型计算出产品的胚料尺寸; - # @api.onchange('model_type_id') - # def count_embryo_size(self): - # if not self.model_type_id: - # return - # bom = self.env['product.product'].search( - # [('categ_id.is_embryo', '=', True), ('product_tmpl_id', '=', self.id)], - # limit=1, - # order='volume desc' - # ) - # for item in self: - # item.embryo_long = bom.embryo_long + 1 - # item.embryo_width = bom.embryo_width + 1 - # item.embryo_height = bom.embryo_height + 1 - - - + # 根据模型类型默认给模型的长高宽加配置的长度; + @api.onchange('model_type_id') + def add_product_size(self): + if not self.model_type_id: + return + model_type = self.env['sf.model.type'].search( + [('id', '=', self.model_type_id.id)]) + print(self.model_long) + print(self.model_width) + print(self.model_height) + for item in self: + print(item.model_long) + print(item.model_width) + print(item.model_height) + item.model_long = item.model_long + model_type.embryo_tolerance + item.model_width = item.model_width + model_type.embryo_tolerance + item.model_height = item.model_width + model_type.embryo_tolerance class ResProductCategory(models.Model): @@ -134,14 +136,3 @@ class ResMrpBom(models.Model): 'product_uom_id': 1 } return self.env['mrp.bom.line'].create(vals) - - - - - - - - - - - diff --git a/sf_base/views/mrs_base_view.xml b/sf_base/views/mrs_base_view.xml index 4cff9e87..927cc8dc 100644 --- a/sf_base/views/mrs_base_view.xml +++ b/sf_base/views/mrs_base_view.xml @@ -531,12 +531,16 @@
+ - + + + + diff --git a/sf_manufacturing_orders/__manifest__.py b/sf_manufacturing_orders/__manifest__.py index 4bcec36c..831aa103 100644 --- a/sf_manufacturing_orders/__manifest__.py +++ b/sf_manufacturing_orders/__manifest__.py @@ -10,9 +10,10 @@ """, 'category': '', 'website': 'https://www.sf.jikimo.com', - 'depends': ['mrp'], + 'depends': ['mrp', 'sf_base'], 'data': [ 'views/sf_production.xml', + 'views/mrp_routing_workcenter_view.xml' ], diff --git a/sf_route_workcenter/models/workcenter.py b/sf_route_workcenter/models/workcenter.py index 25a8b5b2..261ebedd 100644 --- a/sf_route_workcenter/models/workcenter.py +++ b/sf_route_workcenter/models/workcenter.py @@ -3,11 +3,14 @@ import base64 import logging import math +import json +import requests from io import BytesIO from odoo import api, fields, models, SUPERUSER_ID from pystrich.code128 import Code128Encoder from odoo.exceptions import ValidationError +from odoo.addons.sf_base.commons.common import Common _logger = logging.getLogger(__name__) @@ -244,7 +247,40 @@ class MrpWorkOrder(models.Model): productions.create_workorder1(self.processing_panel) return "" + # cnc程序获取 + def fetchCNC(self): + cnc_process = self.env['mrp.workorder'].search( + [("routing_type", '=', 'CNC加工'), + ("production_id", '=', self.production_id.id)], + limit=1, + order='id asc' + ) + vals = { + 'model_long': cnc_process.product_id.model_long, + 'model_width': cnc_process.product_id.model_width, + 'model_height': cnc_process.product_id.model_height, + 'model_volume': cnc_process.product_id.model_volume, + 'model_price': cnc_process.product_id.model_price, + 'model_total_amount': cnc_process.product_id.model_total_amount, + 'model_materials_code': cnc_process.product_id.materials_id.materials_no, + 'model_materials_type_code': cnc_process.product_id.materials_type_id.materials_no, + 'model_surface_process_code': cnc_process.product_id.model_surface_process_id.process_encode, + 'model_process_parameters_code': cnc_process.product_id.model_process_parameters_id.process_encode, + 'model_remark': cnc_process.product_id.model_remark + } + res = [{'order_no': self.product_id.barcode, 'production_no': self.production_id.name, + 'intelligent_programming_str': vals, + 'machine_tool_code': cnc_process.workcenter_id.machine_tool_id.code}] + configsettings = self.env['res.config.settings'].get_values() + token = configsettings['token'] + mrs_secret_key = configsettings['mrs_secret_key'] + config_header = Common.get_headers(self, token, mrs_secret_key) + url = '/api/intelligent_programming/create' + config_url = configsettings['mrs_url'] + url + res_str = json.dumps(res) + ret = requests.post(config_url, json={"result": res_str}, data=None, headers=config_header) + return "" From dadd2e03da6731739cb166a593fe4ce9ec092382 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Fri, 18 Nov 2022 18:08:53 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=8E=B7=E5=BE=97cnc=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_route_workcenter/models/workcenter.py | 36 ++++++++---------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/sf_route_workcenter/models/workcenter.py b/sf_route_workcenter/models/workcenter.py index 261ebedd..bc9a9bf8 100644 --- a/sf_route_workcenter/models/workcenter.py +++ b/sf_route_workcenter/models/workcenter.py @@ -188,8 +188,8 @@ class MrpWorkOrder(models.Model): }) else: raise ValidationError('该托盘编码已失效') - else:return "" - + else: + return "" # 解除托盘绑定 def unbindtray(self): @@ -250,28 +250,16 @@ class MrpWorkOrder(models.Model): # cnc程序获取 def fetchCNC(self): - cnc_process = self.env['mrp.workorder'].search( - [("routing_type", '=', 'CNC加工'), - ("production_id", '=', self.production_id.id)], - limit=1, - order='id asc' - ) - vals = { - 'model_long': cnc_process.product_id.model_long, - 'model_width': cnc_process.product_id.model_width, - 'model_height': cnc_process.product_id.model_height, - 'model_volume': cnc_process.product_id.model_volume, - 'model_price': cnc_process.product_id.model_price, - 'model_total_amount': cnc_process.product_id.model_total_amount, - 'model_materials_code': cnc_process.product_id.materials_id.materials_no, - 'model_materials_type_code': cnc_process.product_id.materials_type_id.materials_no, - 'model_surface_process_code': cnc_process.product_id.model_surface_process_id.process_encode, - 'model_process_parameters_code': cnc_process.product_id.model_process_parameters_id.process_encode, - 'model_remark': cnc_process.product_id.model_remark - } - res = [{'order_no': self.product_id.barcode, 'production_no': self.production_id.name, - 'intelligent_programming_str': vals, - 'machine_tool_code': cnc_process.workcenter_id.machine_tool_id.code}] + res = {'model_code': self.product_id.barcode, 'production_no': self.production_id.name, + 'machine_tool_code': self.workcenter_id.machine_tool_id.code, + 'material_code': self.env['mrs.production.materials'].search( + [('id', '=', self.product_id.materials_id.id)]).materials_no, + 'material_type_code': self.env['mrs.materials.model'].search( + [('id', '=', self.product_id.materials_type_id.id)]).materials_no, + 'embryo_long': self.product_id.bom_ids.bom_line_ids.product_id.long, + 'embryo_height': self.product_id.bom_ids.bom_line_ids.product_id.height, + 'embryo_width': self.product_id.bom_ids.bom_line_ids.product_id.width + } configsettings = self.env['res.config.settings'].get_values() token = configsettings['token'] mrs_secret_key = configsettings['mrs_secret_key'] From a0b7b13c5e6bc9010a576805e5d26c53550ef730 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Sat, 19 Nov 2022 22:52:47 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=BE=97cnc?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_route_workcenter/models/workcenter.py | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sf_route_workcenter/models/workcenter.py b/sf_route_workcenter/models/workcenter.py index bc9a9bf8..6d81fb08 100644 --- a/sf_route_workcenter/models/workcenter.py +++ b/sf_route_workcenter/models/workcenter.py @@ -250,20 +250,20 @@ class MrpWorkOrder(models.Model): # cnc程序获取 def fetchCNC(self): - res = {'model_code': self.product_id.barcode, 'production_no': self.production_id.name, - 'machine_tool_code': self.workcenter_id.machine_tool_id.code, - 'material_code': self.env['mrs.production.materials'].search( - [('id', '=', self.product_id.materials_id.id)]).materials_no, - 'material_type_code': self.env['mrs.materials.model'].search( - [('id', '=', self.product_id.materials_type_id.id)]).materials_no, - 'embryo_long': self.product_id.bom_ids.bom_line_ids.product_id.long, - 'embryo_height': self.product_id.bom_ids.bom_line_ids.product_id.height, - 'embryo_width': self.product_id.bom_ids.bom_line_ids.product_id.width - } + res = [{'model_code': self.product_id.barcode, 'production_no': self.production_id.name, + 'machine_tool_code': self.workcenter_id.machine_tool_id.code, + 'material_code': self.env['mrs.production.materials'].search( + [('id', '=', self.product_id.materials_id.id)]).materials_no, + 'material_type_code': self.env['mrs.materials.model'].search( + [('id', '=', self.product_id.materials_type_id.id)]).materials_no, + 'embryo_long': self.product_id.bom_ids.bom_line_ids.product_id.long, + 'embryo_height': self.product_id.bom_ids.bom_line_ids.product_id.height, + 'embryo_width': self.product_id.bom_ids.bom_line_ids.product_id.width + }] configsettings = self.env['res.config.settings'].get_values() - token = configsettings['token'] - mrs_secret_key = configsettings['mrs_secret_key'] - config_header = Common.get_headers(self, token, mrs_secret_key) + # token = configsettings['token'] + # mrs_secret_key = configsettings['mrs_secret_key'] + config_header = Common.get_headers(self, configsettings['token'], configsettings['mrs_secret_key']) url = '/api/intelligent_programming/create' config_url = configsettings['mrs_url'] + url res_str = json.dumps(res) From aeb9b0f79615c79d252c04f582c1e8660f0d4cde Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Sun, 20 Nov 2022 19:44:31 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=BE=97mrs?= =?UTF-8?q?=E4=B8=8B=E5=8F=91=E7=BC=96=E7=A8=8B=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/sf_base.py | 2 +- sf_mrs_connect/__manifest__.py | 2 +- sf_mrs_connect/controllers/__init__.py | 1 + sf_mrs_connect/controllers/controllers.py | 28 ++++++++++++++++++++++- sf_route_workcenter/models/workcenter.py | 21 +++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/sf_base/models/sf_base.py b/sf_base/models/sf_base.py index e337d301..d098127b 100644 --- a/sf_base/models/sf_base.py +++ b/sf_base/models/sf_base.py @@ -264,5 +264,5 @@ class CNCprocessing(models.Model): FJGSD = fields.Char(string="加工深度(Z)") FSCCD = fields.Char(string="刀具伸出长度") FDJSpec = fields.Char(string="刀柄型号") - FJGDate = fields.Char(string="预计加工时间") + FJGDate = fields.Datetime(string="预计加工时间") FComment = fields.Char(string="备注") diff --git a/sf_mrs_connect/__manifest__.py b/sf_mrs_connect/__manifest__.py index 7f28c5ee..5003bd36 100644 --- a/sf_mrs_connect/__manifest__.py +++ b/sf_mrs_connect/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'YZ', 'website': 'https://www.sf.cs.jikimo.com', - 'depends': [], + 'depends': ['sf_base'], 'data': [ # 'views/sale_process_order_view.xml' ], diff --git a/sf_mrs_connect/controllers/__init__.py b/sf_mrs_connect/controllers/__init__.py index e69de29b..e046e49f 100644 --- a/sf_mrs_connect/controllers/__init__.py +++ b/sf_mrs_connect/controllers/__init__.py @@ -0,0 +1 @@ +from . import controllers diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index e046e49f..5d6e8160 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -1 +1,27 @@ -from . import controllers +# -*- coding: utf-8 -*- +import json +import logging +from datetime import date, timedelta +from odoo import http +from odoo.http import request + + +class Sf_Mrs_Connect(http.Controller): + + @http.route('/api/cnc_processing/create', type='json', auth='sf_token', methods=['GET', 'POST'], csrf=False, + cors="*") + def get_cnc_processing_create(self, **kw): + """ + 获取mrs下发的编程单 + :param kw: + :return: + """ + logging.info('get_cnc_processing_create:%s' % kw) + try: + datas = request.httprequest.data + ret = json.loads(datas) + ret = json.loads(ret['result']) + for obj in ret: + request.env['cnc.processing'].with_user(request.env.ref("base.user_admin")).CNCprocessing_create(obj) + except Exception as e: + logging.info('get_cnc_processing_create error:%s' % e) diff --git a/sf_route_workcenter/models/workcenter.py b/sf_route_workcenter/models/workcenter.py index 6d81fb08..ad260d11 100644 --- a/sf_route_workcenter/models/workcenter.py +++ b/sf_route_workcenter/models/workcenter.py @@ -21,6 +21,26 @@ class CNCprocessing(models.Model): workorder_id = fields.Many2one('mrp.workorder', string="工单") + # mrs下发编程单创建CNC加工 + def CNCprocessing_create(self, obj): + workorder = self.env['mrp.workorder'].search([('production_id', '=', obj['manufacturing_order_no']), + ('processing_panel', '=', obj['processing_panel']), + ('routing_type', '=', 'CNC加工')]) + self.env['cnc.processing'].create({ + 'workorder_id': workorder.id, + 'FNo': obj['sequence_number'], + 'FPGName': obj['program_name'], + 'FKnifeName': obj['cutting_tool_name'], + 'FDNo': obj['cutting_tool_no'], + 'FWorkType': obj['processing_type'], + 'FXY': obj['margin_x_y'], + 'FZ': obj['margin_z'], + 'FJGSD': obj['depth_of_processing_z'], + 'FSCCD': obj['cutting_tool_extension_length'], + 'FDJSpec': obj['cutting_tool_handle_type'], + # 'FJGDate': obj[''] + }) + class Tray(models.Model): _inherit = 'sf.tray' @@ -259,6 +279,7 @@ class MrpWorkOrder(models.Model): 'embryo_long': self.product_id.bom_ids.bom_line_ids.product_id.long, 'embryo_height': self.product_id.bom_ids.bom_line_ids.product_id.height, 'embryo_width': self.product_id.bom_ids.bom_line_ids.product_id.width + # 'factory_code': self.env.user.company_id.partner_id. }] configsettings = self.env['res.config.settings'].get_values() # token = configsettings['token']