diff --git a/sf_base/models/common.py b/sf_base/models/common.py
index d163a024..2e2cccf6 100644
--- a/sf_base/models/common.py
+++ b/sf_base/models/common.py
@@ -67,6 +67,10 @@ class MrsMaterialModel(models.Model):
mf_materia_post = fields.Char("热处理后密度")
density = fields.Float("密度(kg/m³)")
materials_id = fields.Many2one('sf.production.materials', "材料名")
+ tensile_strength = fields.Float("拉伸强度(n/mm²)")
+ hardness = fields.Float("硬度(hrc)")
+ rough_machining = fields.Float("粗加工Vc(m/min)")
+ finish_machining = fields.Float("精加工Vc(m/min)")
remark = fields.Text("备注")
gain_way = fields.Selection(
[("自加工", "自加工"), ("外协", "外协"), ("采购", "采购")],
diff --git a/sf_base/views/common_view.xml b/sf_base/views/common_view.xml
index 492a3b4e..afa7d88b 100644
--- a/sf_base/views/common_view.xml
+++ b/sf_base/views/common_view.xml
@@ -82,7 +82,7 @@
-
+
@@ -105,8 +105,8 @@
sf.production.process
-
-
+
+
@@ -204,12 +204,15 @@
-
+
+
+
-
+
+
@@ -242,8 +245,13 @@
-
-
+
+
+
+
+
+
+
@@ -353,26 +361,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sf_machine_connect/__manifest__.py b/sf_machine_connect/__manifest__.py
index 9642c087..92a4548e 100644
--- a/sf_machine_connect/__manifest__.py
+++ b/sf_machine_connect/__manifest__.py
@@ -22,11 +22,10 @@
'views/ftp_button.xml',
'views/compensation.xml',
-
- 'views/SfWorkOrderBarcodes.xml',
+ # 'views/SfWorkOrderBarcodes.xml',
'views/WorkCenterBarcodes.xml',
'views/Stock_picking_Barcodes.xml',
- 'views/machine_monitor.xml',
+ # 'views/machine_monitor.xml',
'views/machine_info_present.xml',
'views/delivery_record.xml',
'views/res_config_settings_views.xml',
diff --git a/sf_machine_connect/models/ftp_client.py b/sf_machine_connect/models/ftp_client.py
index f782d6d4..cc4d60e2 100644
--- a/sf_machine_connect/models/ftp_client.py
+++ b/sf_machine_connect/models/ftp_client.py
@@ -13,6 +13,11 @@ from odoo.exceptions import ValidationError
from odoo.exceptions import UserError
from odoo.addons.sf_machine_connect.models import py2opcua, ftp_operate
+import shutil
+from io import BytesIO
+from zipfile import ZipFile
+from odoo.exceptions import MissingError
+
_logger = logging.getLogger(__name__)
@@ -537,21 +542,69 @@ class WorkCenterBarcode(models.Model):
else:
return False
+ def cnc_file_download(self):
+ """
+ 一个下载当前cnc所有nc文件为一个zip包的功能
+ """
+ self.ensure_one()
-class CuttingTimeToolType(models.Model):
- _inherit = 'sf.cutting_tool.type'
- total_cut_time = fields.Char(string='总切削时长')
- predict_life_time = fields.Char(string='预估寿命')
- # 只能看到未被占用的刀位,或者有提示说占没占用
- tool_position = fields.Char(string='选择刀位')
- # cnc_ids = fields.One2many(string='选择机床')
- is_connect_tool_position = fields.Boolean(string='是否已绑定刀位', default=False)
+ # 如果没有附件,直接返回
+ if not self.cnc_ids:
+ return
- def tool_connect_machine(self):
- pass
+ # 处理第一个附件的文件名
+ first_attachment = self.cnc_ids[0].cnc_id
+ file_name = first_attachment.display_name.split('-')[0] + '.zip'
- def tool_unconnect_machine(self):
- pass
+ # 创建一个内存文件和一个zip文件
+ memory_file = BytesIO()
+ with ZipFile(memory_file, 'w') as zipf:
+ # 遍历需要下载的附件
+ for item in self.cnc_ids:
+ a = item.cnc_id
+ datas = base64.standard_b64decode(a.datas)
+
+ # 将nc文件写入zip文件
+ zipf.writestr(a.display_name, datas)
+
+ # 然后可以创建一个ir.attachment对象,将生成的zip文件保存为一个新的附件
+ memory_file.seek(0)
+ output = base64.b64encode(memory_file.read())
+ memory_file.close()
+
+ attachment_data = {
+ 'name': file_name,
+ 'type': 'binary',
+ 'res_model': self._name,
+ 'res_id': self.id,
+ 'datas': output
+ }
+ attachment = self.env['ir.attachment'].create(attachment_data)
+
+ # 返回附件的下载链接
+ download_url = '/web/content/%s?download=true' % attachment.id
+ base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
+ return {
+ 'type': 'ir.actions.act_url',
+ 'url': str(base_url) + download_url,
+ 'target': 'self',
+ }
+
+
+# class CuttingTimeToolType(models.Model):
+# _inherit = 'sf.cutting_tool.type'
+# total_cut_time = fields.Char(string='总切削时长')
+# predict_life_time = fields.Char(string='预估寿命')
+# # 只能看到未被占用的刀位,或者有提示说占没占用
+# tool_position = fields.Char(string='选择刀位')
+# # cnc_ids = fields.One2many(string='选择机床')
+# is_connect_tool_position = fields.Boolean(string='是否已绑定刀位', default=False)
+#
+# def tool_connect_machine(self):
+# pass
+#
+# def tool_unconnect_machine(self):
+# pass
class DeliveryRecord(models.Model):
@@ -579,4 +632,3 @@ class DeliveryRecord(models.Model):
# return super().create(values)
# except:
# raise Exception('b_purchase_order.py:create()')
-
diff --git a/sf_machine_connect/views/compensation.xml b/sf_machine_connect/views/compensation.xml
index a6f47b23..5ec6f382 100644
--- a/sf_machine_connect/views/compensation.xml
+++ b/sf_machine_connect/views/compensation.xml
@@ -5,6 +5,9 @@
mrp.workorder
+
+
+
diff --git a/sf_mrs_connect/models/sync_common.py b/sf_mrs_connect/models/sync_common.py
index 25f6974a..6c2003ff 100644
--- a/sf_mrs_connect/models/sync_common.py
+++ b/sf_mrs_connect/models/sync_common.py
@@ -99,25 +99,33 @@ class sfMaterialModel(models.Model):
if result['status'] == 1:
for item in result['materials_model_yesterday_list']:
if item:
- brand = self.env['sf.materials.model'].search(
+ materials_model = self.env['sf.materials.model'].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.mf_materia_post = item['mf_materia_post'],
- brand.materials_id = self.env['sf.production.materials'].search(
+ if materials_model:
+ materials_model.id = item['id'],
+ materials_model.name = item['name'],
+ materials_model.materials_no = item['materials_no'],
+ materials_model.remark = item['remark'],
+ materials_model.tensile_strength = item['tensile_strength'],
+ materials_model.hardness = item['hardness'],
+ materials_model.materials_no = item['materials_no'],
+ materials_model.rough_machining = item['rough_machining'],
+ materials_model.finish_machining = item['finish_machining'],
+ materials_model.mf_materia_post = item['mf_materia_post'],
+ materials_model.materials_id = self.env['sf.production.materials'].search(
[("materials_no", '=', item['materials_id.materials_no'])]).id,
- brand.need_h = item['need_h'],
- brand.density = item['density']
+ materials_model.need_h = item['need_h'],
+ materials_model.density = item['density']
else:
self.env['sf.materials.model'].create({
"id": item['id'],
"name": item['name'],
"materials_no": item['materials_no'],
"remark": item['remark'],
+ "tensile_strength": item['tensile_strength'],
+ "hardness": item['hardness'],
+ "rough_machining": item['rough_machining'],
+ "finish_machining": item['finish_machining'],
"active": item['active'],
"materials_id": self.env['sf.production.materials'].search(
[("materials_no", '=', item['materials_id.materials_no'])]).id,
@@ -143,14 +151,18 @@ class sfMaterialModel(models.Model):
if result['status'] == 1:
for item in result['materials_model_all_list']:
if item:
- brand = self.env['sf.materials.model'].search(
+ materials_model = self.env['sf.materials.model'].search(
[("materials_no", '=', item['materials_no'])])
- if not brand:
+ if not materials_model:
self.env['sf.materials.model'].create({
"name": item['name'],
"materials_no": item['materials_no'],
"remark": item['remark'],
"active": item['active'],
+ "tensile_strength": item['tensile_strength'],
+ "hardness": item['hardness'],
+ "rough_machining": item['rough_machining'],
+ "finish_machining": item['finish_machining'],
"materials_id": self.env['sf.production.materials'].search(
[("materials_no", '=', item['materials_id.materials_no'])]).id,
"need_h": item['need_h'],
@@ -573,7 +585,6 @@ class MachineBrand(models.Model):
raise ValidationError("认证未通过")
-
class MachineToolType(models.Model):
_inherit = 'sf.machine_tool.type'
_description = '机床型号'
@@ -1492,7 +1503,6 @@ class SyncFixtureModel(models.Model):
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
[('code', '=', item['multi_mounting_type_code'])]).id,
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
- "manufacturer_model_number": item['manufacturer_model_number'],
"clamping_way": item['clamping_way'],
"port_type": item['port_type'],
"model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
@@ -1522,7 +1532,6 @@ class SyncFixtureModel(models.Model):
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
[('code', '=', item['multi_mounting_type_code'])]).id,
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
- "manufacturer_model_number": item['manufacturer_model_number'],
"clamping_way": item['clamping_way'],
"port_type": item['port_type'],
"model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
@@ -1574,7 +1583,6 @@ class SyncFixtureModel(models.Model):
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
[('code', '=', item['multi_mounting_type_code'])]).id,
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
- "manufacturer_model_number": item['manufacturer_model_number'],
"clamping_way": item['clamping_way'],
"port_type": item['port_type'],
"model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
@@ -1604,7 +1612,6 @@ class SyncFixtureModel(models.Model):
"multi_mounting_type_id": self.env['sf.multi_mounting.type'].search(
[('code', '=', item['multi_mounting_type_code'])]).id,
"brand_id": self.env['sf.machine.brand'].search([('code', '=', item['brand_code'])]).id,
- "manufacturer_model_number": item['manufacturer_model_number'],
"clamping_way": item['clamping_way'],
"port_type": item['port_type'],
"model_file": '' if not item['model_file'] else base64.b64decode(item['model_file']),
@@ -2031,8 +2038,7 @@ class SfToolModel(models.Model):
else:
raise ValidationError("认证未通过")
-
- # 同步所有刀具型号列表
+ # 同步所有刀具型号列表
def sync_all_tool_model(self):
sf_sync_config = self.env['res.config.settings'].get_values()
token = sf_sync_config['token']