mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-26 10:28:40 -06:00
Export working and new menu
This commit is contained in:
parent
193465c4ea
commit
2f87d70158
@ -2,8 +2,8 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Module for OpenERP
|
# Module for OpenERP
|
||||||
# Copyright (C) 2014 Akretion (http://www.akretion.com).
|
# Copyright (C) 2015 Akretion (http://www.akretion.com).
|
||||||
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
@ -20,27 +20,25 @@
|
|||||||
#
|
#
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
{'name': 'external_file_location',
|
{
|
||||||
|
'name': 'external_file_location',
|
||||||
'version': '0.0.1',
|
'version': '0.0.1',
|
||||||
'author': 'Akretion',
|
'author': 'Akretion',
|
||||||
'website': 'www.akretion.com',
|
'website': 'www.akretion.com',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'category': 'Generic Modules',
|
'category': 'Generic Modules',
|
||||||
'description': """
|
'description': """
|
||||||
|
File exchange system with multiple protocol (SFTP, FTP, Filestore)
|
||||||
""",
|
""",
|
||||||
'depends': [
|
'depends': [
|
||||||
'base',
|
'base',
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
'attachment_view.xml',
|
'attachment_view.xml',
|
||||||
|
'menu.xml',
|
||||||
'location_view.xml',
|
'location_view.xml',
|
||||||
'task_view.xml',
|
'task_view.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'application': True,
|
'application': True,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
|
# Author: Joel Grand-Guillaume
|
||||||
|
# Copyright 2011-2012 Camptocamp SA
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
@ -18,7 +19,6 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
|
||||||
def itersubclasses(cls, _seen=None):
|
def itersubclasses(cls, _seen=None):
|
||||||
"""
|
"""
|
||||||
itersubclasses(cls)
|
itersubclasses(cls)
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
#
|
#
|
||||||
# Module for OpenERP
|
# Module for OpenERP
|
||||||
# Copyright (C) 2014 Akretion (http://www.akretion.com).
|
# Copyright (C) 2015 Akretion (http://www.akretion.com).
|
||||||
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem id="menu_ir_location"
|
<menuitem id="menu_ir_location"
|
||||||
parent="base.next_id_9"
|
parent="menu_file_exchange"
|
||||||
sequence="20"
|
sequence="20"
|
||||||
action="action_location"/>
|
action="action_location"/>
|
||||||
|
|
||||||
|
12
external_file_location/menu.xml
Normal file
12
external_file_location/menu.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<menuitem id="menu_file_exchange"
|
||||||
|
parent="base.menu_administration"
|
||||||
|
sequence="20"
|
||||||
|
name="File exchange"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
@ -34,6 +34,7 @@ class Task(models.Model):
|
|||||||
filename = fields.Char()
|
filename = fields.Char()
|
||||||
filepath = fields.Char()
|
filepath = fields.Char()
|
||||||
location_id = fields.Many2one('external.file.location', string='Location')
|
location_id = fields.Many2one('external.file.location', string='Location')
|
||||||
|
attachment_id = fields.Many2one('ir.attachment', string='Attachment')
|
||||||
|
|
||||||
def _get_method(self):
|
def _get_method(self):
|
||||||
res = []
|
res = []
|
||||||
@ -57,8 +58,8 @@ class Task(models.Model):
|
|||||||
'port': self.location_id.port,
|
'port': self.location_id.port,
|
||||||
'allow_dir_creation': False,
|
'allow_dir_creation': False,
|
||||||
'file_name': self.filename,
|
'file_name': self.filename,
|
||||||
'path': self.filepath
|
'path': self.filepath,
|
||||||
|
'attachment_id': self.attachment_id,
|
||||||
}
|
}
|
||||||
conn = method_class(self.env, config)
|
conn = method_class(self.env, config)
|
||||||
file_id = conn.run()
|
conn.run()
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
<field name="location_id" colspan="4"/>
|
<field name="location_id" colspan="4"/>
|
||||||
<field name="filename" colspan="4"/>
|
<field name="filename" colspan="4"/>
|
||||||
<field name="filepath" colspan="4"/>
|
<field name="filepath" colspan="4"/>
|
||||||
|
<field name="attachment_id" colspan="4"/>
|
||||||
<button name="run" type="object" string="Run"/>
|
<button name="run" type="object" string="Run"/>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
@ -41,7 +42,7 @@
|
|||||||
</record>
|
</record>
|
||||||
|
|
||||||
<menuitem id="menu_ir_location_task"
|
<menuitem id="menu_ir_location_task"
|
||||||
parent="base.next_id_9"
|
parent="menu_file_exchange"
|
||||||
sequence="20"
|
sequence="20"
|
||||||
action="action_task"/>
|
action="action_task"/>
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
|
# Copyright (C) 2014 initOS GmbH & Co. KG (<http://www.initos.com>).
|
||||||
|
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
@ -43,6 +44,7 @@ class FtpTask(AbstractTask):
|
|||||||
self.path = config.get('path', '')
|
self.path = config.get('path', '')
|
||||||
self.move_path = config.get('move_path', '')
|
self.move_path = config.get('move_path', '')
|
||||||
self.delete_file = config.get('delete_file', False)
|
self.delete_file = config.get('delete_file', False)
|
||||||
|
self.attachment_id = config.get('attachment_id', False)
|
||||||
|
|
||||||
|
|
||||||
class FtpImportTask(FtpTask):
|
class FtpImportTask(FtpTask):
|
||||||
@ -133,19 +135,15 @@ class FtpExportTask(FtpTask):
|
|||||||
with ftp_conn.open(target_name, mode='wb') as fileobj:
|
with ftp_conn.open(target_name, mode='wb') as fileobj:
|
||||||
fileobj.write(filedata)
|
fileobj.write(filedata)
|
||||||
_logger.info('wrote %s, size %d', target_name, len(filedata))
|
_logger.info('wrote %s, size %d', target_name, len(filedata))
|
||||||
return file_id
|
# return file_id
|
||||||
|
|
||||||
def _target_name(self, ftp_conn, upload_directory, filename):
|
def _target_name(self, ftp_conn, upload_directory, filename):
|
||||||
return upload_directory + '/' + filename
|
return upload_directory + '/' + filename
|
||||||
|
|
||||||
def _upload_file(self, config, filename, filedata):
|
def _upload_file(self, host, port, user, pwd, path, filename, filedata):
|
||||||
ftp_config = config['ftp']
|
upload_directory = path
|
||||||
upload_directory = ftp_config.get('upload_directory', '')
|
port_session_factory = ftputil.session.session_factory(port=port)
|
||||||
port_session_factory = ftputil.session.session_factory(
|
with ftputil.FTPHost(host, user, pwd,
|
||||||
port=int(ftp_config.get('port', 21))
|
|
||||||
)
|
|
||||||
with ftputil.FTPHost(ftp_config['host'], ftp_config['user'],
|
|
||||||
ftp_config['password'],
|
|
||||||
session_factory=port_session_factory) as ftp_conn:
|
session_factory=port_session_factory) as ftp_conn:
|
||||||
target_name = self._target_name(ftp_conn,
|
target_name = self._target_name(ftp_conn,
|
||||||
upload_directory,
|
upload_directory,
|
||||||
@ -155,10 +153,7 @@ class FtpExportTask(FtpTask):
|
|||||||
else:
|
else:
|
||||||
self._handle_new_target(ftp_conn, target_name, filedata)
|
self._handle_new_target(ftp_conn, target_name, filedata)
|
||||||
|
|
||||||
def run(self, config=None, file_id=None, async=True):
|
def run(self, async=True):
|
||||||
#TODO change when object was made
|
self._upload_file(self.host, self.port, self.user, self.pwd, self.path,
|
||||||
f = self.env.get('impexp.file') \
|
self.attachment_id.datas_fname,
|
||||||
.browse(self.env.cr, self.env.uid, file_id)
|
b64decode(self.attachment_id.datas))
|
||||||
self._upload_file(config, f.attachment_id.datas_fname,
|
|
||||||
b64decode(f.attachment_id.datas))
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user