8000 Add file import/export by Viggor · Pull Request #1 · initOS/connector-interfaces · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add file import/export #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: 8.0-connector_flow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions connector_flow/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'website': 'http://www.initos.com',
'depends': [
'connector',
'external_file_location',
],
'external_dependencies': {
'python': ['ftputil'],
Expand Down
3 changes: 2 additions & 1 deletion connector_flow/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions connector_flow/impexp_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 {}
Expand Down
1 change: 1 addition & 0 deletions connector_flow/impexp_task_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<group>
<field name="name"/>
<field name="task"/>
<field name="file_task_id"/>
<field name="max_retries"/>
<field name="flow_id"/>
<field name="flow_start"/>
Expand Down
3 changes: 1 addition & 2 deletions connector_flow/task/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@

from . import csv_export
from . import csv_import
from . import ftp_upload
from . import ftp_download
from . import file_transfert
2 changes: 1 addition & 1 deletion connector_flow/task/abstract_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
72 changes: 72 additions & 0 deletions connector_flow/task/file_transfert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# Module for OpenERP
# 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
# 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 <http://www.gnu.org/licenses/>.
#
###############################################################################

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
2 changes: 1 addition & 1 deletion connector_flow_example_ftp/data/task_flow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<record model="impexp.task" id="task_partner_to_ftp_3">
<field name="name">res.partner to FTP, part 3 (CSV to FTP)</field>
<field name="task">ftp_upload</field>
<field name="task">file_export</field>
<field name="flow_id" ref="task_partner_to_ftp_flow"/>
</record>

Expand Down
0