From 658e0d33754a7d537b27bfc58494acf435fab0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Beau?= Date: Thu, 4 Apr 2013 17:10:54 +0200 Subject: [PATCH] [REF] refactor file email --- __init__.py | 4 +-- __openerp__.py | 7 ++-- fetchmail.py | 53 ++++++++++++++++++++++++++++++ fetchmail_view.xml | 19 +++++++++++ file_buffer.py => file_document.py | 26 +++++++-------- 5 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 fetchmail.py create mode 100644 fetchmail_view.xml rename file_buffer.py => file_document.py (62%) diff --git a/__init__.py b/__init__.py index 91628407..c2827724 100644 --- a/__init__.py +++ b/__init__.py @@ -20,5 +20,5 @@ # ############################################################################### -import file_buffer - +import file_document +import fetchmail diff --git a/__openerp__.py b/__openerp__.py index 439d74c6..8dcc25e3 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -27,15 +27,16 @@ 'license': 'AGPL-3', 'description': """Abstract module for importing and processing the attachment of an email. The attachment of the email will be imported - as a file_buffer and then in your custom module you can process it. + as a file_document and then in your custom module you can process it. An example of processing can be found in account_statement_email """, 'author': 'Akretion', 'website': 'http://www.akretion.com/', - 'depends': ['file_buffer'], + 'depends': ['file_document'], 'init_xml': [], 'update_xml': [ - ], + "fetchmail_view.xml", + ], 'demo_xml': [], 'installable': True, 'active': False, diff --git a/fetchmail.py b/fetchmail.py new file mode 100644 index 00000000..a140017e --- /dev/null +++ b/fetchmail.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# file_email for OpenERP +# Copyright (C) 2013 Akretion (http://www.akretion.com). +# @author Sébastien BEAU +# +# 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.osv.orm import Model +from openerp.osv import fields + + +class fetchmail_server(Model): + _inherit = 'fetchmail.server' + + def get_file_type(self, cr, uid, context=None): + return [] + + def _get_file_type(self, cr, uid, context=None): + return self.get_file_type(cr, uid, context=context) + + _columns = { + 'file_type': fields.selection(_get_file_type, 'File Type', + help='The file type will show some special option'), + } + + def get_context_for_server(self, cr, uid, server_id, context=None): + if context is None: + ctx = {} + else: + ctx = context.copy() + ctx['default_file_document_vals'] = {} + return ctx + + def fetch_mail(self, cr, uid, ids, context=None): + for id in ids: + ctx = self.get_context_for_server(cr, uid, id, context=context) + super(fetchmail_server, self).fetch_mail(cr, uid, ids, context=ctx) + return True diff --git a/fetchmail_view.xml b/fetchmail_view.xml new file mode 100644 index 00000000..e9eaf732 --- /dev/null +++ b/fetchmail_view.xml @@ -0,0 +1,19 @@ + + + + + + fetchmail.server.form + fetchmail.server + form + + + + + + + + + + + diff --git a/file_buffer.py b/file_document.py similarity index 62% rename from file_buffer.py rename to file_document.py index ee712b1f..ab59be0d 100644 --- a/file_buffer.py +++ b/file_document.py @@ -23,29 +23,27 @@ from openerp.osv import fields, orm -class file_buffer(orm.Model): - _inherit = "file.buffer" +class file_document(orm.Model): + _inherit = "file.document" - def _prepare_data_for_file_buffer(self, cr, uid, msg, context=None): - """Method to prepare the data for creating a file buffer. + def _prepare_data_for_file_document(self, cr, uid, msg, context=None): + """Method to prepare the data for creating a file document. :param msg: a dictionnary with the email data :type: dict - :return: a list of dictionnary that containt the file buffer data + :return: a list of dictionnary that containt the file document data :rtype: list """ return [] def message_new(self, cr, uid, msg, custom_values, context=None): - create_ids = [] - res = self._get_vals_for_file_buffer(cr, uid, msg, context=context) + created_ids = [] + res = self._prepare_data_for_file_document(cr, uid, msg, context=context) if res: for vals in res: - file_id = self.create(cr, uid, vals, context=context) - self.create_file_buffer_attachment(cr, uid, file_id, - datas, file_name, - context=context, - extension=vals['extension']) - create_ids = file_id - return create_ids + if context.get('default_file_document_vals'): + vals.update(context['default_file_document_vals']) + created_ids.append(self.create(cr, uid, vals, context=context)) + print "create message", vals['date'] + return created_ids return None