diff --git a/jikimo_frontend/static/src/scss/custom_style.scss b/jikimo_frontend/static/src/scss/custom_style.scss index 6a398126..f90cca94 100644 --- a/jikimo_frontend/static/src/scss/custom_style.scss +++ b/jikimo_frontend/static/src/scss/custom_style.scss @@ -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 { diff --git a/sf_base/__manifest__.py b/sf_base/__manifest__.py index bcb25c81..60077453 100644 --- a/sf_base/__manifest__.py +++ b/sf_base/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['account', 'base', 'mrp_workorder','sale'], + 'depends': ['account', 'base', 'mrp_workorder', 'sale'], 'data': [ 'security/group_security.xml', 'security/ir.model.access.csv', 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 @@ - + maintenance.equipment.image.tree maintenance.equipment.image - - - - - + + + + + - - maintenance.equipment.image.form + + + maintenance.equipment.image.search maintenance.equipment.image -
- - - - - - - - - -
+ + + +
能力特征库 maintenance.equipment.image - tree,form + tree [] + - - 同步资源库材料 - + + + 制造-配置:每日定时同步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 c2a7361c..02836d13 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() @@ -30,47 +34,38 @@ class ResConfigSettings(models.TransientModel): self.env['sf.production.process'].sync_all_production_process() _logger.info("同步资源库表面工艺") # self.env['sf.processing.technology'].sync_all_processing_technology() - _logger.info("同步资源库加工工艺") + # _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("同步所有刀具型号完成") - _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.type'].sync_all_functional_fixture_type() + self.env['sf.machine_tool.type'].sync_all_machine_tool_type() - _logger.info("同步资源库机床型号") - self.env['sf.international.standards'].sync_all_mrs_international_standards() - _logger.info("同步资源库国际标准") - self.env['material.apply'].sync_all_material_apply() - _logger.info("同步资源库材料应用") + _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 f0ada89b..b322808b 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'], @@ -177,8 +221,21 @@ class sfMaterialModel(models.Model): # "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): @@ -187,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() @@ -200,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): @@ -221,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() @@ -229,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): @@ -247,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() @@ -270,8 +325,16 @@ class sfProductionProcess(models.Model): brand.remark = item['remark'], brand.active = item['active'], brand.remark = item['remark'] + production_process = self.search([("process_encode", '=', 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, @@ -280,7 +343,7 @@ class sfProductionProcess(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") # 定时同步表面工艺 + raise ValidationError("表面工艺认证未通过") # 同步所有表面工艺 def sync_all_production_process(self): @@ -288,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() @@ -296,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['code'])]) - if not brand: - self.env['sf.production.process'].create({ + production_process = self.search([("process_encode", '=', 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['code'], + "category_id": category.id, + "process_encode": item['process_encode'], "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): @@ -319,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() @@ -332,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([("process_encode", '=', item['process_encode'])]) + 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'], "remark": item['remark'], "active": item['active'], - # "tag_ids": item['tag_ids'] - }) else: - raise ValidationError("认证未通过") + raise ValidationError("加工工艺认证未通过") # 同步所有加工工艺 def sync_all_processing_technology(self): @@ -359,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() @@ -367,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([("process_encode", '=', item['process_encode'])]) + if not processing_technology: + self.create({ "name": item['name'], "process_encode": item['process_encode'], "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): @@ -389,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): @@ -430,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() @@ -463,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): @@ -526,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.b64encode(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), "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): @@ -567,24 +606,19 @@ 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'], @@ -592,8 +626,14 @@ class MachineBrand(models.Model): "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.b64encode(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): @@ -602,50 +642,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'], @@ -653,15 +668,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'], @@ -682,12 +698,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): @@ -695,7 +752,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() @@ -706,14 +762,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'], @@ -726,10 +783,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'], @@ -751,15 +807,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'], @@ -772,11 +824,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'], @@ -797,12 +848,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): @@ -811,31 +860,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): @@ -843,22 +887,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): @@ -867,12 +910,11 @@ class sfProductionProcessParameter(models.Model): 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() @@ -880,27 +922,26 @@ 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( + [('process_encode', '=', 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): @@ -908,7 +949,6 @@ class sfProductionProcessParameter(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() @@ -918,23 +958,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( + [('process_encode', '=', item['process_id_code'])]) + 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): @@ -943,7 +988,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'] @@ -954,21 +999,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): @@ -976,25 +1022,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("机床类型认证未通过") # 同步刀具物料 @@ -1005,12 +1054,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() @@ -1020,22 +1068,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): @@ -1043,7 +1091,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() @@ -1053,207 +1100,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("刀具物料认证未通过") # 同步功能刀具类型列表 @@ -1263,12 +1125,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() @@ -1278,22 +1139,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): @@ -1311,23 +1172,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): @@ -1337,7 +1197,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'] @@ -1351,10 +1211,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'], @@ -1369,7 +1228,7 @@ class SyncFixtureMaterial(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具物料认证未通过") # 定时同步所有夹具物料列表 def sync_all_fixture_material(self): @@ -1387,10 +1246,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'], @@ -1405,7 +1263,7 @@ class SyncFixtureMaterial(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具物料认证未通过") class SyncMulti_Mounting_Type(models.Model): @@ -1415,7 +1273,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'] @@ -1424,15 +1282,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'], @@ -1445,7 +1301,7 @@ class SyncMulti_Mounting_Type(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("联装类型认证未通过") # 定时同步所有联装类型列表 def sync_all_multi_mounting_type(self): @@ -1453,7 +1309,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() @@ -1463,10 +1318,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'], @@ -1479,7 +1333,7 @@ class SyncMulti_Mounting_Type(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("联装类型认证未通过") class SyncFixtureModel(models.Model): @@ -1489,7 +1343,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'] @@ -1498,15 +1352,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( @@ -1567,7 +1419,7 @@ class SyncFixtureModel(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具型号认证未通过") # 定时同步所有夹具型号列表 def sync_all_fixture_model(self): @@ -1575,7 +1427,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() @@ -1585,10 +1436,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( @@ -1649,7 +1499,7 @@ class SyncFixtureModel(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("夹具型号认证未通过") class SyncFunctionalFixtureType(models.Model): @@ -1659,7 +1509,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'] @@ -1673,10 +1523,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'], @@ -1689,7 +1538,7 @@ class SyncFunctionalFixtureType(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + raise ValidationError("功能夹具类型认证未通过") # 定时同步所有功能夹具类型列表 def sync_all_functional_fixture_type(self): @@ -1697,20 +1546,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'], @@ -1723,112 +1569,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("功能夹具类型认证未通过") # 同步刀具类型 @@ -1839,12 +1580,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() @@ -1853,28 +1593,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): @@ -1882,7 +1620,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() @@ -1891,295 +1628,94 @@ 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("认证未通过") + raise ValidationError("刀具类型认证未通过") -# 同步刀具型号 -class SfToolModel(models.Model): - _inherit = 'sf.cutting.tool.model' - _description = '同步刀具型号' +# 同步能力特征库 +class SfMaintenanceEquipmentImage(models.Model): + _inherit = 'maintenance.equipment.image' + _description = '能力特征库' - url = '/api/mrs_cutting_tool_model/list' + url = '/api/maintenance_equipment_image/list' - # 定时同步每日刀具型号 - def sync_tool_model(self): + # 定时同步每日能力特征库 + 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['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'], - }) - 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('同步所有刀柄类型列表成功') + 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("认证未通过") + raise ValidationError("能力特征库认证未通过") - # 同步所有刀具型号列表 - def sync_all_tool_model(self): + # 同步所有能力特征库 + 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']) - 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({ - "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('同步所有刀具型号列表成功') + 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("认证未通过") @@ -2291,4 +1827,4 @@ class ModelInternationalStandards(models.Model): "active": item['active'], }) else: - raise ValidationError("认证未通过") + 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