mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-25 18:08:42 -06:00
Export working and new menu
This commit is contained in:
parent
193465c4ea
commit
2f87d70158
@ -2,8 +2,8 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Module for OpenERP
|
||||
# Copyright (C) 2014 Akretion (http://www.akretion.com).
|
||||
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com).
|
||||
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# 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',
|
||||
'author': 'Akretion',
|
||||
'website': 'www.akretion.com',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Generic Modules',
|
||||
'description': """
|
||||
|
||||
File exchange system with multiple protocol (SFTP, FTP, Filestore)
|
||||
""",
|
||||
'depends': [
|
||||
'base',
|
||||
],
|
||||
'data': [
|
||||
'attachment_view.xml',
|
||||
'menu.xml',
|
||||
'location_view.xml',
|
||||
'task_view.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': True,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,24 +1,24 @@
|
||||
# -*- 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
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
|
||||
def itersubclasses(cls, _seen=None):
|
||||
"""
|
||||
itersubclasses(cls)
|
||||
|
@ -2,8 +2,8 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Module for OpenERP
|
||||
# Copyright (C) 2014 Akretion (http://www.akretion.com).
|
||||
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
||||
# Copyright (C) 2015 Akretion (http://www.akretion.com).
|
||||
# @author Valentin CHEMIERE <valentin.chemiere@akretion.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
|
@ -44,7 +44,7 @@
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_ir_location"
|
||||
parent="base.next_id_9"
|
||||
parent="menu_file_exchange"
|
||||
sequence="20"
|
||||
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()
|
||||
filepath = fields.Char()
|
||||
location_id = fields.Many2one('external.file.location', string='Location')
|
||||
attachment_id = fields.Many2one('ir.attachment', string='Attachment')
|
||||
|
||||
def _get_method(self):
|
||||
res = []
|
||||
@ -57,8 +58,8 @@ class Task(models.Model):
|
||||
'port': self.location_id.port,
|
||||
'allow_dir_creation': False,
|
||||
'file_name': self.filename,
|
||||
'path': self.filepath
|
||||
'path': self.filepath,
|
||||
'attachment_id': self.attachment_id,
|
||||
}
|
||||
conn = method_class(self.env, config)
|
||||
file_id = conn.run()
|
||||
|
||||
conn.run()
|
||||
|
@ -13,6 +13,7 @@
|
||||
<field name="location_id" colspan="4"/>
|
||||
<field name="filename" colspan="4"/>
|
||||
<field name="filepath" colspan="4"/>
|
||||
<field name="attachment_id" colspan="4"/>
|
||||
<button name="run" type="object" string="Run"/>
|
||||
</group>
|
||||
</sheet>
|
||||
@ -41,7 +42,7 @@
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_ir_location_task"
|
||||
parent="base.next_id_9"
|
||||
parent="menu_file_exchange"
|
||||
sequence="20"
|
||||
action="action_task"/>
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
##############################################################################
|
||||
#
|
||||
# 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
|
||||
# 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.move_path = config.get('move_path', '')
|
||||
self.delete_file = config.get('delete_file', False)
|
||||
self.attachment_id = config.get('attachment_id', False)
|
||||
|
||||
|
||||
class FtpImportTask(FtpTask):
|
||||
@ -133,19 +135,15 @@ class FtpExportTask(FtpTask):
|
||||
with ftp_conn.open(target_name, mode='wb') as fileobj:
|
||||
fileobj.write(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):
|
||||
return upload_directory + '/' + filename
|
||||
|
||||
def _upload_file(self, config, filename, filedata):
|
||||
ftp_config = config['ftp']
|
||||
upload_directory = ftp_config.get('upload_directory', '')
|
||||
port_session_factory = ftputil.session.session_factory(
|
||||
port=int(ftp_config.get('port', 21))
|
||||
)
|
||||
with ftputil.FTPHost(ftp_config['host'], ftp_config['user'],
|
||||
ftp_config['password'],
|
||||
def _upload_file(self, host, port, user, pwd, path, filename, filedata):
|
||||
upload_directory = path
|
||||
port_session_factory = ftputil.session.session_factory(port=port)
|
||||
with ftputil.FTPHost(host, user, pwd,
|
||||
session_factory=port_session_factory) as ftp_conn:
|
||||
target_name = self._target_name(ftp_conn,
|
||||
upload_directory,
|
||||
@ -155,10 +153,7 @@ class FtpExportTask(FtpTask):
|
||||
else:
|
||||
self._handle_new_target(ftp_conn, target_name, filedata)
|
||||
|
||||
def run(self, config=None, file_id=None, async=True):
|
||||
#TODO change when object was made
|
||||
f = self.env.get('impexp.file') \
|
||||
.browse(self.env.cr, self.env.uid, file_id)
|
||||
self._upload_file(config, f.attachment_id.datas_fname,
|
||||
b64decode(f.attachment_id.datas))
|
||||
|
||||
def run(self, async=True):
|
||||
self._upload_file(self.host, self.port, self.user, self.pwd, self.path,
|
||||
self.attachment_id.datas_fname,
|
||||
b64decode(self.attachment_id.datas))
|
||||
|
Loading…
Reference in New Issue
Block a user