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_maintenance/models/sf_maintenance.py b/sf_maintenance/models/sf_maintenance.py index 90574f2b..dca24821 100644 --- a/sf_maintenance/models/sf_maintenance.py +++ b/sf_maintenance/models/sf_maintenance.py @@ -574,7 +574,8 @@ class MaintenanceStandardImage(models.Model): name = fields.Char('名称') image = fields.Binary(string='图文') type = fields.Selection( - [('加工能力', '加工能力'), ('刀尖特征', '刀尖特征'), ('柄部类型', '柄部类型'), ('走刀方向', '走刀方向'), ('冷却液', '冷却液')], + [('加工能力', '加工能力'), ('刀尖特征', '刀尖特征'), ('柄部类型', '柄部类型'), ('走刀方向', '走刀方向'), + ('冷却液', '冷却液'), ('压紧方式', '压紧方式'), ('刀片形状', '刀片形状')], string='特征') equipment_id = fields.Many2many('maintenance.equipment', 'image_id', string='设备') diff --git a/sf_maintenance/views/maintenance_views.xml b/sf_maintenance/views/maintenance_views.xml index 258dfb34..6bd0af90 100644 --- a/sf_maintenance/views/maintenance_views.xml +++ b/sf_maintenance/views/maintenance_views.xml @@ -953,40 +953,37 @@ maintenance.equipment.image.tree maintenance.equipment.image - - - - - + + + + + - - maintenance.equipment.image.form + + + maintenance.equipment.image.search maintenance.equipment.image -
- - - - - - - - - -
+ + + +
能力特征库 maintenance.equipment.image - tree,form + tree [] + - - 同步静态资源库材料 - + + + 制造-配置:每日定时同步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_category() - 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_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_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 - - + + + + + + + + + + \ 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 6eb78537..95128148 100644 --- a/sf_mrs_connect/models/res_config_setting.py +++ b/sf_mrs_connect/models/res_config_setting.py @@ -35,7 +35,7 @@ class ResConfigSettings(models.TransientModel): _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("同步资源库机床类型") diff --git a/sf_mrs_connect/models/sync_common.py b/sf_mrs_connect/models/sync_common.py index 83036854..9a5146ea 100644 --- a/sf_mrs_connect/models/sync_common.py +++ b/sf_mrs_connect/models/sync_common.py @@ -10,14 +10,68 @@ 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'] @@ -30,14 +84,13 @@ class sfProductionMaterials(models.Model): if result['status'] == 1: for item in result['production_materials_yesterday_list']: if item: - materials = self.env['sf.production.materials'].search( - [("materials_no", '=', item['materials_no'])]) + 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({ + self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], @@ -59,10 +112,9 @@ class sfProductionMaterials(models.Model): if result['status'] == 1: for item in result['production_materials_all_list']: if item: - materials = self.env['sf.production.materials'].search( - [("materials_no", '=', item['materials_no'])]) + materials = self.search([("materials_no", '=', item['materials_no'])]) if not materials: - self.env['sf.production.materials'].create({ + self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], @@ -72,7 +124,6 @@ class sfProductionMaterials(models.Model): materials.name = item['name'] materials.remark = item['remark'] materials.active = item['active'] - else: raise ValidationError("材料认证未通过") @@ -83,7 +134,7 @@ 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'] @@ -95,8 +146,7 @@ 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: @@ -114,7 +164,7 @@ class sfMaterialModel(models.Model): materials_model.density = item['density'] materials_model.active = item['active'] else: - self.env['sf.materials.model'].create({ + self.create({ "name": item['name'], "materials_no": item['materials_no'], "remark": item['remark'], @@ -144,12 +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'], @@ -186,7 +235,7 @@ 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'] @@ -198,14 +247,13 @@ 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.active = item['active'] else: - self.env['sf.production.process.category'].create({ + self.create({ "name": item['name'], "code": item['code'], "active": item['active'], @@ -226,10 +274,9 @@ 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'], @@ -247,7 +294,7 @@ 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'] @@ -259,8 +306,7 @@ class sfProductionProcess(models.Model): if result['status'] == 1: for item in result['production_process_yesterday_list']: if item: - production_process = self.env['sf.production.process'].search( - [("process_encode", '=', item['code'])]) + production_process = self.search([("process_encode", '=', item['code'])]) category = self.env['sf.production.process.category'].search( [("code", '=', item['category_code'])]) if production_process: @@ -269,7 +315,7 @@ class sfProductionProcess(models.Model): production_process.remark = item['remark'] production_process.active = item['active'] else: - self.env['sf.production.process'].create({ + self.create({ "name": item['name'], "category_id": category.id, "process_encode": item['code'], @@ -277,7 +323,7 @@ class sfProductionProcess(models.Model): "active": item['active'], }) else: - raise ValidationError("表面工艺认证未通过") # 定时同步表面工艺 + raise ValidationError("表面工艺认证未通过") # 同步所有表面工艺 def sync_all_production_process(self): @@ -292,12 +338,11 @@ class sfProductionProcess(models.Model): if result['status'] == 1: for item in result['production_process_all_list']: if item: - production_process = self.env['sf.production.process'].search( - [("process_encode", '=', item['code'])]) + 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.env['sf.production.process'].create({ + self.create({ "name": item['name'], "category_id": category.id, "process_encode": item['process_encode'], @@ -319,7 +364,7 @@ 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'] @@ -331,14 +376,13 @@ class sfProcessingTechnology(models.Model): if result['status'] == 1: for item in result['processing_technology_yesterday_list']: if item: - processing_technology = self.env['sf.processing.technology'].search( - [("process_encode", '=', item['process_encode'])]) + 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({ + self.create({ "name": item['name'], "process_encode": item['process_encode'], "remark": item['remark'], @@ -360,10 +404,9 @@ class sfProcessingTechnology(models.Model): if result['status'] == 1: for item in result['processing_technology_all_list']: if item: - processing_technology = self.env['sf.processing.technology'].search( - [("process_encode", '=', item['process_encode'])]) + processing_technology = self.search([("process_encode", '=', item['process_encode'])]) if not processing_technology: - self.env['sf.processing.technology'].create({ + self.create({ "name": item['name'], "process_encode": item['process_encode'], "remark": item['remark'], @@ -383,7 +426,7 @@ 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'] @@ -394,13 +437,12 @@ class MachineBrandTags(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_tags_yesterday_list']: - brand_tags = self.env['sf.machine.brand.tags'].search( - [("id", '=', item['id'])]) + 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({ + self.create({ "name": item['name'], "color": item['color'], }) @@ -420,10 +462,9 @@ class MachineBrandTags(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_brand_tags_all_list']: - brand_tags = self.env['sf.machine.brand.tags'].search( - [("name", '=', item['name'])]) + brand_tags = self.search([("name", '=', item['name'])]) if not brand_tags: - self.env['sf.machine.brand.tags'].create({ + self.create({ "name": item['name'], "color": item['color'], }) @@ -440,7 +481,7 @@ class MachineControlSystem(models.Model): 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'] @@ -452,8 +493,7 @@ class MachineControlSystem(models.Model): if result['status'] == 1: for item in result['machine_control_system_yesterday_list']: if item: - control_system = self.env['sf.machine.control_system'].search( - [("code", '=', item['code'])]) + 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'] @@ -461,7 +501,7 @@ class MachineControlSystem(models.Model): control_system.brand_id = brand.id control_system.active = item['active'] else: - self.env['sf.machine.control_system'].create({ + self.create({ "remark": item['remark'], "name": item['name'], "code": item['code'], @@ -472,7 +512,7 @@ class MachineControlSystem(models.Model): 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'] @@ -484,11 +524,10 @@ class MachineControlSystem(models.Model): if result['status'] == 1: for item in result['machine_control_system_all_list']: if item: - control_system = self.env['sf.machine.control_system'].search( - [("code", '=', item['code'])]) + control_system = self.search([("code", '=', item['code'])]) brand = self.env['sf.machine.brand'].search([('code', '=', item['brand_id'])]) if not control_system: - self.env['sf.machine.control_system'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -510,7 +549,7 @@ 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'] @@ -521,8 +560,7 @@ class MachineBrand(models.Model): 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.name = item['name'] brand.image_brand = '' if not item['image_brand'] else base64.b64encode(item.image_brand) @@ -530,7 +568,7 @@ class MachineBrand(models.Model): 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({ + self.create({ "name": item['name'], "code": item['code'], "image_brand": '' if not item['image_brand'] else base64.b64encode(item.image_brand), @@ -553,14 +591,13 @@ class MachineBrand(models.Model): 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({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -584,7 +621,7 @@ 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'] @@ -595,9 +632,9 @@ class MachineToolType(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_type_yesterday_list']: - machine_tool_type = self.env['sf.machine_tool.type'].search( - [("code", '=', item['code'])]) - control_system = self.env['sf.machine.control_system'].search([('code', '=', item['control_system_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: @@ -618,7 +655,8 @@ class MachineToolType(models.Model): 'control_system_id': control_system.id, "active": item['active'], 'brand_id': brand.id, - 'machine_tool_picture': '' if not item['machine_tool_picture'] else base64.b64decode(item['machine_tool_picture']), + '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'], @@ -642,7 +680,7 @@ class MachineToolType(models.Model): "machine_tool_category": category.id, }) else: - self.env['sf.machine_tool.type'].create({ + self.create({ "name": item['name'], "code": item['code'], "knife_type": item['knife_type'], @@ -660,7 +698,8 @@ class MachineToolType(models.Model): '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'), + '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'], @@ -702,14 +741,13 @@ class MachineToolType(models.Model): image = base64.b64decode(item['machine_tool_picture']) else: image = '' - machine_tool_type = self.env['sf.machine_tool.type'].search( - [("code", '=', item['code'])]) + 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.env['sf.machine_tool.type'].create({ + self.create({ "name": item['name'], "code": item['code'], "number_of_knife_library": item['number_of_knife_library'], @@ -767,7 +805,7 @@ class MachineToolType(models.Model): "precision_max": item['precision_max'], 'control_system_id': control_system.id, "active": item['active'], - 'brand_id':brand.id, + 'brand_id': brand.id, 'machine_tool_picture': image, "heightened_way": item['heightened_way'], "workpiece_load": item['workpiece_load'], @@ -801,7 +839,7 @@ 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'] @@ -812,12 +850,11 @@ class sfProcessingOrder(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_order_yesterday_list']: - processing_order = self.env['sf.processing.order'].search( - [("id", '=', item['id'])]) + processing_order = self.search([("id", '=', item['id'])]) if processing_order: processing_order.sequence = item['sequence'] else: - self.env['sf.processing.order'].create({ + self.create({ "sequence": item['sequence'], }) else: @@ -835,10 +872,9 @@ class sfProcessingOrder(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['processing_order_all_list']: - processing_order = self.env['sf.processing.order'].search( - [("id", '=', item['id'])]) + processing_order = self.search([("id", '=', item['id'])]) if not processing_order: - self.env['sf.processing.order'].create({ + self.create({ "sequence": item['sequence'], }) else: @@ -853,7 +889,7 @@ 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'] @@ -865,8 +901,7 @@ class sfProductionProcessParameter(models.Model): if result['status'] == 1: for item in result['mrs_production_process_parameter_yesterday_list']: if item: - production_process_parameter = self.env['sf.production.process.parameter'].search( - [("code", '=', item['code'])]) + 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: @@ -874,9 +909,9 @@ class sfProductionProcessParameter(models.Model): 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'])]) + [('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'], @@ -902,13 +937,13 @@ class sfProductionProcessParameter(models.Model): for item in result['mrs_production_process_parameter_all_list']: if item: _logger.info('create可选参数:%s' % item) - production_process_parameter = self.env['sf.production.process.parameter'].search( + production_process_parameter = self.search( [("code", '=', item['code'])]) 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'], "active": item['active'], @@ -932,7 +967,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'] @@ -943,15 +978,14 @@ class MachineToolCategory(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_category_yesterday_list']: - machine_tool_category = self.env['sf.machine_tool.category'].search( - [("code", '=', item['code'])]) + 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: - self.env['sf.machine_tool.category'].create({ + self.create({ "name": item['name'], "code": item['code'], "category": item['category'], @@ -973,10 +1007,9 @@ class MachineToolCategory(models.Model): result = json.loads(r['result']) if result['status'] == 1: for item in result['machine_tool_category_all_list']: - machine_tool_category = self.env['sf.machine_tool.category'].search( - [("code", '=', item['code'])]) + machine_tool_category = self.search([("code", '=', item['code'])]) if not machine_tool_category: - self.env['sf.machine_tool.category'].create({ + self.create({ "name": item['name'], "code": item['code'], "category": item['category'], @@ -1000,7 +1033,7 @@ 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'] @@ -1014,10 +1047,9 @@ 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: - cutting_tool_material = self.env['sf.cutting.tool.material'].search( - [("code", '=', item['code'])]) + cutting_tool_material = self.search([("code", '=', item['code'])]) if not cutting_tool_material: - self.env['sf.cutting.tool.material'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1047,10 +1079,9 @@ 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: - cutting_tool_material = self.env['sf.cutting.tool.material'].search( - [("code", '=', item['code'])]) + cutting_tool_material = self.search([("code", '=', item['code'])]) if not cutting_tool_material: - self.env['sf.cutting.tool.material'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1073,7 +1104,7 @@ 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'] @@ -1087,10 +1118,9 @@ 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: - functional_cutting_tool_model = self.env['sf.functional.cutting.tool.model'].search( - [("code", '=', item['code'])]) + functional_cutting_tool_model = self.search([("code", '=', item['code'])]) if not functional_cutting_tool_model: - self.env['sf.functional.cutting.tool.model'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1121,10 +1151,9 @@ 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: - functional_cutting_tool_model = self.env['sf.functional.cutting.tool.model'].search( - [("code", '=', item['code'])]) + functional_cutting_tool_model = self.search([("code", '=', item['code'])]) if not functional_cutting_tool_model: - self.env['sf.functional.cutting.tool.model'].create({ + self.create({ "name": item['name'], "code": item['code'], "remark": item['remark'], @@ -1147,7 +1176,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'] @@ -1161,10 +1190,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'], @@ -1197,10 +1225,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'], @@ -1225,7 +1252,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'] @@ -1238,10 +1265,9 @@ class SyncMulti_Mounting_Type(models.Model): 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'], @@ -1271,10 +1297,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'], @@ -1297,7 +1322,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'] @@ -1310,10 +1335,9 @@ class SyncFixtureModel(models.Model): 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( @@ -1391,10 +1415,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( @@ -1465,7 +1488,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'] @@ -1479,10 +1502,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'], @@ -1511,10 +1533,9 @@ class SyncFunctionalFixtureType(models.Model): 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'], @@ -1538,7 +1559,7 @@ 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'] @@ -1551,22 +1572,21 @@ 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'], }) @@ -1587,24 +1607,93 @@ class SfToolType(models.Model): _logger.info('result:%s' % result) for item in result['mrs_cutting_tool_type_all_list']: if item: - cutting_tool_type = self.env['sf.cutting.tool.type'].search( - [("code", '=', item['code'])]) + cutting_tool_type = self.search([("code", '=', item['code'])]) + cutting_tool_material = self.env['sf.cutting.tool.material'].search( + [("code", '=', item['cutting_tool_material_code'])]) if not cutting_tool_type: - self.env['sf.cutting.tool.type'].create({ + self.create({ "name": item['name'], "code": item['code'], - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, + "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) else: cutting_tool_type.write({ "name": item['name'], - "cutting_tool_material_id": self.env['sf.cutting.tool.material'].search( - [("code", '=', item['cutting_tool_material_code'])]).id, + "cutting_tool_material_id": cutting_tool_material.id, "remark": item['remark'], "active": item['active'], }) else: raise ValidationError("刀具类型认证未通过") + + +# 同步能力特征库 +class SfMaintenanceEquipmentImage(models.Model): + _inherit = 'maintenance.equipment.image' + _description = '能力特征库' + + url = '/api/maintenance_equipment_image/list' + + # 定时同步每日能力特征库 + def sync_maintenance_equipment_image_yesterday(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + sf_secret_key = sf_sync_config['sf_secret_key'] + headers = Common.get_headers(self, token, sf_secret_key) + strUrl = sf_sync_config['sf_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + _logger.info('result:%s' % result) + for item in result['ability_feature_library_yesterday_list']: + if item: + ability_feature_library = self.search([("name", '=', item['name'])]) + if not ability_feature_library: + self.create({ + "name": item['name'], + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) + else: + ability_feature_library.write({ + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) + else: + raise ValidationError("能力特征库认证未通过") + + # 同步所有能力特征库 + def sync_all_maintenance_equipment_image(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + sf_secret_key = sf_sync_config['sf_secret_key'] + headers = Common.get_headers(self, token, sf_secret_key) + strUrl = sf_sync_config['sf_url'] + self.url + r = requests.post(strUrl, json={}, data=None, headers=headers) + r = r.json() + result = json.loads(r['result']) + if result['status'] == 1: + _logger.info('result:%s' % result) + for item in result['ability_feature_library_all_list']: + if item: + ability_feature_library = self.search([("name", '=', item['name'])]) + if not ability_feature_library: + self.create({ + "name": item['name'], + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) + else: + ability_feature_library.write({ + "type": item['type'], + "image": '' if not item['image'] else base64.b64decode(item['image']), + "active": item['active'], + }) + else: + raise ValidationError("能力特征库认证未通过")