diff --git a/jikimo_frontend/static/src/scss/custom_style.scss b/jikimo_frontend/static/src/scss/custom_style.scss index 3ae7958c..d4df8c40 100644 --- a/jikimo_frontend/static/src/scss/custom_style.scss +++ b/jikimo_frontend/static/src/scss/custom_style.scss @@ -3,7 +3,7 @@ } .test_model > .o_form_label { - margin-left: 20px; + margin-left: 0px !important; margin-right: 0px !important; white-space: nowrap; } @@ -257,6 +257,12 @@ div[class="o_content o_component_with_search_panel"] .o_kanban_primary_right > . top: 55px; right: 43.5%; } +//------------------------------------------ + +.test_model > .o_form_label { + margin-left: 4px !important; + line-height: 0 !important; +} @media screen and (min-width: 1200px) { div[class="o_content o_component_with_search_panel"] .o_kanban_primary_right > .row { @@ -289,4 +295,49 @@ div[class="o_content o_component_with_search_panel"] .o_kanban_primary_right > . .text-bg-warning { background-color: #FED300 !important; -} \ No newline at end of file +} + +.test_model>div { + display: flex; + width: 40%; +} + +.test_model>div .o_field_widget { + width: 40% !important; +} + +.o_form_label { + font-weight: 700 !important; +} + +.bigger .o_horizontal_separator { + font-size: 1.5rem; +} + +.o_horizontal_separator { + font-size: 1.5rem; +} + +.o_field_widget input[class='o_input'] { +text-align: center +} + +div:has(.o_required_modifier) > label::before { + position: absolute; + left: -3px; +} + +.o_form_view .o_form_label { + position: relative; + width: 9rem; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + padding-left: 1rem; +} + +.o_form_view .o_form_label:hover { + white-space: normal; + overflow: visible; +} + diff --git a/sf_base/models/common.py b/sf_base/models/common.py index a6aaf0f8..e202a40e 100644 --- a/sf_base/models/common.py +++ b/sf_base/models/common.py @@ -67,7 +67,12 @@ class MrsMaterialModel(models.Model): mf_materia_post = fields.Char("热处理后密度") density = fields.Float("密度(kg/m³)") materials_id = fields.Many2one('sf.production.materials', "材料名") - tensile_strength = fields.Float("拉伸强度(n/mm²)") + tensile_strength = fields.Char("拉伸强度(n/mm²)") + standards_id = fields.Many2one('sf.international.standards', '制造标准') + alloy_code = fields.Char('合金牌号') + price = fields.Float('单价/kg') + apply = fields.Many2many('material.apply', string='材料应用') + materials_code = fields.Char('材料代号') hardness = fields.Float("硬度(hrc)") rough_machining = fields.Float("粗加工Vc(m/min)") finish_machining = fields.Float("精加工Vc(m/min)") @@ -96,7 +101,7 @@ class MrsProductionProcess(models.Model): _name = 'sf.production.process' _description = '表面工艺' - process_encode = fields.Char("编码") + code = fields.Char("编码") name = fields.Char('名称') remark = fields.Text("备注") processing_order_ids = fields.One2many('sf.processing.order', 'production_process_id', string='工序') @@ -113,7 +118,7 @@ class MrsProcessingTechnology(models.Model): name = fields.Char('名称', index=True) remark = fields.Text('备注', index=True) - process_encode = fields.Char("编码") + code = fields.Char("编码") processing_order_ids = fields.Many2many('sf.processing.order', 'sf_associated_processes', index=True, string='工序') active = fields.Boolean('有效', default=True) @@ -172,3 +177,20 @@ class MrsProductionProcessParameter(models.Model): for i in item.parameter_ids: code_arr.append(i.code) return code_arr + + +class ModelInternationalStandards(models.Model): + _name = 'sf.international.standards' + _description = '制造标准' + + code = fields.Char('编码') + name = fields.Char('名称') + active = fields.Boolean('有效', default=True) + + +class MrsMaterialApply(models.Model): + _name = 'material.apply' + _description = '材料应用' + + name = fields.Char('名称', default=True) + active = fields.Boolean('有效', default=True) diff --git a/sf_base/models/fixture.py b/sf_base/models/fixture.py index bc5b19f9..f7cb5fa8 100644 --- a/sf_base/models/fixture.py +++ b/sf_base/models/fixture.py @@ -30,7 +30,7 @@ class FixtureModel(models.Model): fixture_material_id = fields.Many2one('sf.fixture.material', string="夹具物料", ) fixture_material_type = fields.Char(string="夹具物料类型", related='fixture_material_id.name', store=True) multi_mounting_type_id = fields.Many2one('sf.multi_mounting.type', string="联装类型") - brand_id = fields.Many2one('sf.machine.brand', string="品牌") + brand_id = fields.Many2one('sf.machine.brand', string="品牌", domain="[('tag_ids.name', 'ilike', '夹具')]") clamping_way = fields.Char(string="装夹方式") port_type = fields.Char(string="接口类型") model_file = fields.Binary(string="3D模型图") diff --git a/sf_base/models/tool_base.py b/sf_base/models/tool_base.py index 2d7d7028..24a39ecc 100644 --- a/sf_base/models/tool_base.py +++ b/sf_base/models/tool_base.py @@ -70,7 +70,7 @@ class IntegralCuttingTool(models.Model): # 整体式刀具类型字段,关联整体式刀具类型对象 integral_model_number = fields.Many2one('sf.integral.cutting.tool.model', '整体式刀具类型') # 增加品牌、总长度(mm)、柄部长度(mm)、刃部长度(mm)、直径(mm)、刃数、前角(°)、后角(°)、主偏角(°)、材料型号、配对螺母(mm)、适用夹头型号、适用范围、图片、创建人、创建时间等字段 - brand = fields.Many2one('sf.machine.brand', '品牌') + brand = fields.Many2one('sf.machine.brand', '品牌', domain="[('tag_ids.name', 'ilike', '刀具')]") total_length = fields.Float('总长度(mm)') shank_length = fields.Float('柄部长度(mm)') blade_length = fields.Float('刃部长度(mm)') diff --git a/sf_base/models/tool_base_new.py b/sf_base/models/tool_base_new.py index fc62074e..c957ab06 100644 --- a/sf_base/models/tool_base_new.py +++ b/sf_base/models/tool_base_new.py @@ -101,7 +101,7 @@ class CuttingToolModel(models.Model): cutting_tool_type = fields.Char(string="刀具物料类型", related='cutting_tool_material_id.name', store=True) cutting_tool_type_id = fields.Many2one('sf.cutting.tool.type', string='刀具类型', ) - brand_id = fields.Many2one('sf.machine.brand', '品牌') + brand_id = fields.Many2one('sf.machine.brand', '品牌', domain="[('tag_ids.name', 'ilike', '刀具')]") tool_length = fields.Integer('长度(mm)') tool_width = fields.Integer('宽度(mm)') tool_height = fields.Integer('高度(mm)') diff --git a/sf_base/security/ir.model.access.csv b/sf_base/security/ir.model.access.csv index fefaeb1b..1829085c 100644 --- a/sf_base/security/ir.model.access.csv +++ b/sf_base/security/ir.model.access.csv @@ -24,6 +24,8 @@ access_sf_fixture_model,sf_fixture_model,model_sf_fixture_model,base.group_user, access_sf_functional_fixture_type,sf_functional_fixture_type,model_sf_functional_fixture_type,base.group_user,1,1,1,1 access_sf_functional_fixture,sf_functional_fixture,model_sf_functional_fixture,base.group_user,1,1,1,1 access_sf_sync_common,sf_sync_common,model_sf_sync_common,base.group_user,1,1,1,1 +access_sf_international_standards,sf_international_standards,model_sf_international_standards,base.group_user,1,1,1,1 +access_material_apply,material_apply,model_material_apply,base.group_user,1,1,1,1 diff --git a/sf_base/views/common_view.xml b/sf_base/views/common_view.xml index b079beda..a4853907 100644 --- a/sf_base/views/common_view.xml +++ b/sf_base/views/common_view.xml @@ -24,7 +24,7 @@ sf.processing.technology - + @@ -35,7 +35,7 @@ - + @@ -64,7 +64,7 @@ - + @@ -105,7 +105,7 @@ sf.production.process - + @@ -124,7 +124,7 @@ - + @@ -186,7 +186,7 @@ - + @@ -241,17 +241,20 @@ sf.materials.model - - - - + + + + + + - + - - - - + + + + + diff --git a/sf_base/views/ir_cron_mrs.xml b/sf_base/views/ir_cron_mrs.xml index a1e88354..748e1bb5 100644 --- a/sf_base/views/ir_cron_mrs.xml +++ b/sf_base/views/ir_cron_mrs.xml @@ -1,50 +1,50 @@ - - 基础信息同步:品牌类别 - - code - model._cron_machine_brand_tags_func() - 1 - days - -1 - - - + + + + + + + + + + + - - 基础信息同步:工序 - - code - model._cron_processing_order_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:品牌 - - code - model._cron_machine_brand_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:机床型号 - - code - model._cron_machine_tool_type_func() - 1 - days - -1 - - + + + + + + + + + + @@ -80,50 +80,50 @@ - - 基础信息同步:材料 - - code - model._cron_production_materials_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:材料型号 - - code - model._cron_materials_model_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:表面工艺类别 - - code - model._cron_production_process_category_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:表面工艺 - - code - model._cron_production_process_func() - 1 - days - -1 - - + + + + + + + + + + @@ -136,237 +136,127 @@ - - 基础信息同步:数控系统 - - code - model._cron_machine_control_system_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:模型类型 - - code - model._cron_model_type_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:可选参数 - - code - model._cron_mrs_production_process_parameter() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:机床类型 - - code - model._cron_machine_tool_category_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:功能刀具型号 - - code - model._cron_mrs_functional_cutting_tool_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:功能刀具类型 - - code - model._cron_mrs_functional_cutting_tool_model_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:整体式刀具 - - code - model._cron_mrs_integral_cutting_tool_func() - 1 - days - -1 - - + + + + + + + + + + + - - 基础信息同步:整体式刀具类型 - - code - model._cron_mrs_integral_cutting_tool_model_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:刀片型号 - - code - model._cron_mrs_blade_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:刀片类型 - - code - model._cron_mrs_blade_model_func() - 1 - days - -1 - - + + + + + + + + + + - - 基础信息同步:刀杆型号 - - code - model._cron_mrs_cutter_bar_func() - 1 - days - -1 - - - - - 基础信息同步:刀杆类型 - - code - model._cron_mrs_cutter_bar_model_func() - 1 - days - -1 - - - - - 基础信息同步:刀盘型号 - - code - model._cron_mrs_cutter_pad_func() - 1 - days - -1 - - - - - 基础信息同步:刀盘类型 - - code - model._cron_mrs_cutter_pad_model_func() - 1 - days - -1 - - - - - - 基础信息同步:刀柄型号 - - code - model._cron_mrs_handle_func() - 1 - days - -1 - - - - - 基础信息同步:刀柄类型 - - code - model._cron_mrs_handle_model_func() - 1 - days - -1 - - - - - 基础信息同步:夹具物料 - - code - model._cron_fixture_material_func() - 1 - days - -1 - - - - - 基础信息同步:联装类型 - - code - model._cron_multi_mounting_type_func() - 1 - days - -1 - - - - - 基础信息同步:夹具型号 - - code - model._cron_fixture_model_func() - 1 - days - -1 - - - - - 基础信息同步:功能夹具类型 - - code - model._cron_functional_fixture_type_func() - 1 - days - -1 - - - - - 基础信息同步:功能夹具 - - code - model._cron_functional_fixture_func() - 1 - days - -1 - - + + + + + + + + + + diff --git a/sf_base/views/tool_menu.xml b/sf_base/views/tool_menu.xml index eeaf0aca..4f6bb693 100644 --- a/sf_base/views/tool_menu.xml +++ b/sf_base/views/tool_menu.xml @@ -62,13 +62,13 @@ action="action_sf_cutting_tool_type" /> - + + + + + + + diff --git a/sf_bf_connect/controllers/product.py b/sf_bf_connect/controllers/product.py new file mode 100644 index 00000000..eb769a03 --- /dev/null +++ b/sf_bf_connect/controllers/product.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +import json +import logging +from odoo import http +from odoo.http import request + + +# class ProductController(http.Controller): +# +# @http.route('/api/cloud/get_cutting_model', type='http', auth='none', methods=['GET', 'POST'], csrf=False, +# cors="*") +# def get_cutting_model(self, **kw): diff --git a/sf_bf_connect/models/http.py b/sf_bf_connect/models/http.py index 6b0b3ebd..8f546c88 100644 --- a/sf_bf_connect/models/http.py +++ b/sf_bf_connect/models/http.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import logging -import datetime -import time +from datetime import datetime, timedelta import hashlib from odoo import models from odoo.http import request @@ -10,8 +9,6 @@ __author__ = 'jinling.yang' _logger = logging.getLogger(__name__) -class AuthenticationError(Exception): - pass class AuthenticationError(Exception): pass @@ -29,16 +26,18 @@ class Http(models.AbstractModel): # 查询密钥 factory_secret = request.env['res.partner'].sudo().search( [('sf_token', '=', datas['HTTP_TOKEN'])], limit=1) - logging.info('factory_secret:%s' % factory_secret) if not factory_secret: raise AuthenticationError('无效的token') - timestamp_str = int(time.time()) # 设置API接口请求时间,不能超过5秒 - deltime = datetime.timedelta(seconds=5) - # if abs(int(datas['HTTP_TIMESTAMP'])-timestamp_str) > deltime.seconds: + # deltime = datetime.timedelta(seconds=30) + # if abs(int(datas['HTTP_TIMESTAMP']) - timestamp_str) > deltime.seconds: # raise AuthenticationError('请求已过期') - # 获得sha1_str加密字符串 post_time = int(datas['HTTP_TIMESTAMP']) + datetime_post = datetime.fromtimestamp(post_time) + datetime_now = datetime.now().replace(microsecond=0) + datetime_del = datetime_now + timedelta(seconds=5) + if datetime_post > datetime_del: + raise AuthenticationError('请求已过期') check_str = '%s%s%s' % (datas['HTTP_TOKEN'], post_time, factory_secret.sf_secret_key) check_sf_str = hashlib.sha1(check_str.encode('utf-8')).hexdigest() if check_sf_str != datas['HTTP_CHECKSTR']: diff --git a/sf_dlm/views/product_template_view.xml b/sf_dlm/views/product_template_view.xml index dd86fc86..fbc12cee 100644 --- a/sf_dlm/views/product_template_view.xml +++ b/sf_dlm/views/product_template_view.xml @@ -106,7 +106,7 @@ - + - + diff --git a/sf_maintenance/views/maintenance_views.xml b/sf_maintenance/views/maintenance_views.xml index 500d6282..8156c886 100644 --- a/sf_maintenance/views/maintenance_views.xml +++ b/sf_maintenance/views/maintenance_views.xml @@ -49,7 +49,8 @@ - - + + + + + + + + + + + + + + + + + + + + + + @@ -231,6 +972,11 @@ + + + + + @@ -393,40 +1139,37 @@ maintenance.equipment.image.tree maintenance.equipment.image - - - - - + + + + + - - maintenance.equipment.image.form + + + maintenance.equipment.image.search maintenance.equipment.image -
- - - - - - - - - -
+ + + +
能力特征库 maintenance.equipment.image - tree,form + tree [] + + + + + sf_equipment.form + maintenance.equipment + + + + + + + + + + sf.maintenance.logs.tree + sf.maintenance.logs + + + + + + + \ No newline at end of file diff --git a/sf_manufacturing/views/sf_maintenance_equipment.xml b/sf_manufacturing/views/sf_maintenance_equipment.xml new file mode 100644 index 00000000..f072967b --- /dev/null +++ b/sf_manufacturing/views/sf_maintenance_equipment.xml @@ -0,0 +1,55 @@ + + + + + sf_equipment.form + maintenance.equipment + + + + + + + + + + sf.maintenance.logs.tree + sf.maintenance.logs + + + + + + + + + + sf_manufacturing_equipment.form + maintenance.equipment + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sf_mrs_connect/data/ir_cron_data.xml b/sf_mrs_connect/data/ir_cron_data.xml index c9f4b7e4..d3b13eb8 100644 --- a/sf_mrs_connect/data/ir_cron_data.xml +++ b/sf_mrs_connect/data/ir_cron_data.xml @@ -1,245 +1,223 @@ - - 同步资源库材料 - + + + 制造-配置:每日定时同步cloud的静态资源库 + code - model.sync_production_materials() + model._cron_static_resource_yesterday_func() 1 days -1 + + + + + + + + + + - - 同步资源库材料型号 - - code - model.sync_materials_model() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库表面工艺 - - code - model.sync_production_process() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库加工工艺 - - code - model.sync_processing_technology() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库标签 - - code - model.sync_machine_brand_tags() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库控制系统 - - code - model.sync_machine_tool_type_control_system() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库品牌 - - code - model.sync_machine_brand() - 1 - days - -1 - - + + + + + + + + + + - - 同步表面工艺类别 - - code - model.sync_production_process_category() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库机床型号 - - code - model.sync_machine_tool_type() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库工序 - - code - model.sync_processing_order() - 1 - days - -1 - - + + + + + + + + + + - - 同步表面工艺可选参数 - - code - model.sync_production_process_parameter() - 1 - days - -1 - - + + + + + + + + + + - - 同步资源库机床类型 - - code - model.sync_machine_tool_category() - 1 - days - -1 - - + + + + + + + + + + - - 同步刀具物料 - - code - model.sync_cutting_tool_material() - 1 - days - -1 - - + + + + + + + + + + - - 同步刀具类型 - - code - model.sync_tool_type() - 1 - days - -1 - - + + + + + + + + + + - - 同步刀具型号 - - code - model.sync_tool_model() - 1 - days - -1 - - + + + + + + + + + + - - 同步功能刀具型号 - - code - model.sync_functional_cutting_tool() - 1 - days - -1 - - + + + + + + + + + + - - 同步功能刀具类型 - - code - model.sync_functional_cutting_tool_model() - 1 - days - -1 - - + + + + + + + + + + - - 同步夹具物料 - - code - model.sync_fixture_material() - 1 - days - -1 - - + + + + + + + + + + - - 同步联装类型 - - code - model.sync_multi_mounting_type() - 1 - days - -1 - - - - - 同步夹具型号 - - code - model.sync_fixture_model() - 1 - days - -1 - - - - - 同步功能夹具类型 - - code - model.sync_functional_fixture_type() - 1 - days - -1 - - - - - 同步功能夹具 - - code - model.sync_functional_fixture() - 1 - days - -1 - - + + + + + + + + + + \ No newline at end of file diff --git a/sf_mrs_connect/models/res_config_setting.py b/sf_mrs_connect/models/res_config_setting.py index c158ab09..142dca7d 100644 --- a/sf_mrs_connect/models/res_config_setting.py +++ b/sf_mrs_connect/models/res_config_setting.py @@ -21,6 +21,10 @@ class ResConfigSettings(models.TransientModel): def sf_all_sync(self): try: + self.env['sf.international.standards'].sync_all_mrs_international_standards() + _logger.info("同步资源库国际标准完成") + self.env['material.apply'].sync_all_material_apply() + _logger.info("同步资源库材料应用完成") self.env['sf.production.materials'].sync_all_production_materials() _logger.info("同步资源库材料") self.env['sf.materials.model'].sync_all_materials_model() @@ -29,44 +33,41 @@ class ResConfigSettings(models.TransientModel): _logger.info("同步资源库表面工艺类别") self.env['sf.production.process'].sync_all_production_process() _logger.info("同步资源库表面工艺") - self.env['sf.processing.technology'].sync_all_processing_technology() - _logger.info("同步资源库加工工艺") + # self.env['sf.processing.technology'].sync_all_processing_technology() + # _logger.info("同步资源库加工工艺") self.env['sf.machine.brand.tags'].sync_all_machine_brand_tags() _logger.info("同步资源库品牌类别") self.env['sf.machine.brand'].sync_all_machine_brand() _logger.info("同步资源库品牌") - self.env['sf.machine.control_system'].sync_all_machine_tool_type_control_system() + self.env['sf.machine.control_system'].sync_all_machine_control_system() _logger.info("同步资源库控制系统") self.env['sf.machine_tool.category'].sync_all_machine_tool_category() _logger.info("同步资源库机床类型") - # self.env['sf.production.process.parameter'].sync_all_production_process_parameter() - # _logger.info("同步表面工艺参数") - _logger.info("同步所有刀具物料...") + self.env['sf.production.process.parameter'].sync_all_production_process_parameter() + _logger.info("同步刀具物料") self.env['sf.cutting.tool.material'].sync_all_cutting_tool_material() - _logger.info("同步所有刀具物料完成") - _logger.info("同步所有刀具类型...") + _logger.info("同步刀具类型") self.env['sf.cutting.tool.type'].sync_all_tool_type() _logger.info("同步所有刀具类型完成") - _logger.info("同步所有刀具型号...") - self.env['sf.cutting.tool.model'].sync_all_tool_model() + # _logger.info("同步所有刀具型号...") + # self.env['sf.cutting.tool.model'].sync_all_tool_model() _logger.info("同步所有刀具型号完成") - _logger.info("定时同步所有功能刀具类型列表...") self.env['sf.functional.cutting.tool.model'].sync_all_functional_cutting_tool_model() - _logger.info("同步所有功能刀具类型完成") - # _logger.info("同步所有功能刀具列表...") - # self.env['sf.functional.cutting.tool'].sync_all_functional_cutting_tool() - # _logger.info("同步所有功能刀具列表完成") - self.env['sf.fixture.material'].sync_all_fixture_material() _logger.info("同步夹具物料") - self.env['sf.multi_mounting.type'].sync_all_multi_mounting_type() + self.env['sf.fixture.material'].sync_all_fixture_material() _logger.info("同步联装类型") - self.env['sf.fixture.model'].sync_all_fixture_model() + self.env['sf.multi_mounting.type'].sync_all_multi_mounting_type() _logger.info("同步夹具型号") - self.env['sf.functional.fixture.type'].sync_all_functional_fixture_type() + self.env['sf.fixture.model'].sync_all_fixture_model() _logger.info("同步功能夹具类型") - self.env['sf.functional.fixture'].sync_all_functional_fixture() + # self.env['sf.functional.fixture'].sync_all_functional_fixture() + + self.env['sf.functional.fixture.type'].sync_all_functional_fixture_type() + self.env['sf.machine_tool.type'].sync_all_machine_tool_type() - _logger.info("同步资源库机床型号") + _logger.info("同步资源库机床型号完成") + self.env['maintenance.equipment.image'].sync_all_maintenance_equipment_image() + _logger.info("同步能力特征库") except Exception as e: _logger.info("捕获错误信息:%s" % e) raise ValidationError("数据错误导致同步失败,请联系管理员") diff --git a/sf_mrs_connect/models/sync_common.py b/sf_mrs_connect/models/sync_common.py index 3d309689..a326d024 100644 --- a/sf_mrs_connect/models/sync_common.py +++ b/sf_mrs_connect/models/sync_common.py @@ -10,54 +10,101 @@ from odoo.addons.sf_base.commons.common import Common _logger = logging.getLogger(__name__) +class MrStaticResourceDataSync(models.Model): + _name = 'sf.static.resource.datasync' + _description = '同步cloud的静态资源库' + + def _cron_static_resource_yesterday_func(self): + try: + self.env['sf.machine.brand.tags'].sync_machine_brand_tags_yesterday() + logging.info("品牌类别已每日同步成功") + self.env['sf.machine.brand'].sync_machine_brand_yesterday() + logging.info("品牌已每日同步成功") + self.env['sf.machine_tool.category'].sync_machine_tool_category_yesterday() + logging.info("机床类型已每日同步成功") + self.env['sf.machine_tool.type'].sync_machine_tool_type_yesterday() + logging.info("机床型号已每日同步成功") + self.env['sf.machine.control_system'].sync_machine_control_system_yesterday() + logging.info("数控系统已每日同步成功") + self.env['sf.production.materials'].sync_production_materials_yesterday() + logging.info("材料已每日同步成功") + self.env['sf.materials.model'].sync_materials_model_yesterday() + # logging.info("材料型号已每日同步成功") + # self.env['mrs.international.standards']._cron_mrs_international_standards_func() + # logging.info("材料型号材料应用已每日同步成功") + # self.env['material.apply']._cron_material_apply_func() + logging.info("材料型号材料应用已每日同步成功") + self.env['sf.production.process.category'].sync_production_process_category_yesterday() + logging.info("表面工艺类别已每日同步成功") + self.env['sf.production.process'].sync_production_process_yesterday() + logging.info("表面工艺已每日同步成功") + self.env['sf.production.process.parameter'].sync_production_process_parameter_yesterday() + logging.info("表面工艺可选参数已每日同步成功") + self.env['sf.processing.technology'].sync_processing_technology_yesterday() + logging.info("加工工艺已每日同步成功") + self.env['sf.processing.order'].sync_processing_order_yesterday() + logging.info("工序已同步已每日同步成功") + self.env['sf.fixture.material'].sync_fixture_material_yesterday() + logging.info("夹具物料已每日同步成功") + self.env['sf.multi_mounting.type'].sync_multi_mounting_type_yesterday() + logging.info("联装类型已每日同步成功") + self.env['sf.fixture.model'].sync_fixture_model_yesterday() + logging.info("夹具型号已每日同步成功") + self.env['sf.functional.fixture.type'].sync_functional_fixture_type_yesterday() + logging.info("功能夹具类型已每日同步成功") + self.env['sf.cutting.tool.material'].sync_cutting_tool_material_yesterday() + logging.info("刀具物料已每日同步成功") + self.env['sf.cutting.tool.type'].sync_tool_type_yesterday() + logging.info("刀具类型已每日同步成功") + self.env['sf.functional.cutting.tool.model'].sync_functional_cutting_tool_model_yesterday() + logging.info("功能刀具类型已每日同步成功") + self.env['maintenance.equipment.image'].sync_maintenance_equipment_image_yesterday() + logging.info("能力特征库已每日同步成功") + except Exception as e: + logging.info("捕获错误信息:%s" % e) + raise ValidationError("数据错误导致同步失败,请联系管理员") + + class sfProductionMaterials(models.Model): _inherit = "sf.production.materials" _description = "材料" url = '/api/production_materials/list' # 定时同步每日材料 - def sync_production_materials(self): - + def sync_production_materials_yesterday(self): # 配置中获取token sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['production_materials_yesterday_list']: if item: - brand = self.env['sf.production.materials'].search( - [("materials_no", '=', item['materials_no'])]) - if brand: - brand.id = item['id'], - brand.name = item['name'], - brand.remark = item['remark'], - brand.active = item['active'] + materials = self.search([("materials_no", '=', item['materials_no'])]) + if materials: + materials.name = item['name'] + materials.remark = item['remark'] + materials.active = item['active'] else: - self.env['sf.production.materials'].create({ - "id": item['id'], + self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], - "active": item['active'] + "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("材料认证未通过") # 同步所有材料 def sync_all_production_materials(self): - _logger = '正在同步所有材料' sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -65,19 +112,20 @@ class sfProductionMaterials(models.Model): if result['status'] == 1: for item in result['production_materials_all_list']: if item: - - brand = self.env['sf.production.materials'].search( - [("materials_no", '=', item['materials_no'])]) - if not brand: - self.env['sf.production.materials'].create({ - "id": item['id'], + materials = self.search([("materials_no", '=', item['materials_no'])]) + if not materials: + self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], - "active": item['active'] + "active": item['active'], }) + else: + materials.name = item['name'] + materials.remark = item['remark'] + materials.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("材料认证未通过") class sfMaterialModel(models.Model): @@ -86,12 +134,11 @@ class sfMaterialModel(models.Model): url = '/api/materials_model/list' # 定时同步每日材料型号 - def sync_materials_model(self): + def sync_materials_model_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -99,26 +146,25 @@ class sfMaterialModel(models.Model): if result['status'] == 1: for item in result['materials_model_yesterday_list']: if item: - materials_model = self.env['sf.materials.model'].search( - [("materials_no", '=', item['materials_no'])]) + materials_model = self.search([("materials_no", '=', item['materials_no'])]) + materials = self.env['sf.production.materials'].search( + [("materials_no", '=', item['materials_id.materials_no'])]) if materials_model: - materials_model.id = item['id'], - materials_model.name = item['name'], - materials_model.materials_no = item['materials_no'], - materials_model.remark = item['remark'], - materials_model.tensile_strength = item['tensile_strength'], - materials_model.hardness = item['hardness'], - materials_model.materials_no = item['materials_no'], - materials_model.rough_machining = item['rough_machining'], - materials_model.finish_machining = item['finish_machining'], - materials_model.mf_materia_post = item['mf_materia_post'], - materials_model.materials_id = self.env['sf.production.materials'].search( - [("materials_no", '=', item['materials_id.materials_no'])]).id, - materials_model.need_h = item['need_h'], + materials_model.name = item['name'] + materials_model.materials_no = item['materials_no'] + materials_model.remark = item['remark'] + materials_model.tensile_strength = item['tensile_strength'] + materials_model.hardness = item['hardness'] + materials_model.materials_no = item['materials_no'] + materials_model.rough_machining = item['rough_machining'] + materials_model.finish_machining = item['finish_machining'] + materials_model.mf_materia_post = item['mf_materia_post'] + materials_model.materials_id = materials.id + materials_model.need_h = item['need_h'] materials_model.density = item['density'] + materials_model.active = item['active'] else: - self.env['sf.materials.model'].create({ - "id": item['id'], + self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], @@ -127,16 +173,13 @@ class sfMaterialModel(models.Model): "rough_machining": item['rough_machining'], "finish_machining": item['finish_machining'], "active": item['active'], - "materials_id": self.env['sf.production.materials'].search( - [("materials_no", '=', item['materials_id.materials_no'])]).id, + "materials_id": materials.id, "need_h": item['need_h'], "mf_materia_post": item['mf_materia_post'], "density": item['density'], - # "tag_ids": item['tag_ids'] - }) else: - raise ValidationError("认证未通过") + raise ValidationError("材料型号认证未通过") # 同步所有材料型号 def sync_all_materials_model(self): @@ -151,10 +194,11 @@ class sfMaterialModel(models.Model): if result['status'] == 1: for item in result['materials_model_all_list']: if item: - materials_model = self.env['sf.materials.model'].search( - [("materials_no", '=', item['materials_no'])]) + materials_model = self.search([("materials_no", '=', item['materials_no'])]) + materials = self.env['sf.production.materials'].search( + [("materials_no", '=', item['materials_id.materials_no'])]) if not materials_model: - self.env['sf.materials.model'].create({ + self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], @@ -165,14 +209,33 @@ class sfMaterialModel(models.Model): "finish_machining": item['finish_machining'], "materials_id": self.env['sf.production.materials'].search( [("materials_no", '=', item['materials_id.materials_no'])]).id, + "standards_id": self.env['sf.international.standards'].search( + [("name", '=', item['standards_id'])]).id, "need_h": item['need_h'], + "alloy_code": item['alloy_code'], "mf_materia_post": item['mf_materia_post'], "density": item['density'], + "materials_code": item['materials_code'], + "apply": self.env['material.apply'].search( + [("name", 'in', item['apply'])]).ids # "tag_ids": item['tag_ids'] }) + else: + materials_model.name = item['name'] + materials_model.remark = item['remark'] + materials_model.tensile_strength = item['tensile_strength'] + materials_model.hardness = item['hardness'] + materials_model.materials_no = item['materials_no'] + materials_model.rough_machining = item['rough_machining'] + materials_model.finish_machining = item['finish_machining'] + materials_model.mf_materia_post = item['mf_materia_post'] + materials_model.materials_id = materials.id + materials_model.need_h = item['need_h'] + materials_model.density = item['density'] + materials_model.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("材料型号认证未通过") class sfProductionProcessCategory(models.Model): @@ -181,12 +244,11 @@ class sfProductionProcessCategory(models.Model): url = '/api/production_process_category/list' # 定时同步每日表面工艺类别 - def sync_production_process_category(self): + def sync_production_process_category_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -194,20 +256,19 @@ class sfProductionProcessCategory(models.Model): if result['status'] == 1: for item in result['production_process_category_yesterday_list']: if item: - production_process_category = self.env['sf.production.process.category'].search( - [("code", '=', item['code'])]) + production_process_category = self.search([("code", '=', item['code'])]) if production_process_category: - production_process_category.name = item['name'], - production_process_category.code = item['code'], + production_process_category.name = item['name'] + production_process_category.code = item['code'] production_process_category.active = item['active'] else: - self.env['sf.production.process.category'].create({ + self.create({ "name": item['name'], "code": item['code'], "active": item['active'], }) else: - raise ValidationError("认证未通过") # 定时同步表面工艺 + raise ValidationError("表面工艺类别认证未通过") # 同步所有表面工艺类别 def sync_all_production_process_category(self): @@ -215,7 +276,6 @@ class sfProductionProcessCategory(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -223,16 +283,18 @@ class sfProductionProcessCategory(models.Model): if result['status'] == 1: for item in result['production_process_category_all_list']: if item: - category = self.env['sf.production.process.category'].search( - [("code", '=', item['code'])]) + category = self.search([("code", '=', item['code'])]) if not category: - self.env['sf.production.process.category'].create({ + self.create({ "name": item['name'], "code": item['code'], "active": item['active'], }) + else: + category.name = item['name'] + category.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("表面工艺类别认证未通过") class sfProductionProcess(models.Model): @@ -241,12 +303,11 @@ class sfProductionProcess(models.Model): url = '/api/production_process/list' # 定时同步每日表面工艺 - def sync_production_process(self): + def sync_production_process_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -255,26 +316,34 @@ class sfProductionProcess(models.Model): for item in result['production_process_yesterday_list']: if item: brand = self.env['sf.production.process'].search( - [("process_encode", '=', item['process_encode'])]) + [("code", '=', item['code'])]) if brand: brand.name = item['name'], brand.category_id = self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]).id, - brand.process_encode = item['process_encode'], + brand.code = item['code'], brand.remark = item['remark'], brand.active = item['active'], brand.remark = item['remark'] + production_process = self.search([("code", '=', item['code'])]) + category = self.env['sf.production.process.category'].search( + [("code", '=', item['category_code'])]) + if production_process: + production_process.name = item['name'] + production_process.category_id = category.id + production_process.remark = item['remark'] + production_process.active = item['active'] else: - self.env['sf.production.process'].create({ + self.create({ "name": item['name'], "category_id": self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]).id, - "process_encode": item['process_encode'], + "code": item['code'], "remark": item['remark'], "active": item['active'], }) else: - raise ValidationError("认证未通过") # 定时同步表面工艺 + raise ValidationError("表面工艺认证未通过") # 同步所有表面工艺 def sync_all_production_process(self): @@ -282,7 +351,6 @@ class sfProductionProcess(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -290,21 +358,25 @@ class sfProductionProcess(models.Model): if result['status'] == 1: for item in result['production_process_all_list']: if item: - brand = self.env['sf.production.process'].search( - [("process_encode", '=', item['process_encode'])]) - if not brand: - self.env['sf.production.process'].create({ + production_process = self.search([("code", '=', item['code'])]) + category = self.env['sf.production.process.category'].search( + [("code", '=', item['category_code'])]) + if not production_process: + self.create({ "name": item['name'], - "category_id": self.env['sf.production.process.category'].search( - [("code", '=', item['category_code'])]).id, - "process_encode": item['process_encode'], + "category_id": category.id, + "code": item['code'], "remark": item['remark'], "active": item['active'], - # "tag_ids": item['tag_ids'] - }) + else: + production_process.name = item['name'] + production_process.category_id = category.id + production_process.remark = item['remark'] + production_process.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("表面工艺认证未通过") + class sfProcessingTechnology(models.Model): @@ -313,12 +385,11 @@ class sfProcessingTechnology(models.Model): url = '/api/processing_technology/list' # 定时同步加工工艺 - def sync_processing_technology(self): + def sync_processing_technology_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -326,26 +397,20 @@ class sfProcessingTechnology(models.Model): if result['status'] == 1: for item in result['processing_technology_yesterday_list']: if item: - brand = self.env['sf.processing.technology'].search( - [("process_encode", '=', item['process_encode'])]) - if brand: - brand.id = item['id'], - brand.name = item['name'], - brand.process_encode = item['process_encode'], - brand.remark = item['remark'], - brand.active = item['active'] + processing_technology = self.search([("code", '=', item['code'])]) + if processing_technology: + processing_technology.name = item['name'] + processing_technology.remark = item['remark'] + processing_technology.active = item['active'] else: - self.env['sf.processing.technology'].create({ - "id": item['id'], + self.create({ "name": item['name'], - "process_encode": item['process_encode'], + "code": item['code'], "remark": item['remark'], "active": item['active'], - # "tag_ids": item['tag_ids'] - }) else: - raise ValidationError("认证未通过") + raise ValidationError("加工工艺认证未通过") # 同步所有加工工艺 def sync_all_processing_technology(self): @@ -353,7 +418,6 @@ class sfProcessingTechnology(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -361,20 +425,20 @@ class sfProcessingTechnology(models.Model): if result['status'] == 1: for item in result['processing_technology_all_list']: if item: - brand = self.env['sf.processing.technology'].search( - [("process_encode", '=', item['process_encode'])]) - if not brand: - self.env['sf.processing.technology'].create({ - "id": item['id'], + processing_technology = self.search([("code", '=', item['code'])]) + if not processing_technology: + self.create({ "name": item['name'], - "process_encode": item['process_encode'], + "code": item['code'], "remark": item['remark'], "active": item['active'], - # "tag_ids": item['tag_ids'] - }) + else: + processing_technology.name = item['name'] + processing_technology.remark = item['remark'] + processing_technology.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("加工工艺认证未通过") class MachineBrandTags(models.Model): @@ -383,33 +447,28 @@ class MachineBrandTags(models.Model): url = '/api/machine_brand_tags/list' # 定时同步品牌类别 - def sync_machine_brand_tags(self): + def sync_machine_brand_tags_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_tags_yesterday_list']: - brand = self.env['sf.machine.brand.tags'].search( - [("id", '=', item['id'])]) - if brand: - brand.id = item['id'], - brand.name = item['name'], - brand.color = item['color'] + brand_tags = self.search([("id", '=', item['id'])]) + if brand_tags: + brand_tags.name = item['name'] + brand_tags.color = item['color'] else: - self.env['sf.machine.brand.tags'].create({ - "id": item['id'], + self.create({ "name": item['name'], "color": item['color'], - }) else: - raise ValidationError("认证未通过") + raise ValidationError("品牌类别认证未通过") # 同步所有品牌类别 def sync_all_machine_brand_tags(self): @@ -424,32 +483,30 @@ class MachineBrandTags(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_tags_all_list']: - brand = self.env['sf.machine.brand.tags'].search( - [("name", '=', item['name'])]) - if not brand: - self.env['sf.machine.brand.tags'].create({ - "id": item['id'], + brand_tags = self.search([("name", '=', item['name'])]) + if not brand_tags: + self.create({ "name": item['name'], "color": item['color'], - }) - + else: + brand_tags.name = item['name'] + brand_tags.color = item['color'] else: - raise ValidationError("认证未通过") + raise ValidationError("品牌类别认证未通过") class MachineControlSystem(models.Model): _inherit = 'sf.machine.control_system' - _description = '控制系统' + _description = '数控系统' url = '/api/machine_control_system/list' # 定时同步控制系统 - def sync_machine_tool_type_control_system(self): + def sync_machine_control_system_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -457,61 +514,54 @@ class MachineControlSystem(models.Model): if result['status'] == 1: for item in result['machine_control_system_yesterday_list']: if item: - brand = self.env['sf.machine.control_system'].search( - [("code", '=', item['code'])]) - if brand: - brand.id = item['id'], - brand.name = item['name'], - brand.code = item['code'], - brand.remark = item['remark'], - brand.brand_id = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, - brand.active = item['active'] + control_system = self.search([("code", '=', item['code'])]) + brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) + if control_system: + control_system.name = item['name'] + control_system.remark = item['remark'] + control_system.brand_id = brand.id + control_system.active = item['active'] else: - self.env['sf.machine.control_system'].create({ - "id": item['id'], + self.create({ "remark": item['remark'], "name": item['name'], "code": item['code'], - - 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, + 'brand_id': brand.id, "active": item['active'], - # "tag_ids": item['tag_ids'] - }) else: - raise ValidationError("认证未通过") + raise ValidationError("数控系统认证未通过") # 同步所有控制系统 - def sync_all_machine_tool_type_control_system(self): + def sync_all_machine_control_system(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_control_system_all_list']: if item: - brand = self.env['sf.machine.control_system'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.machine.control_system'].create({ - "id": item['id'], + control_system = self.search([("code", '=', item['code'])]) + brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) + if not control_system: + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], - 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, - + 'brand_id': brand.id, "active": item['active'], - # "tag_ids": item['tag_ids'] - }) + else: + control_system.name = item['name'] + control_system.remark = item['remark'] + control_system.brand_id = brand.id + control_system.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("数控系统认证未通过") class MachineBrand(models.Model): @@ -520,40 +570,35 @@ class MachineBrand(models.Model): url = '/api/machine_brand/list' # 定时同步品牌 - def sync_machine_brand(self): + def sync_machine_brand_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_yesterday_list']: - brand = self.env['sf.machine.brand'].search( - [("code", '=', item['code'])]) + brand = self.search([("code", '=', item['code'])]) if brand: - brand.id = item['id'], - brand.name = item['name'], - brand.code = item['code'], - brand.image_brand = '' if not item['image_brand'] else base64.b64encode(item.image_brand), - brand.active = item['active'], - brand.remark = item['remark'], + brand.name = item['name'] + brand.image_brand = '' if not item['image_brand'] else base64.b64decode(item['image_brand']) + brand.active = item['active'] + brand.remark = item['remark'] + brand.tag_ids = self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).ids else: - self.env['sf.machine.brand'].create({ - "id": item['id'], + self.create({ "name": item['name'], "code": item['code'], - "image_brand": '' if not item['image_brand'] else base64.b64encode(item.image_brand), + "image_brand": '' if not item['image_brand'] else base64.b64decode(item['image_brand']), "active": item['active'], "remark": item['remark'], - + "tag_ids": self.env['sf.machine.brand.tags'].search([("name", 'in', item['tag_ids'])]).ids, }) else: - raise ValidationError("认证未通过") + raise ValidationError("品牌认证未通过") # 同步所有品牌 def sync_all_machine_brand(self): @@ -561,33 +606,30 @@ class MachineBrand(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_all_list']: - - brand = self.env['sf.machine.brand'].search( - [("code", '=', item['code'])]) + brand = self.search([("code", '=', item['code'])]) if not brand: - if item.get('image_brand'): - image = base64.b64decode(item['image_brand']) - else: - image = '' - self.env['sf.machine.brand'].create({ - "id": item['id'], + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], - "image_brand": image, + "image_brand": '' if not item['image_brand'] else base64.b64decode(item['image_brand']), "tag_ids": self.env['sf.machine.brand.tags'].search( [("name", 'in', item['tag_ids'])]).ids }) + else: + brand.name = item['name'] + brand.remark = item['remark'] + brand.image_brand = '' if not item['image_brand'] else base64.b64decode(item['image_brand']) + brand.tag_ids = self.env['sf.machine.brand.tags'].search( + [("name", 'in', item['tag_ids'])]).ids else: - raise ValidationError("认证未通过") + raise ValidationError("品牌认证未通过") class MachineToolType(models.Model): @@ -596,50 +638,25 @@ class MachineToolType(models.Model): url = '/api/machine_tool_type/list' # 定时同步机床型号 - def sync_machine_tool_type(self): + def sync_machine_tool_type_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_type_yesterday_list']: - brand = self.env['sf.machine_tool.type'].search( - [("code", '=', item['code'])]) - if brand: - brand.id = item['id'], - brand.knife_type = item['knife_type'], - brand.name = item['name'], - brand.code = item['code'], - brand.precision_min = item['precision_min'], - brand.precision_max = item['precision_max'], - brand.number_of_knife_library = item['number_of_knife_library'], - brand.rotate_speed = item['rotate_speed'], - brand.number_of_axles = item['number_of_axles'], - brand.control_system_id = self.env['sf.machine.control_system'].search( - [('code', '=', item['control_system_id'])]).id, - - brand.x_axis = item['x_axis'], - brand.y_axis = item['y_axis'], - brand.z_axis = item['z_axis'], - brand.b_axis = item['b_axis'], - brand.c_axis = item['c_axis'], - brand.active = item['active'], - brand.remark = item['remark'], - brand.brand_id = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, - - else: - # print(item['machine_tool_picture'].encode('utf-8')) - self.env['sf.machine_tool.type'].create({ - "id": item['id'], + machine_tool_type = self.search([("code", '=', item['code'])]) + control_system = self.env['sf.machine.control_system'].search( + [('code', '=', item['control_system_id'])]) + brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) + category = self.env['sf.machine_tool.category'].search([('code', '=', item['machine_tool_category'])]) + if machine_tool_type: + machine_tool_type.write({ "name": item['name'], - "code": item['code'], - "knife_type": item['knife_type'], - "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], @@ -647,15 +664,16 @@ class MachineToolType(models.Model): "y_axis": item['y_axis'], "z_axis": item['z_axis'], "b_axis": item['b_axis'], + "knife_type": item['knife_type'], "c_axis": item['c_axis'], "remark": item['remark'], "precision_min": item['precision_min'], "precision_max": item['precision_max'], - 'control_system_id': self.env['sf.machine.control_system'].search( - [('code', '=', item['control_system_id'])]).id, + 'control_system_id': control_system.id, "active": item['active'], - 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, - 'machine_tool_picture': item['machine_tool_picture'].encode('utf-8'), + 'brand_id': brand.id, + 'machine_tool_picture': '' if not item['machine_tool_picture'] else base64.b64decode( + item['machine_tool_picture']), "heightened_way": item['heightened_way'], "workpiece_load": item['workpiece_load'], "lead_screw": item['lead_screw'], @@ -676,12 +694,53 @@ class MachineToolType(models.Model): "tool_long_max": item['tool_long_max'], "tool_diameter_max": item['tool_diameter_max'], "tool_diameter_min": item['tool_diameter_min'], - "machine_tool_category": self.env['sf.machine_tool.category'].search( - [('code', '=', item['machine_tool_category'])]).id, - + "machine_tool_category": category.id, + }) + else: + self.create({ + "name": item['name'], + "code": item['code'], + "knife_type": item['knife_type'], + "number_of_knife_library": item['number_of_knife_library'], + "rotate_speed": item['rotate_speed'], + "number_of_axles": item['number_of_axles'], + "x_axis": item['x_axis'], + "y_axis": item['y_axis'], + "z_axis": item['z_axis'], + "b_axis": item['b_axis'], + "c_axis": item['c_axis'], + "remark": item['remark'], + "precision_min": item['precision_min'], + "precision_max": item['precision_max'], + 'control_system_id': control_system.id, + "active": item['active'], + 'brand_id': brand.id, + 'machine_tool_picture': '' if not item['machine_tool_picture'] else item[ + 'machine_tool_picture'].encode('utf-8'), + "heightened_way": item['heightened_way'], + "workpiece_load": item['workpiece_load'], + "lead_screw": item['lead_screw'], + "workbench_L": item['workbench_L'], + "workbench_W": item['workbench_W'], + "guide_rail": item['guide_rail'], + "machine_tool_L": item['machine_tool_L'], + "machine_tool_W": item['machine_tool_W'], + "machine_tool_H": item['machine_tool_H'], + "feed_speed": item['feed_speed'], + "tool_speed": item['tool_speed'], + "distance_min": item['distance_min'], + "distance_max": item['distance_max'], + "taper": item['taper'], + "torque": item['torque'], + "motor_power": item['motor_power'], + "tool_quality_max": item['tool_quality_max'], + "tool_long_max": item['tool_long_max'], + "tool_diameter_max": item['tool_diameter_max'], + "tool_diameter_min": item['tool_diameter_min'], + "machine_tool_category": category.id, }) else: - raise ValidationError("认证未通过") + raise ValidationError("机床型号认证未通过") # 同步所有机床型号 def sync_all_machine_tool_type(self): @@ -689,7 +748,6 @@ class MachineToolType(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -700,14 +758,15 @@ class MachineToolType(models.Model): image = base64.b64decode(item['machine_tool_picture']) else: image = '' - brand = self.env['sf.machine_tool.type'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.machine_tool.type'].create({ - "id": item['id'], + machine_tool_type = self.search([("code", '=', item['code'])]) + control_system = self.env['sf.machine.control_system'].search( + [('code', '=', item['control_system_id'])]) + brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) + category = self.env['sf.machine_tool.category'].search([('code', '=', item['machine_tool_category'])]) + if not machine_tool_type: + self.create({ "name": item['name'], "code": item['code'], - "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], @@ -720,10 +779,9 @@ class MachineToolType(models.Model): "remark": item['remark'], "precision_min": item['precision_min'], "precision_max": item['precision_max'], - 'control_system_id': self.env['sf.machine.control_system'].search( - [('code', '=', item['control_system_id'])]).id, + 'control_system_id': control_system.id, "active": item['active'], - 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, + 'brand_id': brand.id, 'machine_tool_picture': image, "heightened_way": item['heightened_way'], "workpiece_load": item['workpiece_load'], @@ -745,15 +803,11 @@ class MachineToolType(models.Model): "tool_long_max": item['tool_long_max'], "tool_diameter_max": item['tool_diameter_max'], "tool_diameter_min": item['tool_diameter_min'], - "machine_tool_category": self.env['sf.machine_tool.category'].search( - [('code', '=', item['machine_tool_category'])]).id, - + "machine_tool_category": category.id, }) else: - brand.write({ - "id": item['id'], + machine_tool_type.write({ "name": item['name'], - "code": item['code'], "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], "number_of_axles": item['number_of_axles'], @@ -766,11 +820,10 @@ class MachineToolType(models.Model): "remark": item['remark'], "precision_min": item['precision_min'], "precision_max": item['precision_max'], - 'control_system_id': self.env['sf.machine.control_system'].search( - [('code', '=', item['control_system_id'])]).id, + 'control_system_id': control_system.id, "active": item['active'], - 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]).id, - 'machine_tool_picture': base64.b64decode(item['machine_tool_picture']), + 'brand_id': brand.id, + 'machine_tool_picture': image, "heightened_way": item['heightened_way'], "workpiece_load": item['workpiece_load'], "lead_screw": item['lead_screw'], @@ -791,12 +844,10 @@ class MachineToolType(models.Model): "tool_long_max": item['tool_long_max'], "tool_diameter_max": item['tool_diameter_max'], "tool_diameter_min": item['tool_diameter_min'], - "machine_tool_category": self.env['sf.machine_tool.category'].search( - [('code', '=', item['machine_tool_category'])]).id, - + "machine_tool_category": category.id, }) else: - raise ValidationError("认证未通过") + raise ValidationError("机床型号认证未通过") class sfProcessingOrder(models.Model): @@ -805,31 +856,26 @@ class sfProcessingOrder(models.Model): url = '/api/processing_order/list' # 定时同步工序 - def sync_processing_order(self): + def sync_processing_order_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_order_yesterday_list']: - brand = self.env['sf.processing.order'].search( - [("id", '=', item['id'])]) - if brand: - brand.id = item['id'] - brand.sequence = item['sequence'] + processing_order = self.search([("id", '=', item['id'])]) + if processing_order: + processing_order.sequence = item['sequence'] else: - self.env['sf.processing.order'].create({ - "id": item['id'], + self.create({ "sequence": item['sequence'], - }) else: - raise ValidationError("认证未通过") + raise ValidationError("工序认证未通过") # 同步所有工序 def sync_all_processing_order(self): @@ -837,22 +883,21 @@ class sfProcessingOrder(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_order_all_list']: - brand = self.env['sf.processing.order'].search( - [("id", '=', item['id'])]) - if not brand: - self.env['sf.processing.order'].create({ - "id": item['id'], + processing_order = self.search([("id", '=', item['id'])]) + if not processing_order: + self.create({ "sequence": item['sequence'], }) + else: + processing_order.sequence = item['sequence'] else: - raise ValidationError("认证未通过") + raise ValidationError("工序认证未通过") class sfProductionProcessParameter(models.Model): @@ -860,13 +905,12 @@ class sfProductionProcessParameter(models.Model): _description = '表面工艺可选参数' url = '/api/production_process_parameter/list' - # 定时同步每日表面工艺 - def sync_production_process_parameter(self): + # 定时同步每日表面工艺可选参数 + def sync_production_process_parameter_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -874,35 +918,33 @@ class sfProductionProcessParameter(models.Model): if result['status'] == 1: for item in result['mrs_production_process_parameter_yesterday_list']: if item: - brand = self.env['sf.production.process.parameter'].search( - [("code", '=', item['code'])]) - if brand: - brand.name = item['name'], - brand.code = item['code'], - brand.active = item['active'], - # brand.price = item['price'], + production_process_parameter = self.search([("code", '=', item['code'])]) + process = self.env['sf.production.process'].search( + [('code', '=', item['process_id_code'])]) + if production_process_parameter: + production_process_parameter.name = item['name'] + production_process_parameter.active = item['active'] + production_process_parameter.process_id = process.id + production_process_parameter.materials_model_ids = self.env['sf.materials.model'].search( + [('materials_no', 'in', item['materials_model_ids_codes'])]) else: - self.env['sf.production.process.parameter'].create({ + self.create({ "name": item['name'], "code": item['code'], "active": item['active'], - # "price": item['price'], - "process_id": self.env['sf.production.process'].search( - [('process_encode', '=', item['process_id_code'])]).id, - 'materials_model_ids': self.env['sf.materials.model'].search( - [('materials_no', 'in', item['materials_model_ids_codes'])]) - + "process_id": process.id, + "materials_model_ids": self.env['sf.materials.model'].search( + [('materials_no', 'in', item['materials_model_ids_codes'])]), }) else: - raise ValidationError("认证未通过") # 定时同步表面工艺 + raise ValidationError("表面工艺可选参数认证未通过") # 定时同步表面工艺 - # 同步所有表面工艺 + # 同步所有表面工艺可选参数 def sync_all_production_process_parameter(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -912,23 +954,28 @@ class sfProductionProcessParameter(models.Model): for item in result['mrs_production_process_parameter_all_list']: if item: _logger.info('create可选参数:%s' % item) - brand = self.env['sf.production.process.parameter'].search( + production_process_parameter = self.search( [("code", '=', item['code'])]) - if not brand: + process = self.env['sf.production.process'].search( + [('code', '=', item['process_id_code'])], limit=1) + if not production_process_parameter: _logger.info('create可选参数:%s' % item) - self.env['sf.production.process.parameter'].create({ + self.create({ "name": item['name'], "code": item['code'], - # "price": item['price'], "active": item['active'], - "process_id": self.env['sf.production.process'].search( - [('process_encode', '=', item['process_id_code'])]).id, + "process_id": process.id, 'materials_model_ids': self.env['sf.materials.model'].search( - [('materials_no', 'in', item['materials_model_ids_codes'])]) - + [('materials_no', 'in', item['materials_model_ids_codes'])]), }) + else: + production_process_parameter.name = item['name'] + production_process_parameter.process_id = process.id + production_process_parameter.materials_model_ids = self.env['sf.materials.model'].search( + [('materials_no', 'in', item['materials_model_ids_codes'])]) + production_process_parameter.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("表面工艺可选参数认证未通过") class MachineToolCategory(models.Model): @@ -937,7 +984,7 @@ class MachineToolCategory(models.Model): url = '/api/machine_tool_category/list' # 定时同步机床类型 - def sync_machine_tool_category(self): + def sync_machine_tool_category_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] @@ -948,21 +995,22 @@ class MachineToolCategory(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_category_yesterday_list']: - brand = self.env['sf.machine_tool.category'].search( - [("code", '=', item['code'])]) - if brand: - brand.name = item['name'], - brand.code = item['code'], - brand.category = item['category'], - brand.remark = item['remark'] - + machine_tool_category = self.search([("code", '=', item['code'])]) + if machine_tool_category: + machine_tool_category.name = item['name'] + machine_tool_category.category = item['category'] + machine_tool_category.remark = item['remark'] + machine_tool_category.active = item['active'] else: - brand.name = item['name'], - brand.code = item['code'], - brand.category = item['category'], - brand.remark = item['remark'] + self.create({ + "name": item['name'], + "code": item['code'], + "category": item['category'], + "remark": item['remark'], + "active": item['active'], + }) else: - raise ValidationError("认证未通过") + raise ValidationError("机床类型认证未通过") # 同步所有机床类型 def sync_all_machine_tool_category(self): @@ -970,25 +1018,28 @@ class MachineToolCategory(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_category_all_list']: - brand = self.env['sf.machine_tool.category'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.machine_tool.category'].create({ + machine_tool_category = self.search([("code", '=', item['code'])]) + if not machine_tool_category: + self.create({ "name": item['name'], "code": item['code'], "category": item['category'], "remark": item['remark'], - + "active": item['active'], }) + else: + machine_tool_category.name = item['name'] + machine_tool_category.category = item['category'] + machine_tool_category.remark = item['remark'] + machine_tool_category.active = item['active'] else: - raise ValidationError("认证未通过") + raise ValidationError("机床类型认证未通过") # 同步刀具物料 @@ -999,12 +1050,11 @@ class sfSyncCutting_tool_Material(models.Model): url = '/api/mrs_cutting_tool_material/list' # 定时同步每日刀具物料 - def sync_cutting_tool_material(self): + def sync_cutting_tool_material_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -1014,22 +1064,22 @@ class sfSyncCutting_tool_Material(models.Model): if result.get('mrs_cutting_tool_material_yesterday_list'): for item in result['mrs_cutting_tool_material_yesterday_list']: if item: - brand = self.env['sf.cutting.tool.material'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.cutting.tool.material'].create({ + cutting_tool_material = self.search([("code", '=', item['code'])]) + if not cutting_tool_material: + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], + "active": item['active'], }) else: - brand.write({ + cutting_tool_material.write({ "name": item['name'], - "code": item['code'], "remark": item['remark'], + "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("刀具物料认证未通过") # 同步所有刀具物料 def sync_all_cutting_tool_material(self): @@ -1037,7 +1087,6 @@ class sfSyncCutting_tool_Material(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -1047,207 +1096,22 @@ class sfSyncCutting_tool_Material(models.Model): if result.get('mrs_cutting_tool_material_all_list'): for item in result['mrs_cutting_tool_material_all_list']: if item: - brand = self.env['sf.cutting.tool.material'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.cutting.tool.material'].create({ + cutting_tool_material = self.search([("code", '=', item['code'])]) + if not cutting_tool_material: + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], + "active": item['active'], }) else: - brand.write({ + cutting_tool_material.write({ "name": item['name'], - "code": item['code'], "remark": item['remark'], - }) - - -# 同步功能刀具列表 -class sfSyncFunctional_cutting_tool(models.Model): - _inherit = 'sf.functional.cutting.tool' - _description = '功能刀具同步' - url = '/api/mrs_functional_cutting_tool/list' - - # 定时同步每日功能刀具 - def sync_functional_cutting_tool(self): - sf_sync_config = self.env['res.config.settings'].get_values() - token = sf_sync_config['token'] - sf_secret_key = sf_sync_config['sf_secret_key'] - headers = Common.get_headers(self, token, sf_secret_key) - - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) - r = r.json() - result = json.loads(r['result']) - # print('result:%s' % result) - if result['status'] == 1: - if result.get('mrs_functional_cutting_tool_yesterday_list'): - for item in result['mrs_functional_cutting_tool_yesterday_list']: - if item: - brand = self.env['sf.functional.cutting.tool'].search( - [("code", '=', item['code'])]) - if item.get('image'): - image = base64.b64decode(item['image']) - else: - image = '' - if not brand: - self.env['sf.functional.cutting.tool'].create({ - "name": item['name'], - "code": item['code'], - # 功能刀具类型 - "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( - [('code', '=', item['mrs_cutting_tool_type_id'])]).id, - # # 刀具型号 - # "mrs_cutting_tool_model_id": self.env['sf.cutting.tool.model'].search( - # [('code', '=', item['mrs_cutting_tool_model_id'])]).id, - "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_integral_model_ids']), - "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_blade_model_ids']), - "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterbar_model_ids']), - "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterpad_model_ids']), - "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhandle_model_ids']), - "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhead_model_ids']), - "diameter": item['diameter'], - "tool_grade": item['tool_grade'], - "machining_accuracy": item['machining_accuracy'], - "tool_length": item['tool_length'], - "blade_number": item['blade_number'], - "integral_blade_length": item['integral_blade_length'], - "effective_blade_length": item['effective_blade_length'], - "max_life": item['max_life'], - "is_standard": item['is_standard'], - "applicable_range": item['applicable_range'], - "image": image, - - }) - else: - brand.write({ - "name": item['name'], - "code": item['code'], - # 功能刀具类型 - "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( - [('code', '=', item['mrs_cutting_tool_type_id'])]).id, - "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_integral_model_ids']), - "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_blade_model_ids']), - "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterbar_model_ids']), - "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterpad_model_ids']), - "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhandle_model_ids']), - "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhead_model_ids']), - "diameter": item['diameter'], - "tool_grade": item['tool_grade'], - "machining_accuracy": item['machining_accuracy'], - "tool_length": item['tool_length'], - "blade_number": item['blade_number'], - "integral_blade_length": item['integral_blade_length'], - "effective_blade_length": item['effective_blade_length'], - "max_life": item['max_life'], - "is_standard": item['is_standard'], - "applicable_range": item['applicable_range'], - "image": image, - + "active": item['active'], }) else: - raise ValidationError("认证未通过") - - # 同步所有功能刀具 - def sync_all_functional_cutting_tool(self): - sf_sync_config = self.env['res.config.settings'].get_values() - token = sf_sync_config['token'] - sf_secret_key = sf_sync_config['sf_secret_key'] - headers = Common.get_headers(self, token, sf_secret_key) - - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) - r = r.json() - result = json.loads(r['result']) - print('result:%s' % result) - if result['status'] == 1: - if result.get('mrs_functional_cutting_tool_all_list'): - for item in result['mrs_functional_cutting_tool_all_list']: - if item: - brand = self.env['sf.functional.cutting.tool'].search( - [("code", '=', item['code'])]) - if item.get('image'): - image = base64.b64decode(item['image']) - else: - image = '' - if not brand: - self.env['sf.functional.cutting.tool'].create({ - "name": item['name'], - "code": item['code'], - # 功能刀具类型 - "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( - [('code', '=', item['mrs_cutting_tool_type_id'])]).id, - "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_integral_model_ids']), - "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_blade_model_ids']), - "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterbar_model_ids']), - "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterpad_model_ids']), - "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhandle_model_ids']), - "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhead_model_ids']), - "diameter": item['diameter'], - "tool_grade": item['tool_grade'], - "machining_accuracy": item['machining_accuracy'], - "tool_length": item['tool_length'], - "blade_number": item['blade_number'], - "integral_blade_length": item['integral_blade_length'], - "effective_blade_length": item['effective_blade_length'], - "max_life": item['max_life'], - "is_standard": item['is_standard'], - "applicable_range": item['applicable_range'], - "image": image, - - }) - else: - brand.write({ - "name": item['name'], - "code": item['code'], - # 功能刀具类型 - "mrs_cutting_tool_type_id": self.env['sf.functional.cutting.tool.model'].search( - [('code', '=', item['mrs_cutting_tool_type_id'])]).id, - "mrs_cutting_tool_integral_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_integral_model_ids']), - "mrs_cutting_tool_blade_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_blade_model_ids']), - "mrs_cutting_tool_cutterbar_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterbar_model_ids']), - "mrs_cutting_tool_cutterpad_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterpad_model_ids']), - "mrs_cutting_tool_cutterhandle_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhandle_model_ids']), - "mrs_cutting_tool_cutterhead_model_ids": self._get_functional_tool_model_ids( - item['mrs_cutting_tool_cutterhead_model_ids']), - "diameter": item['diameter'], - "tool_grade": item['tool_grade'], - "machining_accuracy": item['machining_accuracy'], - "tool_length": item['tool_length'], - "blade_number": item['blade_number'], - "integral_blade_length": item['integral_blade_length'], - "effective_blade_length": item['effective_blade_length'], - "max_life": item['max_life'], - "is_standard": item['is_standard'], - "applicable_range": item['applicable_range'], - "image": image, - }) - else: - raise ValidationError("认证未通过") + raise ValidationError("刀具物料认证未通过") # 同步功能刀具类型列表 @@ -1257,12 +1121,11 @@ class SyncFunctionalCuttingToolModel(models.Model): url = '/api/mrs_functional_cutting_tool_model/list' # 定时同步每日功能刀具类型列表 - def sync_functional_cutting_tool_model(self): + def sync_functional_cutting_tool_model_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -1272,22 +1135,22 @@ class SyncFunctionalCuttingToolModel(models.Model): if result.get('mrs_functional_cutting_tool_model_yesterday_list'): for item in result['mrs_functional_cutting_tool_model_yesterday_list']: if item: - brand = self.env['sf.functional.cutting.tool.model'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.functional.cutting.tool.model'].create({ + functional_cutting_tool_model = self.search([("code", '=', item['code'])]) + if not functional_cutting_tool_model: + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], + "active": item['active'], }) else: - brand.write({ + functional_cutting_tool_model.write({ "name": item['name'], - "code": item['code'], "remark": item['remark'], + "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("功能刀具类型认证未通过") # 同步所有功能刀具类型列表 def sync_all_functional_cutting_tool_model(self): @@ -1305,23 +1168,22 @@ class SyncFunctionalCuttingToolModel(models.Model): if result.get('mrs_functional_cutting_tool_model_all_list'): for item in result['mrs_functional_cutting_tool_model_all_list']: if item: - brand = self.env['sf.functional.cutting.tool.model'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.functional.cutting.tool.model'].create({ + functional_cutting_tool_model = self.search([("code", '=', item['code'])]) + if not functional_cutting_tool_model: + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], + "active": item['active'], }) else: - brand.write({ + functional_cutting_tool_model.write({ "name": item['name'], - "code": item['code'], "remark": item['remark'], + "active": item['active'], }) - print('同步功能刀具类型列表成功') else: - raise ValidationError("认证未通过") + raise ValidationError("功能刀具类型认证未通过") class SyncFixtureMaterial(models.Model): @@ -1331,7 +1193,7 @@ class SyncFixtureMaterial(models.Model): url = '/api/fixture_material/list' # 定时同步夹具物料列表 - def sync_fixture_material(self): + def sync_fixture_material_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] @@ -1345,10 +1207,9 @@ class SyncFixtureMaterial(models.Model): if result.get('fixture_material_yesterday_list'): for item in result['fixture_material_yesterday_list']: if item: - fixture_material = self.env['sf.fixture.material'].search( - [("code", '=', item['code'])]) + fixture_material = self.search([("code", '=', item['code'])]) if not fixture_material: - self.env['sf.fixture.material'].create({ + self.create({ "name": item['name'], "code": item['code'], "category": item['category'], @@ -1363,7 +1224,7 @@ class SyncFixtureMaterial(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具物料认证未通过") # 定时同步所有夹具物料列表 def sync_all_fixture_material(self): @@ -1381,10 +1242,9 @@ class SyncFixtureMaterial(models.Model): if result.get('fixture_material_all_list'): for item in result['fixture_material_all_list']: if item: - fixture_material = self.env['sf.fixture.material'].search( - [("code", '=', item['code'])]) + fixture_material = self.search([("code", '=', item['code'])]) if not fixture_material: - self.env['sf.fixture.material'].create({ + self.create({ "name": item['name'], "code": item['code'], "category": item['category'], @@ -1399,7 +1259,7 @@ class SyncFixtureMaterial(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具物料认证未通过") class SyncMulti_Mounting_Type(models.Model): @@ -1409,7 +1269,7 @@ class SyncMulti_Mounting_Type(models.Model): url = '/api/multi_mounting_type/list' # 定时同步联装类型列表 - def sync_multi_mounting_type(self): + def sync_multi_mounting_type_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] @@ -1418,15 +1278,13 @@ class SyncMulti_Mounting_Type(models.Model): r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) - # print('result:%s' % result) if result['status'] == 1: if result.get('multi_mounting_type_yesterday_list'): for item in result['multi_mounting_type_yesterday_list']: if item: - multi_mounting_type = self.env['sf.multi_mounting.type'].search( - [("code", '=', item['code'])]) + multi_mounting_type = self.search([("code", '=', item['code'])]) if not multi_mounting_type: - self.env['sf.multi_mounting.type'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1439,7 +1297,7 @@ class SyncMulti_Mounting_Type(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("联装类型认证未通过") # 定时同步所有联装类型列表 def sync_all_multi_mounting_type(self): @@ -1447,7 +1305,6 @@ class SyncMulti_Mounting_Type(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -1457,10 +1314,9 @@ class SyncMulti_Mounting_Type(models.Model): if result.get('multi_mounting_type_all_list'): for item in result['multi_mounting_type_all_list']: if item: - multi_mounting_type = self.env['sf.multi_mounting.type'].search( - [("code", '=', item['code'])]) + multi_mounting_type = self.search([("code", '=', item['code'])]) if not multi_mounting_type: - self.env['sf.multi_mounting.type'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1473,7 +1329,7 @@ class SyncMulti_Mounting_Type(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("联装类型认证未通过") class SyncFixtureModel(models.Model): @@ -1483,7 +1339,7 @@ class SyncFixtureModel(models.Model): url = '/api/fixture_model/list' # 定时同步夹具型号列表 - def sync_fixture_model(self): + def sync_fixture_model_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] @@ -1492,15 +1348,13 @@ class SyncFixtureModel(models.Model): r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) - # print('result:%s' % result) if result['status'] == 1: if result.get('fixture_model_yesterday_list'): for item in result['fixture_model_yesterday_list']: if item: - fixture_model = self.env['sf.fixture.model'].search( - [("code", '=', item['code'])]) + fixture_model = self.search([("code", '=', item['code'])]) if not fixture_model: - self.env['sf.fixture.model'].create({ + self.create({ "name": item['name'], "code": item['code'], "fixture_material_id": self.env['sf.fixture.material'].search( @@ -1561,7 +1415,7 @@ class SyncFixtureModel(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具型号认证未通过") # 定时同步所有夹具型号列表 def sync_all_fixture_model(self): @@ -1569,7 +1423,6 @@ class SyncFixtureModel(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -1579,10 +1432,9 @@ class SyncFixtureModel(models.Model): if result.get('fixture_model_all_list'): for item in result['fixture_model_all_list']: if item: - fixture_model = self.env['sf.fixture.model'].search( - [("code", '=', item['code'])]) + fixture_model = self.search([("code", '=', item['code'])]) if not fixture_model: - self.env['sf.fixture.model'].create({ + self.create({ "name": item['name'], "code": item['code'], "fixture_material_id": self.env['sf.fixture.material'].search( @@ -1643,7 +1495,7 @@ class SyncFixtureModel(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具型号认证未通过") class SyncFunctionalFixtureType(models.Model): @@ -1653,7 +1505,7 @@ class SyncFunctionalFixtureType(models.Model): url = '/api/functional_fixture_type/list' # 定时同步功能夹具类型列表 - def sync_functional_fixture_type(self): + def sync_functional_fixture_type_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] @@ -1667,10 +1519,9 @@ class SyncFunctionalFixtureType(models.Model): if result.get('functional_fixture_type_yesterday_list'): for item in result['functional_fixture_type_yesterday_list']: if item: - functional_fixture_type = self.env['sf.functional.fixture.type'].search( - [("code", '=', item['code'])]) + functional_fixture_type = self.search([("code", '=', item['code'])]) if not functional_fixture_type: - self.env['sf.functional.fixture.type'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1683,7 +1534,7 @@ class SyncFunctionalFixtureType(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("功能夹具类型认证未通过") # 定时同步所有功能夹具类型列表 def sync_all_functional_fixture_type(self): @@ -1691,20 +1542,17 @@ class SyncFunctionalFixtureType(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) - # print('result:%s' % result) if result['status'] == 1: if result.get('functional_fixture_type_all_list'): for item in result['functional_fixture_type_all_list']: if item: - functional_fixture_type = self.env['sf.functional.fixture.type'].search( - [("code", '=', item['code'])]) + functional_fixture_type = self.search([("code", '=', item['code'])]) if not functional_fixture_type: - self.env['sf.functional.fixture.type'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1717,112 +1565,7 @@ class SyncFunctionalFixtureType(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") - - -class SyncFunctionalFixture(models.Model): - _inherit = 'sf.functional.fixture' - _description = '同步功能夹具列表' - - url = '/api/functional_fixture/list' - - # 定时同步每日功能夹具列表 - def sync_functional_fixture(self): - sf_sync_config = self.env['res.config.settings'].get_values() - token = sf_sync_config['token'] - sf_secret_key = sf_sync_config['sf_secret_key'] - headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) - r = r.json() - result = json.loads(r['result']) - # print('result:%s' % result) - if result['status'] == 1: - if result.get('functional_fixture_yesterday_list'): - for item in result['functional_fixture_yesterday_list']: - if item: - functional_fixture = self.env['sf.functional.fixture'].search( - [("code", '=', item['code'])]) - if not functional_fixture: - self.env['sf.functional.fixture'].create({ - "name": item['name'], - "code": item['code'], - "type_id": self.env['sf.functional.fixture.type'].search( - [("code", '=', item['functional_fixture_type_code'])]).id, - "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), - "transfer_tray_model_ids": self._get_fixture_model_ids( - item['transfer_tray_model_codes']), - "pneumatic_tray_model_ids": self._get_fixture_model_ids( - item['pneumatic_tray_model_codes']), - "magnetic_tray_model_ids": self._get_fixture_model_ids( - item['magnetic_tray_model_codes']), - "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), - }) - else: - functional_fixture.write({ - "name": item['name'], - "type_id": self.env['sf.functional.fixture.type'].search( - [("code", '=', item['functional_fixture_type_code'])]).id, - "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), - "transfer_tray_model_ids": self._get_fixture_model_ids( - item['transfer_tray_model_codes']), - "pneumatic_tray_model_ids": self._get_fixture_model_ids( - item['pneumatic_tray_model_codes']), - "magnetic_tray_model_ids": self._get_fixture_model_ids( - item['magnetic_tray_model_codes']), - "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), - }) - else: - raise ValidationError("认证未通过") - - # 定时同步所有功能夹具列表 - def sync_all_functional_fixture(self): - sf_sync_config = self.env['res.config.settings'].get_values() - token = sf_sync_config['token'] - sf_secret_key = sf_sync_config['sf_secret_key'] - headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url - r = requests.post(strUrl, json={}, data=None, headers=headers) - r = r.json() - result = json.loads(r['result']) - # print('result:%s' % result) - if result['status'] == 1: - if result.get('functional_fixture_all_list'): - for item in result['functional_fixture_all_list']: - if item: - functional_fixture = self.env['sf.functional.fixture'].search( - [("code", '=', item['code'])]) - if not functional_fixture: - self.env['sf.functional.fixture'].create({ - "name": item['name'], - "code": item['code'], - "type_id": self.env['sf.functional.fixture.type'].search( - [("code", '=', item['functional_fixture_type_code'])]).id, - "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), - "transfer_tray_model_ids": self._get_fixture_model_ids( - item['transfer_tray_model_codes']), - "pneumatic_tray_model_ids": self._get_fixture_model_ids( - item['pneumatic_tray_model_codes']), - "magnetic_tray_model_ids": self._get_fixture_model_ids( - item['magnetic_tray_model_codes']), - "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), - }) - else: - functional_fixture.write({ - "name": item['name'], - "type_id": self.env['sf.functional.fixture.type'].search( - [("code", '=', item['functional_fixture_type_code'])]).id, - "zero_chuck_model_ids": self._get_fixture_model_ids(item['zero_chuck_model_codes']), - "transfer_tray_model_ids": self._get_fixture_model_ids( - item['transfer_tray_model_codes']), - "pneumatic_tray_model_ids": self._get_fixture_model_ids( - item['pneumatic_tray_model_codes']), - "magnetic_tray_model_ids": self._get_fixture_model_ids( - item['magnetic_tray_model_codes']), - "vice_tray_model_ids": self._get_fixture_model_ids(item['vice_tray_model_codes']), - }) - else: - raise ValidationError("认证未通过") + raise ValidationError("功能夹具类型认证未通过") # 同步刀具类型 @@ -1833,12 +1576,11 @@ class SfToolType(models.Model): url = '/api/mrs_cutting_tool_type/list' # 定时同步每日刀具类型 - def sync_tool_type(self): + def sync_tool_type_yesterday(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -1847,28 +1589,26 @@ class SfToolType(models.Model): _logger.info('result:%s' % result) for item in result['mrs_cutting_tool_type_yesterday_list']: if item: - cutting_tool_type = self.env['sf.cutting.tool.type'].search( - [("code", '=', item['code'])]) + cutting_tool_type = self.search([("code", '=', item['code'])]) + cutting_tool_material = self.env['sf.cutting.tool.material'].search( + [("code", '=', item['cutting_tool_material_code'])]) if not cutting_tool_type: - self.env['sf.cutting.tool.type'].create({ + self.create({ "name": item['name'], "code": item['code'], - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, + "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) else: cutting_tool_type.write({ "name": item['name'], - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, + "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) - else: - raise ValidationError("认证未通过") + raise ValidationError("刀具类型认证未通过") # 同步所有刀具类型列表 def sync_all_tool_type(self): @@ -1876,7 +1616,6 @@ class SfToolType(models.Model): token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] headers = Common.get_headers(self, token, sf_secret_key) - strUrl = sf_sync_config['sf_url'] + self.url r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() @@ -1885,39 +1624,104 @@ class SfToolType(models.Model): _logger.info('result:%s' % result) for item in result['mrs_cutting_tool_type_all_list']: if item: - cutting_tool_type = self.env['sf.cutting.tool.type'].search( - [("code", '=', item['code'])]) + cutting_tool_type = self.search([("code", '=', item['code'])]) + cutting_tool_material = self.env['sf.cutting.tool.material'].search( + [("code", '=', item['cutting_tool_material_code'])]) if not cutting_tool_type: - self.env['sf.cutting.tool.type'].create({ + self.create({ "name": item['name'], "code": item['code'], - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, + "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) else: cutting_tool_type.write({ "name": item['name'], - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, + "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) + else: + raise ValidationError("刀具类型认证未通过") + +# 同步能力特征库 +class SfMaintenanceEquipmentImage(models.Model): + _inherit = 'maintenance.equipment.image' + _description = '能力特征库' + + url = '/api/maintenance_equipment_image/list' + + # 定时同步每日能力特征库 + def sync_maintenance_equipment_image_yesterday(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + sf_secret_key = sf_sync_config['sf_secret_key'] + headers = Common.get_headers(self, token, sf_secret_key) + strUrl = sf_sync_config['sf_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + _logger.info('result:%s' % result) + for item in result['ability_feature_library_yesterday_list']: + if item: + ability_feature_library = self.search([("name", '=', item['name'])]) + if not ability_feature_library: + self.create({ + "name": item['name'], + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) + else: + ability_feature_library.write({ + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) + else: + raise ValidationError("能力特征库认证未通过") + + # 同步所有能力特征库 + def sync_all_maintenance_equipment_image(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + sf_secret_key = sf_sync_config['sf_secret_key'] + headers = Common.get_headers(self, token, sf_secret_key) + strUrl = sf_sync_config['sf_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + _logger.info('result:%s' % result) + for item in result['ability_feature_library_all_list']: + if item: + ability_feature_library = self.search([("name", '=', item['name'])]) + if not ability_feature_library: + self.create({ + "name": item['name'], + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) + else: + ability_feature_library.write({ + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) else: raise ValidationError("认证未通过") +class MaterialApply(models.Model): + _inherit = 'material.apply' + _description = '材料应用' + url = '/api/material_apply/list' -# 同步刀具型号 -class SfToolModel(models.Model): - _inherit = 'sf.cutting.tool.model' - _description = '同步刀具型号' - - url = '/api/mrs_cutting_tool_model/list' - - # 定时同步每日刀具型号 - def sync_tool_model(self): + # 定时同步材料应用 + def sync_material_apply(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] @@ -1928,126 +1732,23 @@ class SfToolModel(models.Model): r = r.json() result = json.loads(r['result']) if result['status'] == 1: - _logger.info('result:%s' % result) - for item in result['mrs_cutting_tool_model_yesterday_list']: - cutting_tool_model = self.search( - [("code", '=', item['code'])]) - if not cutting_tool_model: - self.env['sf.cutting.tool.model'].create({ - "name": item['name'], - "code": item['code'], - "brand_id": self.env['sf.machine.brand'].search( - [("code", '=', item['brand_code'])]).id, - "material_model_id": self.env['sf.materials.model'].search( - [("materials_no", '=', item['material_model_code'])]).id, - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, - "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( - [("code", '=', item['cutting_tool_type_code'])]).id, - "tool_length": item['tool_length'], - "tool_width": item['tool_width'], - "tool_height": item['tool_height'], - "tool_thickness": item['tool_thickness'], - "tool_weight": item['tool_weight'], - "coating_material": item['coating_material'], - "total_length": item['total_length'], - "shank_length": item['shank_length'], - "blade_length": item['blade_length'], - "front_angle": item['front_angle'], - "rear_angle": item['rear_angle'], - "main_included_angle": item['main_included_angle'], - "nut": item['nut'], - "top_angle": item['top_angle'], - "jump_accuracy": item['jump_accuracy'], - "working_hardness": item['working_hardness'], - "blade_diameter": item['blade_diameter'], - "wrench": item['wrench'], - "screw": item['screw'], - "accuracy_level": item['accuracy_level'], - "diameter_max": item['diameter_max'], - "clamping_diameter": item['clamping_diameter'], - "flange_length": item['flange_length'], - 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['chuck_codes']), - 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_bar_codes']), - 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_pad_codes']), - 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['blade_codes']), - 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['handle_codes']), - "flange_diameter": item['flange_diameter'], - "outer_diameter": item['outer_diameter'], - "inner_diameter": item['inner_diameter'], - "active": item['active'], - }) + for item in result['material_apply_yesterday_list']: + brand = self.env['material.apply'].search( + [("name", '=', item['name'])]) + if brand: + brand.name = item['name'], + brand.active = item['active'] else: - cutting_tool_model.write({ + self.env['material.apply'].create({ "name": item['name'], - "code": item['code'], - "brand_id": self.env['sf.machine.brand'].search( - [("code", '=', item['brand_code'])]).id, - "material_model_id": self.env['sf.materials.model'].search( - [("materials_no", '=', item['material_model_code'])]).id, - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, - "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( - [("code", '=', item['cutting_tool_type_code'])]).id, - "tool_length": item['tool_length'], - "tool_width": item['tool_width'], - "tool_height": item['tool_height'], - "tool_thickness": item['tool_thickness'], - "tool_weight": item['tool_weight'], - "coating_material": item['coating_material'], - "total_length": item['total_length'], - "shank_length": item['shank_length'], - "blade_length": item['blade_length'], - "front_angle": item['front_angle'], - "rear_angle": item['rear_angle'], - "main_included_angle": item['main_included_angle'], - "nut": item['nut'], - "top_angle": item['top_angle'], - "jump_accuracy": item['jump_accuracy'], - "working_hardness": item['working_hardness'], - "blade_diameter": item['blade_diameter'], - "wrench": item['wrench'], - "screw": item['screw'], - "accuracy_level": item['accuracy_level'], - "diameter_max": item['diameter_max'], - "clamping_diameter": item['clamping_diameter'], - "flange_length": item['flange_length'], - 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['chuck_codes']), - 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_bar_codes']), - 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_pad_codes']), - 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['blade_codes']), - 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['handle_codes']), - "flange_diameter": item['flange_diameter'], - "outer_diameter": item['outer_diameter'], - "inner_diameter": item['inner_diameter'], "active": item['active'], + }) - print('同步所有刀柄类型列表成功') else: raise ValidationError("认证未通过") - # 同步所有刀具型号列表 - def sync_all_tool_model(self): + # 同步所有材料应用 + def sync_all_material_apply(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] sf_secret_key = sf_sync_config['sf_secret_key'] @@ -2057,122 +1758,69 @@ class SfToolModel(models.Model): r = requests.post(strUrl, json={}, data=None, headers=headers) r = r.json() result = json.loads(r['result']) - print('result', result) if result['status'] == 1: - _logger.info('result:%s' % result) - for item in result['mrs_cutting_tool_model_all_list']: - cutting_tool_model = self.search( - [("code", '=', item['code'])]) - if not cutting_tool_model: - self.env['sf.cutting.tool.model'].create({ + for item in result['material_apply_all_list']: + brand = self.env['material.apply'].search( + [("name", '=', item['name'])]) + if not brand: + self.env['material.apply'].create({ "name": item['name'], - "code": item['code'], - "brand_id": self.env['sf.machine.brand'].search( - [("code", '=', item['brand_code'])]).id, - "material_model_id": self.env['sf.materials.model'].search( - [("materials_no", '=', item['material_model_code'])]).id, - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, - "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( - [("code", '=', item['cutting_tool_type_code'])]).id, - "tool_length": item['tool_length'], - "tool_width": item['tool_width'], - "tool_height": item['tool_height'], - "tool_thickness": item['tool_thickness'], - "tool_weight": item['tool_weight'], - "coating_material": item['coating_material'], - "total_length": item['total_length'], - "shank_length": item['shank_length'], - "blade_length": item['blade_length'], - "front_angle": item['front_angle'], - "rear_angle": item['rear_angle'], - "main_included_angle": item['main_included_angle'], - "nut": item['nut'], - "top_angle": item['top_angle'], - "jump_accuracy": item['jump_accuracy'], - "working_hardness": item['working_hardness'], - "blade_diameter": item['blade_diameter'], - "wrench": item['wrench'], - "screw": item['screw'], - "accuracy_level": item['accuracy_level'], - "diameter_max": item['diameter_max'], - "clamping_diameter": item['clamping_diameter'], - "flange_length": item['flange_length'], - 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['chuck_codes']), - 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_bar_codes']), - 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_pad_codes']), - 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['blade_codes']), - 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['handle_codes']), - "flange_diameter": item['flange_diameter'], - "outer_diameter": item['outer_diameter'], - "inner_diameter": item['inner_diameter'], "active": item['active'], }) - else: - cutting_tool_model.write({ - "name": item['name'], - "code": item['code'], - "brand_id": self.env['sf.machine.brand'].search( - [("code", '=', item['brand_code'])]).id, - "material_model_id": self.env['sf.materials.model'].search( - [("materials_no", '=', item['material_model_code'])]).id, - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, - "cutting_tool_type_id": self.env['sf.cutting.tool.type'].search( - [("code", '=', item['cutting_tool_type_code'])]).id, - "tool_length": item['tool_length'], - "tool_width": item['tool_width'], - "tool_height": item['tool_height'], - "tool_thickness": item['tool_thickness'], - "tool_weight": item['tool_weight'], - "coating_material": item['coating_material'], - "total_length": item['total_length'], - "shank_length": item['shank_length'], - "blade_length": item['blade_length'], - "front_angle": item['front_angle'], - "rear_angle": item['rear_angle'], - "main_included_angle": item['main_included_angle'], - "nut": item['nut'], - "top_angle": item['top_angle'], - "jump_accuracy": item['jump_accuracy'], - "working_hardness": item['working_hardness'], - "blade_diameter": item['blade_diameter'], - "wrench": item['wrench'], - "screw": item['screw'], - "accuracy_level": item['accuracy_level'], - "diameter_max": item['diameter_max'], - "clamping_diameter": item['clamping_diameter'], - "flange_length": item['flange_length'], - 'chuck_ids': [(6, 0, [])] if not item.get('chuck_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['chuck_codes']), - 'cutter_bar_ids': [(6, 0, [])] if not item.get('cutter_bar_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_bar_codes']), - 'cutter_pad_ids': [(6, 0, [])] if not item.get('cutter_pad_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['cutter_pad_codes']), - 'blade_ids': [(6, 0, [])] if not item.get('blade_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['blade_codes']), - 'handle_ids': [(6, 0, [])] if not item.get('handle_codes') else - self.env['mrs.cutting.tool.dynamic.model'].sudo()._get_cutting_tool_model_ids( - item['handle_codes']), - "flange_diameter": item['flange_diameter'], - "outer_diameter": item['outer_diameter'], - "inner_diameter": item['inner_diameter'], - "active": item['active'], - }) - print('同步所有刀具型号列表成功') else: raise ValidationError("认证未通过") + +class ModelInternationalStandards(models.Model): + _inherit = 'sf.international.standards' + _description = '制造标准' + url = '/api/mrs_international_standards/list' + + # 定时同步制造标准 + def sync_mrs_international_standards(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + sf_secret_key = sf_sync_config['sf_secret_key'] + headers = Common.get_headers(self, token, sf_secret_key) + + strUrl = sf_sync_config['sf_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + for item in result['mrs_international_standards_yesterday_list']: + brand = self.env['sf.international.standards'].search( + [("name", '=', item['name'])]) + if brand: + brand.name = item['name'], + brand.active = item['active'] + else: + self.env['sf.international.standards'].create({ + "name": item['name'], + "active": item['active'], + + }) + else: + raise ValidationError("认证未通过") + + # 同步所有制造标准 + def sync_all_mrs_international_standards(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + sf_secret_key = sf_sync_config['sf_secret_key'] + headers = Common.get_headers(self, token, sf_secret_key) + + strUrl = sf_sync_config['sf_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + for item in result['mrs_international_standards_all_list']: + brand = self.env['sf.international.standards'].search( + [("name", '=', item['name'])]) + if not brand: + self.env['sf.international.standards'].create({ + "name": item['name'], + "active": item['active'], + }) + else: + raise ValidationError("能力特征库认证未通过") diff --git a/sf_sale/__manifest__.py b/sf_sale/__manifest__.py index bfb221ca..abd8d5a6 100644 --- a/sf_sale/__manifest__.py +++ b/sf_sale/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['sale', 'web_widget_model_viewer'], + 'depends': ['sale', 'sale_management', 'web_widget_model_viewer'], 'data': [ 'security/group_security.xml', 'security/ir.model.access.csv', diff --git a/sf_sale/models/quick_easy_order.py b/sf_sale/models/quick_easy_order.py index 6599cd09..0a20a676 100644 --- a/sf_sale/models/quick_easy_order.py +++ b/sf_sale/models/quick_easy_order.py @@ -82,7 +82,7 @@ class QuickEasyOrder(models.Model): # logging.info('create-model_file:%s' % len(vals['model_file'])) obj = super(QuickEasyOrder, self).create(vals) - # self.model_coloring(obj) + self.model_coloring(obj) self.distribute_to_factory(obj) obj.state = '待接单' return obj @@ -90,14 +90,14 @@ class QuickEasyOrder(models.Model): # 将attach的datas内容转为glb文件 def transition_glb_file(self, report_path, model_code): shapes = read_step_file(report_path) - output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl') - # output_file = os.path.join('/tmp', str(model_code) + '.stl') + # output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl') + output_file = os.path.join('/tmp', str(model_code) + '.stl') write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) # 转化为glb - output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb') - # output_glb_file = os.path.join('/tmp', str(model_code) + '.glb') + # output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb') + output_glb_file = os.path.join('/tmp', str(model_code) + '.glb') util_path = get_resource_path('sf_dlm', 'static/util') - cmd = 'python %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) + cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) os.system(cmd) # 转base64 with open(output_glb_file, 'rb') as fileObj: @@ -122,17 +122,17 @@ class QuickEasyOrder(models.Model): model_code = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest() logging.info("模型编码: %s" % model_code) item.model_file = self.transition_glb_file(report_path, model_code) - # ret = self.feature_recognition(report_path, model_code) - # logging.info("自动报价返回值: %s" % ret) - # boxshape = ret['boxshape'].tolist() - # logging.info("自动报价boxshape: %s" % boxshape) - # logging.info('自动报价feature_infos:%s' % ret['feature_infos']) - # item.model_length = boxshape[0] # 长 单位mm - # item.model_width = boxshape[1] # 宽 - # item.model_height = boxshape[2] # 高 - # item.model_volume = boxshape[0] * boxshape[1] * boxshape[2] - # item.model_feature = json.dumps(ret['feature_infos'], ensure_ascii=False) - # self._get_price(item) + ret = self.feature_recognition(report_path, model_code) + logging.info("自动报价返回值: %s" % ret) + boxshape = ret['boxshape'].tolist() + logging.info("自动报价boxshape: %s" % boxshape) + logging.info('自动报价feature_infos:%s' % ret['feature_infos']) + item.model_length = boxshape[0] # 长 单位mm + item.model_width = boxshape[1] # 宽 + item.model_height = boxshape[2] # 高 + item.model_volume = boxshape[0] * boxshape[1] * boxshape[2] + item.model_feature = json.dumps(ret['feature_infos'], ensure_ascii=False) + self._get_price(item) else: item.model_file = False item.model_feature = False diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 9ed661ee..664876b1 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -756,7 +756,7 @@ class FunctionalToolAssembly(models.Model): domain=[('cutting_tool_material_id', '=', '整体式刀具')]) integral_code = fields.Char('整体式刀具序列号', readonly=True) integral_name = fields.Char('整体式刀具名称', readonly=True) - sf_tool_brand_id_1 = fields.Many2one('sf.machine.brand', '整体式刀具品牌', readonly=True) + sf_tool_brand_id_1 = fields.Many2one('sf.machine.brand', '整体式刀具品牌', readonly=True, domain="[('tag_ids.name', 'ilike', '刀具')]") # 刀片型号 cutting_tool_blade_model_id = fields.Many2one('product.product', string='刀片型号', readonly=True, domain=[('cutting_tool_material_id', '=', '刀片')]) diff --git a/sf_tool_management/models/tool_material_search.py b/sf_tool_management/models/tool_material_search.py index b422d1bf..91782faf 100644 --- a/sf_tool_management/models/tool_material_search.py +++ b/sf_tool_management/models/tool_material_search.py @@ -19,7 +19,7 @@ class SfToolMaterialSearch(models.Model): mrs_cutting_tool_material_name = fields.Char(related='mrs_cutting_tool_material_id.name', string='刀具物料名称', store=True) cutting_tool_type = fields.Char(related='mrs_cutting_tool_material_id.name', string='刀具物料类型', store=True) - mrs_machine_brand_id = fields.Many2one('sf.machine.brand', '品牌', required=True) + mrs_machine_brand_id = fields.Many2one('sf.machine.brand', '品牌', required=True, domain="[('tag_ids.name', 'ilike', '刀具')]") # 关联刀具型号 # mrs_cutting_tool_model_id = fields.Many2one('sf.cutting.tool.model', '刀具型号')