diff --git a/sf_base/__manifest__.py b/sf_base/__manifest__.py index 105cd241..2352c3a6 100644 --- a/sf_base/__manifest__.py +++ b/sf_base/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'YZ', 'website': 'https://www.sf.jikimo.com', - 'depends': ['account'], + 'depends': ['account', 'base'], 'data': [ 'security/group_security.xml', 'security/ir.model.access.csv', diff --git a/sf_base/models/__init__.py b/sf_base/models/__init__.py index e53038fc..27b447be 100644 --- a/sf_base/models/__init__.py +++ b/sf_base/models/__init__.py @@ -1,3 +1,2 @@ - from. import sf_base from. import sf_common diff --git a/sf_base/models/sf_base.py b/sf_base/models/sf_base.py index 05334842..abe0255b 100644 --- a/sf_base/models/sf_base.py +++ b/sf_base/models/sf_base.py @@ -80,47 +80,7 @@ class MachineTool(models.Model): active = fields.Boolean('有效', default=True) - # @api.depends('type_id') - # def _compute_type_id(self): - # to_reset = self.filtered(lambda e: e.type_id != e.type_id.id) - # to_reset.type_id = False - # 编码规则:加工工厂编码-品牌编码-注册年月-00001 - # def get_machine_tool_code(self): - # partner = self.env['res.partner'].sudo().search( - # [('is_factory', '=', True)], - # limit=1, - # order="id desc") - # brand = self.env['mrs.machine.brand'].sudo().search( - # [('tag_ids', '=', '机床')], - # limit=1, - # order="id desc") - # if not brand: - # num = item.brand_id.code + "%04d" % 1 - # item.code = num - # else: - # print('--------') - # print(type) - # m = int(type.code[-4:]) + 1 - # num = item.brand_id.code + "%04d" % m - # item.code = num - - # 选择机床型号时,该型号的基本信息带出并赋给机床对应的信息里 - - # @api.onchange('type_id') - # def get_type_info(self): - # for item in self: - # item.knife_type = item.type_id.knife_type - # item.number_of_knife_library = item.type_id.number_of_knife_library - # item.number_of_axles = item.type_id.number_of_axles - # item.rotate_speed = item.type_id.rotate_speed - # item.precision = item.type_id.precision - # item.control_system_id = item.type_id.control_system_id - # item.x_axis = item.type_id.x_axis - # item.y_axis = item.type_id.y_axis - # item.z_axis = item.type_id.z_axis - # item.b_axis = item.type_id.b_axis - # item.c_axis = item.type_id.c_axis class MachineToolType(models.Model): @@ -153,48 +113,15 @@ class MachineToolType(models.Model): active = fields.Boolean('有效', default=True) code = fields.Char('编码') - # @api.onchange('brand_id') - # def get_machine_tool_type_code(self): - # for item in self: - # if not item.brand_id: - # return False - # type = self.env['mrs.machine_tool.type'].sudo().search( - # [('brand_id', '=', item.brand_id.id)], - # limit=1, - # order="id desc" - # ) - # print(item.brand_id.id) - # if not type: - # num = item.brand_id.code + "%04d" % 1 - # item.code = num - # print(item.code) - # else: - # print('----------') - # m = int(type.code[-4:]) + 1 - # num = item.brand_id.code + "%04d" % m - # item.code = num - # print(item.code) - # 刀具 class CuttingTool(models.Model): _name = 'mrs.cutting_tool.category' _description = '刀具类别' - # def get_cutting_tool_category_code(self): - # code = self.env['mrs.cutting_tool.category'].sudo().search( - # [('code', '!=', False)], limit=1, - # order="id desc") - # if not code: - # num = "%03d" % 1 - # else: - # m = int(code.code) + 1 - # num = "%03d" % m - # return num - code = fields.Char('编码') name = fields.Char('名称') - # type_ids = fields.One2many('mrs.cutting_tool.type', 'category_id', string='刀具型号') + remark = fields.Text('备注') active = fields.Boolean('有效', default=True) @@ -216,23 +143,3 @@ class CuttingToolType(models.Model): brand_id = fields.Many2one('mrs.machine.brand', string='品牌') remark = fields.Text('备注') active = fields.Boolean('有效', default=True) - - # @api.onchange('brand_id', 'category_id') - # def get_cutting_tool_type_code(self): - # for item in self: - # if not item.brand_id: - # return False - # if not item.category_id: - # return False - # type = self.env['mrs.cutting_tool.type'].sudo().search( - # [('brand_id', '=', item.brand_id.id), ('brand_id', '=', item.category_id.id)], - # limit=1, - # order="id desc" - # ) - # if not type: - # num = item.brand_id.code + item.category_id.code + "%03d" % 1 - # item.code = num - # else: - # m = int(type.code[-4:]) + 1 - # num = item.brand_id.code + item.category_id.code + "%03d" % m - # item.code = num diff --git a/sf_base/models/sf_common.py b/sf_base/models/sf_common.py index 17bd0a79..95dd6595 100644 --- a/sf_base/models/sf_common.py +++ b/sf_base/models/sf_common.py @@ -23,12 +23,12 @@ class MrsMaterialModel(models.Model): _description = '材料型号' remark = fields.Text("备注") name = fields.Char('型号名') - need_h = fields.Boolean("需要热处理", default="false") - mf_materia_post = fields.Char("热处理后硬度") + need_h = fields.Boolean("热处理", default="false") + mf_materia_post = fields.Char("热处理后密度") density = fields.Float("密度(kg/m³)") materials_id = fields.Many2one('mrs.production.materials', "材料名") materials_num = fields.Char("编码号") - material_no = fields.Char("编码") + materials_no = fields.Char("编码") active = fields.Boolean('有效', default=True) @@ -52,9 +52,10 @@ class MrsProcessingTechnology(models.Model): remark = fields.Text('备注', index=True) process_encode = fields.Char("编码") processing_order_ids = fields.Many2many('mrs.processing.order', 'mrs_associated_processes', - index=True, string='工序') + index=True, string='工序') active = fields.Boolean('有效', default=True) + class MrsProcessingOrder(models.Model): _name = 'mrs.processing.order' _description = '工序' @@ -66,6 +67,7 @@ class MrsProcessingOrder(models.Model): production_process_id = fields.Many2one('mrs.production.process', string="表面工艺") + class ProductTemplate(models.Model): _inherit = 'product.template' _description = '产品' diff --git a/sf_base/security/group_security.xml b/sf_base/security/group_security.xml index fdbc3ae5..c32538c7 100644 --- a/sf_base/security/group_security.xml +++ b/sf_base/security/group_security.xml @@ -1,5 +1,27 @@ + + 员工 + 1 + + + + 管理 + 2 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sf_base/security/ir.model.access.csv b/sf_base/security/ir.model.access.csv index 40dcc91c..e754163e 100644 --- a/sf_base/security/ir.model.access.csv +++ b/sf_base/security/ir.model.access.csv @@ -1,17 +1,17 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_mrs_machine_tool,mrs_machine_tool,model_mrs_machine_tool,base.group_user,1,0,0,0 -access_mrs_cutting_tool_category,mrs_cutting_tool_category,model_mrs_cutting_tool_category,base.group_user,1,0,0,0 -access_mrs_machine_tool_type,mrs_machine_tool_type,model_mrs_machine_tool_type,base.group_user,1,0,0,0 -access_mrs_cutting_tool_type,mrs_cutting_tool_type,model_mrs_cutting_tool_type,base.group_user,1,0,0,0 -access_mrs_machine_brand,mrs_machine_brand,model_mrs_machine_brand,base.group_user,1,0,0,0 -access_mrs_machine_brand_tags,mrs_machine_brand_tags,model_mrs_machine_brand_tags,base.group_user,1,0,0,0 -access_mrs_machine_tool_type_control_system,mrs_machine_tool_type_control_system,model_mrs_machine_tool_type_control_system,base.group_user,1,0,0,0 +access_mrs_machine_tool,mrs_machine_tool,model_mrs_machine_tool,base.group_user,1,1,1,1 +access_mrs_cutting_tool_category,mrs_cutting_tool_category,model_mrs_cutting_tool_category,base.group_user,1,1,1,1 +access_mrs_machine_tool_type,mrs_machine_tool_type,model_mrs_machine_tool_type,base.group_user,1,1,1,1 +access_mrs_cutting_tool_type,mrs_cutting_tool_type,model_mrs_cutting_tool_type,base.group_user,1,1,1,1 +access_mrs_machine_brand,mrs_machine_brand,model_mrs_machine_brand,base.group_user,1,1,1,1 +access_mrs_machine_brand_tags,mrs_machine_brand_tags,model_mrs_machine_brand_tags,base.group_user,1,1,1,1 +access_mrs_machine_tool_type_control_system,mrs_machine_tool_type_control_system,model_mrs_machine_tool_type_control_system,base.group_user,1,1,1,1 -access_mrs_processing_order,mrs_processing_order,model_mrs_processing_order,base.group_user,1,0,0,0 -access_mrs_production_process,mrs_production_process,model_mrs_production_process,base.group_user,1,0,0,0 -access_mrs_production_materials,mrs_production_materials,model_mrs_production_materials,base.group_user,1,0,0,0 -access_mrs_materials_model,mrs_materials_model,model_mrs_materials_model,base.group_user,1,0,0,0 -access_mrs_processing_technology,mrs_processing_technology,model_mrs_processing_technology,base.group_user,1,0,0,0 +access_mrs_processing_order,mrs_processing_order,model_mrs_processing_order,base.group_user,1,1,1,1 +access_mrs_production_process,mrs_production_process,model_mrs_production_process,base.group_user,1,1,1,1 +access_mrs_production_materials,mrs_production_materials,model_mrs_production_materials,base.group_user,1,1,1,1 +access_mrs_materials_model,mrs_materials_model,model_mrs_materials_model,base.group_user,1,1,1,1 +access_mrs_processing_technology,mrs_processing_technology,model_mrs_processing_technology,base.group_user,1,1,1,1 diff --git a/sf_base/views/menu_view.xml b/sf_base/views/menu_view.xml index e1731e63..927cbce1 100644 --- a/sf_base/views/menu_view.xml +++ b/sf_base/views/menu_view.xml @@ -2,20 +2,43 @@ + + + + + + + + + - + - @@ -38,10 +59,8 @@ id="menu_mrs_production_process" name="表面工艺" parent="menu_mrs_production_process_1" - sequence="2" + sequence="1" action="mrs_production_process" - - /> @@ -49,7 +68,7 @@ id="menu_mrs_production_materials" name="材料" parent="menu_mrs_production_materials_1" - sequence="2" + sequence="1" action="mrs_production_materials" @@ -58,7 +77,7 @@ id="menu_mrs_materials_model" name="材料型号" parent="menu_mrs_production_materials_1" - sequence="2" + sequence="1" action="mrs_materials_model" @@ -69,13 +88,10 @@ id="menu_mrs_processing_technology" name="加工工艺" parent="menu_mrs_production_process_1" - sequence="2" + sequence="1" action="mrs_processing_technology"/> - - - + sequence="0"/> - - - \ No newline at end of file diff --git a/sf_base/views/mrs_base_view.xml b/sf_base/views/mrs_base_view.xml index b5d4797d..6894df01 100644 --- a/sf_base/views/mrs_base_view.xml +++ b/sf_base/views/mrs_base_view.xml @@ -312,4 +312,97 @@

+ + #------------------机床注册------------------ + + + search.mrs.machine_tool + mrs.machine_tool + + + + + + + + + tree.mrs.machine_tool + mrs.machine_tool + + + + + + + + + + + + form.mrs.machine_tool + mrs.machine_tool + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + 机床注册 + ir.actions.act_window + mrs.machine_tool + tree,form + +

+ [机床注册] +

+

+

+
+
\ No newline at end of file diff --git a/sf_base/views/mrs_common_view.xml b/sf_base/views/mrs_common_view.xml index 3ad854e0..e878cbfd 100644 --- a/sf_base/views/mrs_common_view.xml +++ b/sf_base/views/mrs_common_view.xml @@ -109,7 +109,7 @@
- + @@ -136,7 +136,7 @@ mrs.materials.model - + @@ -150,7 +150,7 @@ - + @@ -173,7 +173,7 @@ - + diff --git a/sf_bf_connect/__init__.py b/sf_bf_connect/__init__.py index f719d7e8..50ed18aa 100644 --- a/sf_bf_connect/__init__.py +++ b/sf_bf_connect/__init__.py @@ -1,3 +1 @@ # -*-coding:utf-8-*- -from . import models -from . import controllers diff --git a/sf_mrs_sync/data/sf_cron.xml b/sf_mrs_sync/data/sf_cron.xml index 6131b340..993e519b 100644 --- a/sf_mrs_sync/data/sf_cron.xml +++ b/sf_mrs_sync/data/sf_cron.xml @@ -80,10 +80,10 @@ - 同步资源库机床 + 同步注册机床 code - model.sync_machine_tool() + model.enroll_machine_tool() 1 days -1 diff --git a/sf_mrs_sync/models/res_config_setting.py b/sf_mrs_sync/models/res_config_setting.py index e42776c7..4cf815e3 100644 --- a/sf_mrs_sync/models/res_config_setting.py +++ b/sf_mrs_sync/models/res_config_setting.py @@ -14,6 +14,20 @@ class ResConfigSettings(models.TransientModel): mrs_secret_key = fields.Char(string='密钥', default= 'wBmxej38OkErKhD6') mrs_url = fields.Char(string='访问地址', default= 'https://mrs.cs.jikimo.com') + def sf_all_sync(self): + self.env['mrs.production.materials'].sync_all_production_materials() + self.env['mrs.materials.model'].sync_all_materials_model() + self.env['mrs.production.process'].sync_all_production_process() + self.env['mrs.processing.technology'].sync_all_processing_technology() + self.env['mrs.machine.brand.tags'].sync_all_machine_brand_tags() + self.env['mrs.machine_tool.type.control_system'].sync_all_machine_tool_type_control_system() + self.env['mrs.machine.brand'].sync_all_machine_brand() + # self.env['mrs.machine_tool'].sync_all_machine_tool() + self.env['mrs.machine_tool.type'].sync_all_machine_tool_type() + self.env['mrs.cutting_tool.category'].sync_all_cutting_tool_category() + self.env['mrs.cutting_tool.type'].sync_all_cutting_tool_type() + return _logger.info("同步资源库成功") + @api.model def get_values(self): """ diff --git a/sf_mrs_sync/models/sf_sync_common.py b/sf_mrs_sync/models/sf_sync_common.py index 5484d294..262c3a84 100644 --- a/sf_mrs_sync/models/sf_sync_common.py +++ b/sf_mrs_sync/models/sf_sync_common.py @@ -5,6 +5,8 @@ from odoo import models from odoo.exceptions import ValidationError import logging from odoo.addons.sf_base.commons.common import Common + +from odoo.http import request from .res_config_setting import ResConfigSettings _logger = logging.getLogger(__name__) @@ -17,7 +19,8 @@ class MrsProductionMaterials(models.Model): # 定时同步每日材料 def sync_production_materials(self): - #配置中获取token + + # 配置中获取token sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] mrs_secret_key = sf_sync_config['mrs_secret_key'] @@ -34,11 +37,11 @@ class MrsProductionMaterials(models.Model): brand = self.env['mrs.production.materials'].search( [("materials_no", '=', item['materials_no'])]) if brand: - brand.id=item['id'], - brand.name= item['name'], - brand.materials_no= item['materials_no'], - brand.remark= item['remark'], - brand.active= item['active'] + brand.id = item['id'], + brand.name = item['name'], + brand.materials_no = item['materials_no'], + brand.remark = item['remark'], + brand.active = item['active'] else: self.env['mrs.production.materials'].create({ "id": item['id'], @@ -52,6 +55,7 @@ class MrsProductionMaterials(models.Model): # 同步所有材料 def sync_all_production_materials(self): + _logger = '正在同步所有材料' sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] mrs_secret_key = sf_sync_config['mrs_secret_key'] @@ -102,7 +106,15 @@ class MrsMaterialModel(models.Model): brand = self.env['mrs.materials.model'].search( [("materials_num", '=', item['materials_num'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.materials_no = item['materials_no'], + brand.remark = item['remark'], + brand.active = item['active'], + brand.mf_materia_post = item['mf_materia_post'], + brand.materials_id = item['materials_id'], + brand.need_h = item['need_h'], + brand.density = item['density'] else: self.env['mrs.materials.model'].create({ "id": item['id'], @@ -172,7 +184,12 @@ class MrsProductionProcess(models.Model): brand = self.env['mrs.production.process'].search( [("process_encode", '=', item['process_encode'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.process_encode = item['process_encode'], + brand.remark = item['remark'], + brand.active = item['active'], + brand.remark = item['remark'] else: self.env['mrs.production.process'].create({ "id": item['id'], @@ -235,7 +252,11 @@ class MrsProcessingTechnology(models.Model): brand = self.env['mrs.processing.technology'].search( [("process_encode", '=', item['process_encode'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.process_encode = item['process_encode'], + brand.remark = item['remark'], + brand.active = item['active'] else: self.env['mrs.processing.technology'].create({ "id": item['id'], @@ -297,7 +318,9 @@ class MachineBrandTags(models.Model): brand = self.env['mrs.machine.brand.tags'].search( [("id", '=', item['id'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.color = item['color'] else: self.env['mrs.machine.brand.tags'].create({ "id": item['id'], @@ -353,7 +376,10 @@ class MachineControlSystem(models.Model): brand = self.env['mrs.machine_tool.type.control_system'].search( [("code", '=', item['code'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.code = item['code'], + brand.active = item['active'] else: self.env['mrs.machine_tool.type.control_system'].create({ "id": item['id'], @@ -419,7 +445,10 @@ class MachineBrand(models.Model): brand = self.env['mrs.machine.brand'].search( [("code", '=', item['code'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.code = item['code'], + brand.active = item['active'] else: self.env['mrs.machine.brand'].create({ "id": item['id'], @@ -464,6 +493,49 @@ class MachineTool(models.Model): _inherit = 'mrs.machine_tool' _description = '机床' url = '/api/machine_tool/list' + crea_url = '/api/machine_tool/create' + + # 注册同步机床 + def enroll_machine_tool(self): + sf_sync_config = self.env['res.config.settings'].get_values() + token = sf_sync_config['token'] + mrs_secret_key = sf_sync_config['mrs_secret_key'] + headers = Common.get_headers(self, token, mrs_secret_key) + strurl = sf_sync_config['mrs_url'] + self.crea_url + objs_all = request.env['mrs.machine_tool'].sudo().search([]) + machine_tool_list = [] + if objs_all: + for item in objs_all: + val = { + 'id': item.id, + 'name': item.name, + 'code': item.code, + 'precision': item.precision, + 'knife_type': item.knife_type, + 'registration_date': str(item.registration_date), + 'number_of_knife_library': item.number_of_knife_library, + 'rotate_speed': item.rotate_speed, + 'number_of_axles': item.number_of_axles, + 'control_system_id': item.control_system_id.id, + # 'type_id': item.type_id.id, + # 'brand_id': item.brand_id.id, + 'factory_id': item.factory_id.id, + 'supplier_id': item.supplier_id.id, + '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, + 'state': item.state, + 'active': item.active + } + machine_tool_list.append(val) + kw = json.dumps(machine_tool_list, ensure_ascii=False) + print(type(kw)) + r = requests.post(strurl, json=kw, data=None, headers=headers) + print(r) + else: + raise _logger.info("没有注册机床") # 定时同步机床 def sync_machine_tool(self): @@ -477,11 +549,31 @@ class MachineTool(models.Model): r = r.json() result = json.loads(r['result']) if result['status'] == 1: - for item in result['machine_tool_yesterday_list']: + for item in result['machine_tool_all_yesterday_list']: brand = self.env['mrs.machine_tool'].search( [("code", '=', item['code'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.code = item['code'], + brand.precision = item['precision'], + + brand.knife_type = item['knife_type'], + brand.registration_date = item['registration_date'], + 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 = item['control_system_id'], + brand.type_id = item['type_id'], + brand.brand_id = item['brand_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.state = item['state'], + brand.active = item['active'] + else: self.env['mrs.machine_tool'].create({ "id": item['id'], @@ -572,7 +664,24 @@ class MachineToolType(models.Model): brand = self.env['mrs.machine_tool.type'].search( [("code", '=', item['code'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.code = item['code'], + brand.precision = item['precision'], + 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 = item['control_system_id'], + brand.brand_id = item['brand_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.machine_tool_id = item['machine_tool_id'] + else: self.env['mrs.machine_tool.type'].create({ "id": item['id'], @@ -655,7 +764,11 @@ class CuttingTool(models.Model): brand = self.env['mrs.cutting_tool.category'].search( [("code", '=', item['code'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.code = item['code'], + brand.active = item['active'], + brand.remark = item['remark'] else: self.env['mrs.cutting_tool.category'].create({ "id": item['id'], @@ -716,7 +829,18 @@ class CuttingToolType(models.Model): brand = self.env['mrs.cutting_tool.type'].search( [("code", '=', item['code'])]) if brand: - print(item['name']) + brand.id = item['id'], + brand.name = item['name'], + brand.code = item['code'], + brand.active = item['active'], + brand.remark = item['remark'], + brand.diameter = item['diameter'], + brand.cone_angle_pitch = item['cone_angle_pitch'], + brand.shank_diameter = item['shank_diameter'], + brand.long_blade = item['long_blade'], + brand.taper_shank_length = item['taper_shank_length'], + brand.tool_length = item['tool_length'], + brand.blade_number = item['blade_number'] else: self.env['mrs.cutting_tool.type'].create({ "id": item['id'], @@ -737,7 +861,7 @@ class CuttingToolType(models.Model): else: raise ValidationError("认证未通过") - # 同步所有刀具型号 + # 同步所有刀具型号 def sync_all_cutting_tool_type(self): sf_sync_config = self.env['res.config.settings'].get_values() token = sf_sync_config['token'] diff --git a/sf_mrs_sync/views/sf_sync_config_settings_views.xml b/sf_mrs_sync/views/sf_sync_config_settings_views.xml index 8cc9084f..d98c166e 100644 --- a/sf_mrs_sync/views/sf_sync_config_settings_views.xml +++ b/sf_mrs_sync/views/sf_sync_config_settings_views.xml @@ -27,6 +27,9 @@ +
+