From 642007d29b25d077b483584961ba2883f26845cd Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Mon, 21 Aug 2023 17:20:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?cnc=E5=B7=A5=E5=8D=95=E5=A4=84=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0NC=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B7=B2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/__manifest__.py | 5 +- sf_machine_connect/models/ftp_client.py | 78 +++++++++++++++++++---- sf_machine_connect/views/compensation.xml | 3 + 3 files changed, 70 insertions(+), 16 deletions(-) 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 + + + From e781bce27e1d4dc43195f9e6e5813eb8f4ac1ea6 Mon Sep 17 00:00:00 2001 From: yuxianghui <1608204036@qq.com> Date: Tue, 22 Aug 2023 11:40:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E4=BA=A7=E7=BA=BF=E8=AE=BE=E5=A4=87=E8=B5=84=E6=BA=90=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=92=8C=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=8E=86=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=95=8C=E9=9D=A2=E5=B8=83=E5=B1=80=EF=BC=9B=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=8E=86=E3=80=81=E7=8F=AD?= =?UTF-8?q?=E6=AC=A1=E3=80=81=E4=BC=91=E6=81=AF=E6=97=A5=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E7=9A=84form=E8=A7=86=E5=9B=BE=EF=BC=8C=E6=96=B0=E5=A2=9Etree?= =?UTF-8?q?=E8=A7=86=E5=9B=BE=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD=EF=BC=9B?= =?UTF-8?q?2=E3=80=81=E4=BF=AE=E5=A4=8D=E4=BA=A7=E7=BA=BF=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=B5=84=E6=BA=90=E8=AE=BE=E7=BD=AE=E7=9A=84=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=BA=86=E6=9C=BA=E5=8F=B0=E5=8F=B7?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=8D=E7=A7=B0=EF=BC=9B3=E3=80=81?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=8E=86=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E7=8F=AD=E6=AC=A1=E5=AD=97=E6=AE=B5=E5=BF=85=E5=A1=AB?= =?UTF-8?q?=EF=BC=9B4=E3=80=81=E8=B0=83=E6=95=B4=E4=BA=A7=E7=BA=BF?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E8=B5=84=E6=BA=90=E8=AE=BE=E7=BD=AE=E5=92=8C?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=97=A5=E5=8E=86=E8=AE=BE=E7=BD=AE=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_plan_management/models/base.py | 8 +- sf_plan_management/models/calendar_base.py | 4 +- sf_plan_management/views/menu_view.xml | 14 +- sf_plan_management/views/plan_base_view.xml | 216 ++++++++++---------- 4 files changed, 121 insertions(+), 121 deletions(-) diff --git a/sf_plan_management/models/base.py b/sf_plan_management/models/base.py index 801c5eb4..097401ad 100644 --- a/sf_plan_management/models/base.py +++ b/sf_plan_management/models/base.py @@ -8,7 +8,7 @@ class ProcedureEquipmentResourceSetting(models.Model): name = fields.Many2one('sf.production.line', string='生产线', required=True) work_center_name_id = fields.Many2one('mrp.workcenter', string='工作中心名称') - equipment_code = fields.Char(string='机台号(原设备编码)', readonly=True, compute='_onchange_equipment_name_id') + equipment_code = fields.Char(string='机台号', readonly=True, compute='_onchange_equipment_name_id') equipment_name_id = fields.Many2one('maintenance.equipment', string='设备名称', readonly=True, @@ -41,9 +41,9 @@ class ProcedureEquipmentResourceSetting(models.Model): @api.onchange('equipment_name_id') def _onchange_equipment_name_id(self): for record in self: - record.equipment_code = record.equipment_name_id.code, - record.brand = record.equipment_name_id.brand_id.name, - record.model = record.equipment_name_id.type_id.name, + record.equipment_code = record.equipment_name_id.code + record.brand = record.equipment_name_id.brand_id.name + record.model = record.equipment_name_id.type_id.name record.status = record.equipment_name_id.state @api.depends('working_calendar_id') diff --git a/sf_plan_management/models/calendar_base.py b/sf_plan_management/models/calendar_base.py index 5b86e6dd..b783f8b7 100644 --- a/sf_plan_management/models/calendar_base.py +++ b/sf_plan_management/models/calendar_base.py @@ -26,14 +26,14 @@ class WorkLogSetting(models.Model): code = fields.Char(string='序号', default=_get_code) name = fields.Char(string='工作日历名称', required=True, size=15, length=30) - working_shift_ids = fields.Many2many('sf.working.shift', string='班次') + working_shift_ids = fields.Many2many('sf.working.shift', string='班次', required=True) start_time = fields.Datetime(string='日开始时间', readonly=True, compute='_compute_working_shift_ids') end_time = fields.Datetime(string='日结束时间', readonly=True, compute='_compute_working_shift_ids') duration = fields.Char(string='时长', readonly=True, compute='_compute_working_shift_ids') day_off_ids = fields.Many2many('sf.day.off', string='休息日', required=True) - status = fields.Boolean(string='状态', default=True) + status = fields.Selection([('正常', '正常'), ('禁用', '禁用')], string='状态', default='正常') update_person = fields.Char(string='更新人', default=lambda self: self.env.user.name) update_time = fields.Datetime(string='更新时间', default=lambda self: fields.Datetime.now()) diff --git a/sf_plan_management/views/menu_view.xml b/sf_plan_management/views/menu_view.xml index d0c7dc87..6817e30c 100644 --- a/sf_plan_management/views/menu_view.xml +++ b/sf_plan_management/views/menu_view.xml @@ -7,20 +7,20 @@ sequence="599" /> - - + + 工作日历设置 sf.work.log.setting - + - - - + + + @@ -30,38 +30,39 @@ sf.work.log.setting + + + + - - + + - - - - - - - - - - - - - - - - + + - - + + + + + + + - - - - + + + + + + @@ -79,7 +80,7 @@ 休息日 sf.day.off - + @@ -88,7 +89,7 @@ 休息日 sf.day.off - tree,form + tree @@ -97,7 +98,7 @@ 班次 sf.working.shift - + @@ -107,32 +108,32 @@ - - 班次 - sf.working.shift - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + 班次 sf.working.shift - tree,form + tree @@ -141,34 +142,35 @@ 工作日历 sf.work.schedule.calendar - - + + + - - 工作日历 - sf.work.schedule.calendar - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + 工作日历 @@ -196,7 +198,7 @@ 工作日历 sf.work.schedule.calendar - calendar,search,tree,form + calendar,search,tree @@ -207,15 +209,15 @@ - - - + + + - - - - + + + + @@ -229,41 +231,39 @@ - - + + - - - + + + - - - - - - - ` - - - - - - - - - - - - + + + + + ` + + + + + + + + + + + +