修改机床型号同步接口以及基础数据

This commit is contained in:
qihao.gong@jikimo.com
2023-06-07 15:26:44 +08:00
parent 46c57162d7
commit 9d1597089b
3 changed files with 186 additions and 163 deletions

View File

@@ -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(

View File

@@ -91,66 +91,88 @@
<field name="name"/>
<field name="brand_id"/>
<field name="remark"/>
<field name="machine_tool_picture" widget="image"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="form_sf_machine_tool_type">
<record model="ir.ui.view" id="form_sf_machine_tool_type">
<field name="name">form.sf.machine_tool.type</field>
<field name="model">sf.machine_tool.type</field>
<field name="arch" type="xml">
<form string="机床型号">
<group string="基本信息" name="base_info">
<group>
<field name="code" force_save="1" readonly="1"/>
<field name="name" required="1"/>
</group>
<group>
<field name="brand_id" required="1"
domain="[('tag_ids', '=', '机床')]"
options="{'no_create': True}"/>
</group>
</group>
<field name="machine_tool_picture" widget="image"/>
<group string="基本信息">
<group>
<field name="code" force_save="1" readonly="1"/>
<field name="name" required="1"/>
</group>
<group>
<field name="machine_tool_category"/>
<field name="brand_id" required="1"
domain="[('tag_ids', '=', '机床')]"
options="{'no_create': True}" />
</group>
</group>
<group string="参数">
<group>
<field name="knife_type" required="1"/>
<field name="number_of_knife_library" required="1" options="{'format': false}"/>
<field name="number_of_axles" required="1" widget="radio" options="{'horizontal': true}"/>
<label for="x_axis" string="加工行程(mm)"
attrs="{'invisible': [('number_of_axles', '=', False)]}"/>
<div class="o_address_format"
attrs="{'invisible': [('number_of_axles', '=', False)]}">
<label for="x_axis" string="x"/>
<field name="x_axis" class="o_address_city" required="1" options="{'format': false}"/>
<label for="y_axis" string="y"/>
<field name="y_axis" class="o_address_zip" required="1" options="{'format': false}"/>
<label for="z_axis" string="z"/>
<field name="z_axis" class="o_address_zip" required="1" options="{'format': false}"/>
<label for="b_axis" string="b"
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}"/>
<field name="b_axis" class="o_address_city" required="1"
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}"
options="{'format': false}"/>
<label for="c_axis" string="c"
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}"/>
<field name="c_axis" class="o_address_zip" required="1"
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}"
options="{'format': false}"/>
</div>
</group>
<group>
<field name="rotate_speed" string="转速(min)" required="1" options="{'format': false}"/>
<field name="precision" required="1" string="加工精度(mm)"/>
<field name="control_system_id" required="1" options="{'no_create': True}"/>
</group>
</group>
<group>
<field name="control_system_id" required="1" options="{'no_create': True}" />
<field name="workbench_L" required="1"/>
<field name="workbench_W" required="1"/>
<field name="machine_tool_L" required="1"/>
<field name="machine_tool_W" required="1"/>
<field name="machine_tool_H" required="1"/>
<field name="knife_type" required="1"/>
<field name="workpiece_load" required="1"/>
<field name="lead_screw" required="1"/>
<field name="taper" required="1"/>
<field name="torque" required="1"/>
<field name="motor_power" required="1"/>
<field name="number_of_knife_library" required="1" options="{'format': false}"/>
<field name="number_of_axles" required="1" widget="radio" options="{'horizontal': true}"/>
<label for="x_axis" string="加工行程(mm)"
attrs="{'invisible': [('number_of_axles', '=', False)]}"/>
<div class="test_model"
attrs="{'invisible': [('number_of_axles', '=', False)]}">
<label for="x_axis" string="x"/>
<field name="x_axis" class="o_address_zip" required="1" options="{'format': false}" />
<span>&amp;nbsp;</span>
<label for="y_axis" string="y"/>
<field name="y_axis" class="o_address_zip" required="1" options="{'format': false}" />
<span>&amp;nbsp;</span>
<label for="z_axis" string="z"/>
<field name="z_axis" class="o_address_zip" required="1" options="{'format': false}" />
<br></br>
<label for="b_axis" string="b"
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}"/>
<field name="b_axis" class="o_address_zip" required="1"
attrs="{'invisible': [('number_of_axles', '=', '三轴')]}" options="{'format': false}" />
<span>&amp;nbsp;</span>
<label for="c_axis" string="c"
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}"/>
<field name="c_axis" class="o_address_zip" required="1"
attrs="{'invisible': [('number_of_axles', 'in', ['三轴','四轴'])]}" options="{'format': false}" />
</div>
</group>
<group>
<field name="heightened_way" required="1"/>
<field name="tool_quality_max" required="1"/>
<field name="tool_long_max" required="1"/>
<field name="tool_diameter_max" required="1"/>
<field name="guide_rail" required="1"/>
<field name="feed_speed" required="1"/>
<field name="tool_speed" required="1"/>
<field name="distance" required="1"/>
<field name="rotate_speed" string="主轴转速(min)" required="1" options="{'format': false}"/>
<field name="precision" required="1" string="X轴定位精度(mm)(mm)"/>
</group>
</group>
<group string="其它">
<field name="remark"/>
</group>
</form>
</field>
</record>

View File

@@ -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: