diff --git a/connector_flow/__openerp__.py b/connector_flow/__openerp__.py index d9976dd31..a93e18000 100644 --- a/connector_flow/__openerp__.py +++ b/connector_flow/__openerp__.py @@ -28,6 +28,7 @@ 'website': 'http://www.initos.com', 'depends': [ 'connector', + 'external_file_location', ], 'external_dependencies': { 'python': ['ftputil'], diff --git a/connector_flow/file.py b/connector_flow/file.py index 31d34660b..e41ea587e 100644 --- a/connector_flow/file.py +++ b/connector_flow/file.py @@ -25,13 +25,14 @@ class ImpExpFile(models.Model): _name = 'impexp.file' _description = 'Wrapper for a file to be imported/exported' + # states is already managed in attachment metadata, should be deleted here? @api.model def _states(self): return [('new', 'New'), ('failed', 'Failed'), ('done', 'Done')] - attachment_id = fields.Many2one('ir.attachment', string='Attachment', + attachment_id = fields.Many2one('ir.attachment.metadata', string='Attachment', required=True) task_id = fields.Many2one('impexp.task', string='Task') state = fields.Selection(string='State', selection='_states', diff --git a/connector_flow/impexp_task.py b/connector_flow/impexp_task.py index 9f3132e95..7b734b801 100644 --- a/connector_flow/impexp_task.py +++ b/connector_flow/impexp_task.py @@ -79,6 +79,7 @@ def _get_available_tasks(self): 'task_to_id', string='Incoming Transitions') flow_start = fields.Boolean(string='Start of a Task Flow') + file_task_id = fields.Many2one('external.file.task') @api.one @api.constrains('flow_start', 'flow_id') @@ -99,6 +100,8 @@ def _config(self): """Parse task configuration""" self.ensure_one() config = self.config + if self.file_task_id: + return self.file_task_id if config: return literal_eval(config) return {} diff --git a/connector_flow/impexp_task_view.xml b/connector_flow/impexp_task_view.xml index 0a1c0527c..99242fc56 100644 --- a/connector_flow/impexp_task_view.xml +++ b/connector_flow/impexp_task_view.xml @@ -25,6 +25,7 @@ + diff --git a/connector_flow/task/__init__.py b/connector_flow/task/__init__.py index 32d4130a5..42c9e7ace 100644 --- a/connector_flow/task/__init__.py +++ b/connector_flow/task/__init__.py @@ -20,5 +20,4 @@ from . import csv_export from . import csv_import -from . import ftp_upload -from . import ftp_download +from . import file_transfert diff --git a/connector_flow/task/abstract_task.py b/connector_flow/task/abstract_task.py index 0fae0cf10..dccb89717 100644 --- a/connector_flow/task/abstract_task.py +++ b/connector_flow/task/abstract_task.py @@ -52,7 +52,7 @@ def run_successor_tasks(self, **kwargs): return retval def create_file(self, filename, data): - ir_attachment = self.session.env['ir.attachment'].\ + ir_attachment = self.session.env['ir.attachment.metadata'].\ create({'name': filename, 'datas': b64encode(data), 'datas_fname': filename}) diff --git a/connector_flow/task/file_transfert.py b/connector_flow/task/file_transfert.py new file mode 100644 index 000000000..25e9816bc --- /dev/null +++ b/connector_flow/task/file_transfert.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# Module for OpenERP +# Copyright (C) 2015 Akretion (http://www.akretion.com). +# @author Valentin CHEMIERE +# +# 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. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################### + +from openerp import api, models, fields + +from .abstract_task import AbstractTask +import logging +_logger = logging.getLogger(__name__) + + +class FileImport(AbstractTask): + + def run(self, config=None, async=True): + att_ids = self.session.env['external.file.task'].browse(config['file_task_id']).run() + impexp_file = self.session.env['impexp.file'].\ + create({'attachment_id': ir_attachment.id, + 'task_id': self._id, + 'state': 'done'}) + return impexp_file.id + + +class FileExport(AbstractTask): + + def run(self, config=None, file_id=None, async=True): + task = self.session.env['external.file.task'].browse(config.id) + file = self.session.env['impexp.file'].browse(file_id) + file.attachment_id.write({'task_id': task.id}) + task.run() + +class FileExportTask(models.Model): + _inherit = 'impexp.task' + + @api.model + def _get_available_tasks(self): + return super(FileExportTask, self)._get_available_tasks() + [ + ('file_export', 'File Export') + ] + + def file_export_class(self): + return FileExport + + +class FileImportTask(models.Model): + _inherit = 'impexp.task' + + @api.model + def _get_available_tasks(self): + return super(FileImportTask, self)._get_available_tasks() + [ + ('file_import', 'File Import') + ] + + def file_import_class(self): + return FileImport diff --git a/connector_flow_example_ftp/data/task_flow.xml b/connector_flow_example_ftp/data/task_flow.xml index 0d9a0be73..24e6aa541 100644 --- a/connector_flow_example_ftp/data/task_flow.xml +++ b/connector_flow_example_ftp/data/task_flow.xml @@ -30,7 +30,7 @@ res.partner to FTP, part 3 (CSV to FTP) - ftp_upload + file_export