From 1cfaf44b25abe5489dc5e78dbcf970e4fd8336f9 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Fri, 13 Mar 2015 18:56:42 +0100 Subject: [PATCH] Reworking of some methods and views --- external_file_location/README.rst | 60 +++++++++++++++++ external_file_location/__openerp__.py | 9 +-- external_file_location/attachment.py | 4 +- external_file_location/helper.py | 1 - external_file_location/location.py | 18 +++-- external_file_location/location_view.xml | 6 +- external_file_location/task.py | 32 +++++---- external_file_location/task_view.xml | 33 +++------- external_file_location/tasks/ftp.py | 84 +++++++++++++----------- ir_attachment_metadata/README.rst | 51 ++++++++++++++ ir_attachment_metadata/attachment.py | 2 + 11 files changed, 211 insertions(+), 89 deletions(-) create mode 100644 external_file_location/README.rst create mode 100644 ir_attachment_metadata/README.rst diff --git a/external_file_location/README.rst b/external_file_location/README.rst new file mode 100644 index 00000000..38fbe2e0 --- /dev/null +++ b/external_file_location/README.rst @@ -0,0 +1,60 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg +:alt: License + +External File Location +====================== + +This module was written to extend the functionality of ir.attachment to support remote communication and allow you to import/export file to a remote server + +Installation +============ + +To install this module, you need to: + +* FTPUtil python module + +Usage +===== + +To use this module, you need to: + +* Add a location with your server infos +* Create a task with your file info and remote communication method +* A cron task will trigger each task + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +* add SFTP protocol +* add FILESTORE protocol + +Credits +======= + +* Joel Grand-Guillaume Camptocamp +* initOS +* Valentin CHEMIERE + +Contributors +------------ + +* Sebastien BEAU + +Maintainer +---------- + +* Valentin CHEMIERE + +.. image:: http://odoo-community.org/logo.png +:alt: Odoo Community Association +:target: http://odoo-community.org + + This module is maintained by the OCA. + + OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + + To contribute to this module, please visit http://odoo-community.org. diff --git a/external_file_location/__openerp__.py b/external_file_location/__openerp__.py index c45965a7..85177bf5 100644 --- a/external_file_location/__openerp__.py +++ b/external_file_location/__openerp__.py @@ -27,13 +27,14 @@ 'website': 'www.akretion.com', 'license': 'AGPL-3', 'category': 'Generic Modules', - 'description': """ - File exchange system with multiple protocol (SFTP, FTP, Filestore) - """, 'depends': [ - 'base', 'ir_attachment_metadata', ], + 'external_dependencies': { + 'python': [ + 'ftputil', + ], + }, 'data': [ 'menu.xml', 'attachment_view.xml', diff --git a/external_file_location/attachment.py b/external_file_location/attachment.py index 410da1db..63d18b49 100644 --- a/external_file_location/attachment.py +++ b/external_file_location/attachment.py @@ -2,8 +2,8 @@ ############################################################################### # # Module for OpenERP -# Copyright (C) 2014 Akretion (http://www.akretion.com). -# @author Sébastien BEAU +# 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 diff --git a/external_file_location/helper.py b/external_file_location/helper.py index 3e0b93a6..f46e5f0d 100644 --- a/external_file_location/helper.py +++ b/external_file_location/helper.py @@ -41,7 +41,6 @@ def itersubclasses(cls, _seen=None): >>> [cls.__name__ for cls in itersubclasses(object)] #doctest: +ELLIPSIS ['type', ...'tuple', ...] """ - #import pdb; pdb.set_trace() if not isinstance(cls, type): raise TypeError('itersubclasses must be called with ' 'new-style classes, not %.100r' % cls diff --git a/external_file_location/location.py b/external_file_location/location.py index 1a625956..81cbecbc 100644 --- a/external_file_location/location.py +++ b/external_file_location/location.py @@ -20,7 +20,7 @@ # ############################################################################### -from openerp import models, fields +from openerp import models, fields, api from .abstract_task import AbstractTask from .helper import itersubclasses @@ -28,11 +28,11 @@ class Location(models.Model): _name = 'external.file.location' _description = 'Description' - name = fields.Char(string='Name') - protocol = fields.Selection(selection='_get_protocol') - address = fields.Char(string='Address') - port = fields.Integer() - login = fields.Char() + name = fields.Char(string='Name', required=True) + protocol = fields.Selection(selection='_get_protocol', required=True) + address = fields.Char(string='Address', required=True) + port = fields.Integer(required=True) + login = fields.Char(required=True) password = fields.Char() task_ids = fields.One2many('external.file.task', 'location_id') @@ -45,3 +45,9 @@ class Location(models.Model): res.append(cls_info) return res + @api.onchange('protocol') + def get_default_port(self): + for cls in itersubclasses(AbstractTask): + if cls._key == self.protocol: + self.port = cls._default_port + diff --git a/external_file_location/location_view.xml b/external_file_location/location_view.xml index da11c6d6..db5815d8 100644 --- a/external_file_location/location_view.xml +++ b/external_file_location/location_view.xml @@ -9,7 +9,7 @@
-
@@ -20,8 +20,9 @@ - + + @@ -62,3 +63,4 @@ + diff --git a/external_file_location/task.py b/external_file_location/task.py index 154e098a..cca65cd4 100644 --- a/external_file_location/task.py +++ b/external_file_location/task.py @@ -29,17 +29,25 @@ class Task(models.Model): _name = 'external.file.task' _description = 'Description' - name = fields.Char() - method = fields.Selection(selection='_get_method') + name = fields.Char(required=True) + method = fields.Selection(selection='_get_method', required=True, + help='procotol and trasmitting info') method_type = fields.Char() - filename = fields.Char() - filepath = fields.Char() - location_id = fields.Many2one('external.file.location', string='Location') + filename = fields.Char(help='File name which is imported') + filepath = fields.Char(help='Path to imported file') + location_id = fields.Many2one('external.file.location', string='Location', + required=True) attachment_ids = fields.One2many('ir.attachment', 'task_id', string='Attachment') - delete_file = fields.Boolean(string='Delete file') - move_file = fields.Boolean(string='Move file') - move_path = fields.Char(string='Move path') + move_path = fields.Char(string='Move path', + help='Imported File will be moved to this path') + md5_check = fields.Boolean(help='Control file integrity after import with' + ' a md5 file') + after_import = fields.Selection(selection='_get_action', + help='Action after import a file') + + def _get_action(self): + return [('move', 'Move'), ('delete', 'Delete')] def _get_method(self): res = [] @@ -51,7 +59,7 @@ class Task(models.Model): return res @api.onchange('method') - def onchage_method(self): + def onchange_method(self): if self.method: if 'import' in self.method: self.method_type = 'import' @@ -70,7 +78,7 @@ class Task(models.Model): for cls in itersubclasses(AbstractTask): if cls._synchronize_type and \ cls._key + '_' + cls._synchronize_type == self.method: - method_class = cls + method_class = cls config = { 'host': self.location_id.address, 'user': self.location_id.login, @@ -82,8 +90,8 @@ class Task(models.Model): 'attachment_ids': self.attachment_ids, 'task': self, 'move_path': self.move_path, - 'delete_file': self.delete_file, - 'move_file': self.move_file, + 'after_import': self.after_import, + 'md5_check': self.md5_check, } conn = method_class(self.env, config) conn.run() diff --git a/external_file_location/task_view.xml b/external_file_location/task_view.xml index 2281ef8b..780b87d0 100644 --- a/external_file_location/task_view.xml +++ b/external_file_location/task_view.xml @@ -6,25 +6,23 @@ external.file.task
+
+
-
- - + + - - - - - - - -