From aa7e39c28a83b31e75029606a55cdc41f4d6a6ce Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Fri, 4 Aug 2023 17:33:21 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E5=85=A5=E5=BA=93=E6=97=B6=E5=AE=9E=E6=97=B6=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=A4=B9=E5=85=B7=E4=BA=A7=E5=93=81=E5=88=B0cloud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/fixture.py | 4 -- sf_manufacturing/models/product_template.py | 46 +++++++++++++++++++++ sf_manufacturing/models/stock.py | 3 +- sf_mrs_connect/models/res_config_setting.py | 8 ++-- 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/sf_base/models/fixture.py b/sf_base/models/fixture.py index d929cad9..8e56fd08 100644 --- a/sf_base/models/fixture.py +++ b/sf_base/models/fixture.py @@ -1,8 +1,4 @@ from odoo import models, fields, api -from odoo.addons.sf_base.commons.common import Common -from odoo.exceptions import ValidationError -import requests -import json class FixtureMaterial(models.Model): diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index 85f8313f..6bd94673 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -1,4 +1,8 @@ from odoo import models, fields, api +from odoo.addons.sf_base.commons.common import Common +from odoo.exceptions import ValidationError,UserError +import requests +import json class ResProductMo(models.Model): @@ -152,6 +156,12 @@ class ResProductMo(models.Model): fixture_through_hole_size = fields.Integer(string="过孔大小[mm]", size=6) fixture_screw_size = fields.Integer(string="螺牙大小[mm]", size=6) + def _json_apply_machine_tool_type_item_code(self, item): + code_arr = [] + for i in item.fixture_apply_machine_tool_type_ids: + code_arr.append(i.code) + return code_arr + def _get_ids(self, param): type_ids = [] if not param: @@ -350,6 +360,42 @@ class ResProductMo(models.Model): item.cutting_tool_standard_speed = False item.image_1920 = False + # 将采购到的夹具注册到Cloud + def _register_fixture(self): + config = self.env['res.config.settings'].get_values() + headers = Common.get_headers(self, config['token'], config['sf_secret_key']) + strurl = config['sf_url'] + self.crea_url + for item in self: + val = { + 'factory_token': config['token'], + 'name': item.name, + 'brand_id': item.brand_id.code, + 'materials_type_id': item.materials_type_id.code, + 'fixture_material_code': item.fixture_material_id.code, + 'fixture_multi_mounting_type_id': item.fixture_multi_mounting_type_id.code, + 'fixture_clamping_way': item.fixture_clamping_way, + 'fixture_port_type': item.fixture_port_type, + 'fixture_clamp_workpiece_length_max': item.fixture_clamp_workpiece_length_max, + 'fixture_clamp_workpiece_width_max': item.fixture_clamp_workpiece_width_max, + 'fixture_clamp_workpiece_height_max': item.fixture_clamp_workpiece_height_max.id, + 'fixture_clamp_workpiece_diameter_max': item.fixture_clamp_workpiece_diameter_max, + 'fixture_maximum_carrying_weight': item.fixture_maximum_carrying_weight, + 'fixture_maximum_clamping_force': item.fixture_maximum_clamping_force, + 'fixture_driving_way': item.fixture_driving_way, + 'fixture_apply_machine_tool_type_ids': self._json_apply_machine_tool_type_item_code(item), + 'fixture_through_hole_size': item.fixture_through_hole_size, + 'fixture_screw_size': item.fixture_screw_size, + } + try: + ret = requests.post(strurl, json={}, data=val, headers=headers) + ret = ret.json() + if ret['status'] == 200: + raise UserError(ret['message']) + else: + raise UserError(ret['message']) + except Exception as e: + raise UserError("注册夹具到云端失败,请联系管理员!") + class ResMrpBomMo(models.Model): _inherit = 'mrp.bom' diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index eab3a74c..71e23dc3 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -276,7 +276,8 @@ class StockPicking(models.Model): if picking_out.state != 'done': raise UserError( _('该入库单对应的单号为%s的出库单还未完成,不能进行验证操作!' % picking_out.name)) - + # 采购单验证(夹具和刀具) + if self.product_id.categ_type in ['刀具', '夹具']: res = super().button_validate() return res diff --git a/sf_mrs_connect/models/res_config_setting.py b/sf_mrs_connect/models/res_config_setting.py index 4d9c0ece..12ba5b31 100644 --- a/sf_mrs_connect/models/res_config_setting.py +++ b/sf_mrs_connect/models/res_config_setting.py @@ -61,12 +61,12 @@ class ResConfigSettings(models.TransientModel): _logger.info("同步夹具物料") self.env['sf.multi_mounting.type'].sync_all_multi_mounting_type() _logger.info("同步联装类型") - self.env['sf.fixture.model'].sync_all_fixture_model() - _logger.info("同步夹具型号") + # self.env['sf.fixture.model'].sync_all_fixture_model() + # _logger.info("同步夹具型号") self.env['sf.functional.fixture.type'].sync_all_functional_fixture_type() _logger.info("同步功能夹具类型") - self.env['sf.functional.fixture'].sync_all_functional_fixture() - _logger.info("同步功能夹具") + # self.env['sf.functional.fixture'].sync_all_functional_fixture() + # _logger.info("同步功能夹具") except Exception as e: _logger.info("捕获错误信息:%s" % e) raise ValidationError("数据错误导致同步失败,请联系管理员") From b3f2065edd7ad8391347bbaa009cced966821ad7 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Mon, 7 Aug 2023 17:29:17 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E5=A4=B9=E5=85=B7=E7=89=A9=E6=96=99?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/views/fixture_view.xml | 4 +- sf_dlm/views/product_template_view.xml | 4 +- sf_manufacturing/models/product_template.py | 137 +++++++------------- sf_manufacturing/models/stock.py | 51 ++++++++ 4 files changed, 105 insertions(+), 91 deletions(-) diff --git a/sf_base/views/fixture_view.xml b/sf_base/views/fixture_view.xml index 65cf2ce1..53714553 100644 --- a/sf_base/views/fixture_view.xml +++ b/sf_base/views/fixture_view.xml @@ -161,7 +161,7 @@ 夹具型号 sf.fixture.model - + @@ -175,7 +175,7 @@ 夹具型号 sf.fixture.model -
+ diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index 3fcdcf1b..2fc78eda 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -227,7 +227,7 @@ -