diff --git a/sf_base/models/base.py b/sf_base/models/base.py index 1abc5622..4c77c114 100644 --- a/sf_base/models/base.py +++ b/sf_base/models/base.py @@ -84,7 +84,31 @@ class MachineTool(models.Model): state = fields.Selection( [("正常", "正常"), ("故障", "故障"), ("不可用", "不可用")], default='正常', string="机床状态") - + #0606新增字段 + machine_tool_picture = fields.Binary('机床图片') + heightened_way = fields.Selection([ + ('sifudianji', '伺服电机驱动'), + ('youyagang', '油压缸驱动'), + ('chilunjia', '齿轮架驱动') + ], string="主轴加高方式", default='sifudianji') + workpiece_load = fields.Char('工件负载') + lead_screw = fields.Char('丝杆') + workbench_L = fields.Char('工作台长度(mm)') + workbench_W = fields.Char('工作台宽度(mm)') + guide_rail = fields.Char('导轨') + machine_tool_L = fields.Char('机床长度(mm)') + machine_tool_W = fields.Char('机床宽度(mm)') + machine_tool_H = fields.Char('机床高度(mm)') + feed_speed = fields.Char('进给速度(mm/min)') + tool_speed = fields.Char('刀具速度') + distance = fields.Char('主轴端面至工作台面距离(mm)') + taper = fields.Char('主轴锥度(°)') + torque = fields.Char('主轴点击扭矩(n/m)') + motor_power = fields.Char('主轴电机功率(kw)') + tool_quality_max = fields.Char('刀具最大质量') + tool_long_max = fields.Char('刀具最大长度') + tool_diameter_max = fields.Char('刀具最大刀径') + machine_tool_category = fields.Many2one('sf.machine_tool.category', string='机床类型') # 一个机床对应一個加工工厂,一个加工工厂对应多个机床 factory_id = fields.Many2one('res.partner', string='所属工厂', domain="[('is_factory', '=', True)]") @@ -152,6 +176,26 @@ class MachineTool(models.Model): item.z_axis = item.type_id.z_axis item.b_axis = item.type_id.b_axis item.c_axis = item.type_id.c_axis + item.machine_tool_picture = item.type_id.machine_tool_picture + item.heightened_way = item.type_id.heightened_way + item.workpiece_load = item.type_id.workpiece_load + item.lead_screw = item.type_id.lead_screw + item.workbench_L = item.type_id.workbench_L + item.workbench_W = item.type_id.workbench_W + item.guide_rail = item.type_id.guide_rail + item.machine_tool_L = item.type_id.machine_tool_L + item.machine_tool_W = item.type_id.machine_tool_W + item.machine_tool_H = item.type_id.machine_tool_H + item.feed_speed = item.type_id.feed_speed + item.tool_speed = item.type_id.tool_speed + item.distance = item.type_id.distance + item.taper = item.type_id.taper + item.torque = item.type_id.torque + item.motor_power = item.type_id.motor_power + item.tool_quality_max = item.type_id.tool_quality_max + item.tool_long_max = item.type_id.tool_long_max + item.tool_diameter_max = item.type_id.tool_diameter_max + item.machine_tool_category = item.type_id.machine_tool_category.id # 注册同步机床 def enroll_machine_tool(self): @@ -214,6 +258,33 @@ class MachineToolType(models.Model): default="", string="刀把类型") number_of_knife_library = fields.Integer('刀库数量') rotate_speed = fields.Integer('转速') + #0606新增字段 + created_user = fields.Many2one('res.users', string='创建人', default=lambda self: self.env.user) + machine_tool_picture = fields.Binary('机床图片') + heightened_way = fields.Selection([ + ('sifudianji', '伺服电机驱动'), + ('youyagang', '油压缸驱动'), + ('chilunjia', '齿轮架驱动') + ], string="主轴加高方式", default='sifudianji') + workpiece_load = fields.Char('工件负载') + lead_screw = fields.Char('丝杆') + workbench_L = fields.Char('工作台长度(mm)') + workbench_W = fields.Char('工作台宽度(mm)') + guide_rail = fields.Char('导轨') + machine_tool_L = fields.Char('机床长度(mm)') + machine_tool_W = fields.Char('机床宽度(mm)') + machine_tool_H = fields.Char('机床高度(mm)') + feed_speed = fields.Char('进给速度(mm/min)') + tool_speed = fields.Char('刀具速度') + distance = fields.Char('主轴端面至工作台面距离(mm)') + taper = fields.Char('主轴锥度(°)') + torque = fields.Char('主轴点击扭矩(n/m)') + motor_power = fields.Char('主轴电机功率(kw)') + tool_quality_max = fields.Char('刀具最大质量') + tool_long_max = fields.Char('刀具最大长度') + tool_diameter_max = fields.Char('刀具最大刀径') + machine_tool_category = fields.Many2one('sf.machine_tool.category', string='机床类型') + # 多个型号对应一个机床 machine_tool_id = fields.Many2one('sf.machine_tool', '机床') number_of_axles = fields.Selection( diff --git a/sf_base/views/base_view.xml b/sf_base/views/base_view.xml index 3eb49034..7aa192c1 100644 --- a/sf_base/views/base_view.xml +++ b/sf_base/views/base_view.xml @@ -91,66 +91,88 @@ + - + form.sf.machine_tool.type sf.machine_tool.type - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - diff --git a/sf_mrs_connect/models/sync_common.py b/sf_mrs_connect/models/sync_common.py index 8a1c258a..dc428061 100644 --- a/sf_mrs_connect/models/sync_common.py +++ b/sf_mrs_connect/models/sync_common.py @@ -567,121 +567,6 @@ class MachineBrand(models.Model): raise ValidationError("认证未通过") -class MachineTool(models.Model): - _inherit = 'sf.machine_tool' - _description = '机床' - url = '/api/machine_tool/list' - crea_url = '/api/machine_tool/create' - - # 定时同步机床 - def sync_machine_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']) - if result['status'] == 1: - for item in result['machine_tool_all_yesterday_list']: - brand = self.env['sf.machine_tool'].search( - [("code", '=', item['code'])]) - if brand: - 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['sf.machine_tool'].create({ - "id": item['id'], - "name": item['name'], - "precision": item['precision'], - "code": item['code'], - "status": item['status'], - "knife_type": item['knife_type'], - "registration_date": 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'], - "type_id": item['type_id'], - "brand_id": item['brand_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'], - # "tag_ids": item['tag_ids'] - - }) - else: - raise ValidationError("认证未通过") - - # 同步所有机床 - def sync_all_machine_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']) - if result['status'] == 1: - for item in result['machine_tool_all_list']: - brand = self.env['sf.machine_tool'].search( - [("code", '=', item['code'])]) - if not brand: - self.env['sf.machine_tool'].create({ - - "id": item['id'], - "name": item['name'], - "precision": item['precision'], - "code": item['code'], - "status": item['status'], - "knife_type": item['knife_type'], - "registration_date": 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'], - "type_id": item['type_id'], - 'brand_id': self.env['sf.machine.brand'].search([('code', '=', item['brand_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'], - # "tag_ids": item['tag_ids'] - - }) - else: - raise ValidationError("认证未通过") - class MachineToolType(models.Model): _inherit = 'sf.machine_tool.type' @@ -726,6 +611,7 @@ class MachineToolType(models.Model): [('code', '=', item['machine_tool_id'])]).id else: + print(item['machine_tool_picture'].encode('utf-8')) self.env['sf.machine_tool.type'].create({ "id": item['id'], "name": item['name'], @@ -747,6 +633,28 @@ class MachineToolType(models.Model): [('code', '=', item['control_system_id'])]).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'), + "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": item['distance'], + "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'], + "machine_tool_category": self.env['sf.machine_tool.category'].search( + [('code', '=', item['machine_tool_category'])]).id, + }) else: @@ -772,6 +680,7 @@ class MachineToolType(models.Model): "id": item['id'], "name": item['name'], "code": item['code'], + "number_of_knife_library": item['number_of_knife_library'], "rotate_speed": item['rotate_speed'], 'machine_tool_id': self.env['sf.machine_tool'].search( @@ -788,6 +697,27 @@ class MachineToolType(models.Model): [('code', '=', item['control_system_id'])]).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']), + "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": item['distance'], + "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'], + "machine_tool_category": self.env['sf.machine_tool.category'].search( + [('code', '=', item['machine_tool_category'])]).id, }) else: