更新mrs_connect

This commit is contained in:
gqh
2023-01-11 15:04:37 +08:00
parent 8e51654f17
commit 381d6ca9a5
4 changed files with 85 additions and 53 deletions

View File

@@ -20,44 +20,32 @@ class Sf_Mrs_Connect(http.Controller):
""" """
logging.info('get_cnc_processing_create:%s' % kw) logging.info('get_cnc_processing_create:%s' % kw)
try: try:
res = {'status': 1, 'message': '成功'}
datas = request.httprequest.data datas = request.httprequest.data
ret = json.loads(datas) ret = json.loads(datas)
ret = json.loads(ret['result']) ret = json.loads(ret['result'])
for obj in ret: # 查询状态为进行中且类型为获取CNC加工程序的工单
cnc = request.env['sf.cnc.processing'].with_user( cnc_workorder = request.env['mrp.workorder'].with_user(
request.env.ref("base.user_admin")).cnc_processing_create(obj) request.env.ref("base.user_admin")).search([('production_id.name', '=', ret['production_order_no']),
# # 从ftp拉取对应的文件 ('routing_type', '=', '获取CNC加工程序')])
model_code = cnc.workorder_id.product_id.barcode if cnc_workorder:
processing_panel = cnc.workorder_id.processing_panel # 拉取所有加工面的程序文件
logging.info('model_code:%s' % model_code) # i = 1
server_dir = cnc.with_user(request.env.ref("base.user_admin")).download_file_tmp(model_code, for r in ret['processing_panel']:
processing_panel) download_state = request.env['sf.cnc.processing'].with_user(
# cnc_file_path = os.path.join('/', server_dir, cnc.program_name + '.nc') request.env.ref("base.user_admin")).download_file_tmp(
# logging.info('cnc_file_path:%s' % cnc_file_path) ret['folder_name'], r)
# cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc) if download_state == False:
logging.info('server_dir:%s' % server_dir) res['status'] = -2
for root, dirs, files in os.walk(server_dir): res['message'] = '制造订单号为%s的CNC程序文件从FTP拉取失败' % (cnc_workorder.production_id.name)
for f in files: return json.JSONEncoder().encode(res)
logging.info('f:%s' % f) request.env['sf.cnc.processing'].with_user(
logging.info('f[0]:%s' % f.split('.')[0]) request.env.ref("base.user_admin")).cnc_processing_create(cnc_workorder, ret)
if os.path.splitext(f)[1] == ".pdf": return json.JSONEncoder().encode(res)
full_path = os.path.join(server_dir, root, f)
logging.info('pdf:%s' % full_path)
if full_path != False:
if not cnc.workorder_id.cnc_worksheet:
cnc.workorder_id.cnc_worksheet = base64.b64encode(open(full_path, 'rb').read())
else: else:
logging.info('break:%s' % 'break') res = {'status': 0, 'message': '该制造订单暂未开始'}
continue return json.JSONEncoder().encode(res)
else:
logging.info('cnc.program_name:%s' % cnc.program_name)
if cnc.program_name == f.split('.')[0]:
logging.info('f[0]:%s' % f[0])
cnc_file_path = os.path.join(server_dir, root, f)
logging.info('cnc_file_path:%s' % cnc_file_path)
cnc.with_user(request.env.ref("base.user_admin")).write_file(cnc_file_path, cnc)
else:
continue
except Exception as e: except Exception as e:
res = {'status': -1, 'message': '系统解析失败'}
logging.info('get_cnc_processing_create error:%s' % e) logging.info('get_cnc_processing_create error:%s' % e)
return json.JSONEncoder().encode(res)

View File

@@ -15,26 +15,30 @@ class FtpController():
ftp = FTP() ftp = FTP()
def __init__(self, host="192.168.50.202", port=21, username="ftpuser", password="123456"): def __init__(self, host, port, username, password):
try: try:
self.ftp.connect(host, port) self.ftp.connect(host, port)
self.ftp.login(username, password) self.ftp.login(username, password)
logging.info("连接成功: ") logging.info("ftp连接成功")
except: except:
logging.info("连接失败: ") logging.info("ftp连接失败")
# 下载目录下的文件 # 下载目录下的文件
def download_file_tree(self, target_dir, serverdir): def download_file_tree(self, target_dir, serverdir):
if not os.path.exists(serverdir): if not os.path.exists(serverdir):
os.makedirs(serverdir) os.makedirs(serverdir)
try:
logging.info("进入FTP目录 ")
self.ftp.cwd(target_dir) # 切换工作路径 self.ftp.cwd(target_dir) # 切换工作路径
logging.info('FTP目录:%s' % target_dir)
remotenames = self.ftp.nlst() remotenames = self.ftp.nlst()
logging.info('FTP目录文件:%s' % remotenames)
for file in remotenames: for file in remotenames:
server = os.path.join(serverdir, file) server = os.path.join(serverdir, file)
if file.find(".") != -1: if file.find(".") != -1:
self.download_file(server, file) self.download_file(server, file)
else: except:
return return False
# 下载指定目录下的指定文件 # 下载指定目录下的指定文件
def download_file(self, serverfile, remotefile): def download_file(self, serverfile, remotefile):

View File

@@ -14,6 +14,10 @@ class ResConfigSettings(models.TransientModel):
token = fields.Char(string='TOKEN', default='b811ac06-3f00-11ed-9aed-0242ac110003') token = fields.Char(string='TOKEN', default='b811ac06-3f00-11ed-9aed-0242ac110003')
sf_secret_key = fields.Char(string='密钥', default='wBmxej38OkErKhD6') sf_secret_key = fields.Char(string='密钥', default='wBmxej38OkErKhD6')
sf_url = fields.Char(string='访问地址', default='https://sf.cs.jikimo.com') sf_url = fields.Char(string='访问地址', default='https://sf.cs.jikimo.com')
ftp_host = fields.Char(string='FTP的ip')
ftp_port = fields.Char(string='FTP端口')
ftp_user = fields.Char(string='FTP用户')
ftp_password = fields.Char(string='FTP密码')
def sf_all_sync(self): def sf_all_sync(self):
self.env['sf.production.materials'].sync_all_production_materials() self.env['sf.production.materials'].sync_all_production_materials()
@@ -40,8 +44,6 @@ class ResConfigSettings(models.TransientModel):
_logger.info("同步资源库刀具") _logger.info("同步资源库刀具")
# self.env['sf.processing.order'].sync_all_processing_order() # self.env['sf.processing.order'].sync_all_processing_order()
@api.model @api.model
def get_values(self): def get_values(self):
""" """
@@ -53,11 +55,19 @@ class ResConfigSettings(models.TransientModel):
token = config.get_param('token', default='') token = config.get_param('token', default='')
sf_secret_key = config.get_param('sf_secret_key', default='') sf_secret_key = config.get_param('sf_secret_key', default='')
sf_url = config.get_param('sf_url', default='') sf_url = config.get_param('sf_url', default='')
ftp_host = config.get_param('ftp_host', default='')
ftp_port = config.get_param('ftp_port', default='')
ftp_user = config.get_param('ftp_user', default='')
ftp_password = config.get_param('ftp_password', default='')
values.update( values.update(
token=token, token=token,
sf_secret_key=sf_secret_key, sf_secret_key=sf_secret_key,
sf_url=sf_url, sf_url=sf_url,
ftp_host=ftp_host,
ftp_port=ftp_port,
ftp_user=ftp_user,
ftp_password=ftp_password
) )
return values return values
@@ -67,4 +77,7 @@ class ResConfigSettings(models.TransientModel):
ir_config.set_param("token", self.token or "") ir_config.set_param("token", self.token or "")
ir_config.set_param("sf_secret_key", self.sf_secret_key or "") ir_config.set_param("sf_secret_key", self.sf_secret_key or "")
ir_config.set_param("sf_url", self.sf_url or "") ir_config.set_param("sf_url", self.sf_url or "")
ir_config.set_param("ftp_host", self.ftp_host or "")
ir_config.set_param("ftp_port", self.ftp_port or "")
ir_config.set_param("ftp_user", self.ftp_user or "")
ir_config.set_param("ftp_password", self.ftp_password or "")

View File

@@ -14,25 +14,52 @@
<div class="o_setting_left_pane"/> <div class="o_setting_left_pane"/>
<div class="o_setting_right_pane"> <div class="o_setting_right_pane">
<div class="text-muted"> <div class="text-muted">
<label for="token"/> <label for="sf_url"/>
<field name="sf_url"/>
</div>
<div class="text-muted">
<label for="token" string="Token"/>
<field name="token"/> <field name="token"/>
</div> </div>
<div class="text-muted"> <div class="text-muted">
<label for="sf_secret_key"/> <label for="sf_secret_key"/>
<field name="sf_secret_key"/> <field name="sf_secret_key"/>
</div>
<div class="text-muted">
<label for="sf_url"/>
<field name="sf_url"/>
</div>
</div>
</div> </div>
<div class="col-12 col-lg-6 o_setting_box"> <div class="col-12 col-lg-6 o_setting_box">
<button type="object" class="oe_highlight" name="sf_all_sync" string="同步资源库所有基础数据" <button type="object" class="oe_highlight" name="sf_all_sync"
string="同步资源库基础数据"
/> />
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
<div>
<h2>FTP参数配置</h2>
<div class="row mt16 o_settings_container" id="pay_api">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane"/>
<div class="o_setting_right_pane">
<div class="text-muted">
<label for="ftp_host" string="访问地址"/>
<field name="ftp_host"/>
</div>
<div class="text-muted">
<label for="ftp_port" string="端口"/>
<field name="ftp_port"/>
</div>
<div class="text-muted">
<label for="ftp_user" string="用户"/>
<field name="ftp_user"/>
</div>
<div class="text-muted">
<label for="ftp_password" string="密码"/>
<field name="ftp_password" password="True"/>
</div>
</div>
</div>
</div>
</div>
</xpath> </xpath>
</field> </field>
</record> </record>