文件写入cnc关联的attach里面

This commit is contained in:
jinling.yang
2022-11-30 17:19:46 +08:00
parent 8fce929022
commit 1bf8e8a268
3 changed files with 31 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ import os
import json
import requests
import logging
import base64
from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, SUPERUSER_ID, _
@@ -321,6 +322,8 @@ class CNCprocessing(models.Model):
workorder = self.env['mrp.workorder'].search([('production_id.name', '=', obj['manufacturing_order_no']),
('processing_panel', '=', obj['processing_panel']),
('routing_type', '=', 'CNC加工')])
logging.info('workorder:%s' % workorder)
logging.info('production_id.name:%s' % workorder.production_id.name)
vals = {
'workorder_id': workorder.id,
'sequence_number': obj['sequence_number'],
@@ -340,7 +343,7 @@ class CNCprocessing(models.Model):
def attachment_create(self, name, data):
attachment = self.env['ir.attachment'].create({
'datas': data,
'datas': base64.b64encode(data),
'type': 'binary',
'description': '程序文件',
'name': name
@@ -352,3 +355,14 @@ class CNCprocessing(models.Model):
serverdir = os.path.join('/tmp', model_code, 'return', processing_panel)
ftp = FtpController()
ftp.download_file_tree(remotepath, serverdir)
return serverdir
def write_file(self, nc_file_path, cnc):
if os.path.exists(nc_file_path):
with open(nc_file_path, 'rb') as file:
data_bytes = file.read()
attachment = self.attachment_create(cnc.program_name + '.NC', data_bytes)
cnc.write({'cnc_id': attachment.id})
file.close()
else:
return False