From c54bbf93d15e61ba71f0d14d41fe640a92d30520 Mon Sep 17 00:00:00 2001 From: Valentin Chemiere Date: Wed, 17 Jun 2015 12:14:35 +0200 Subject: [PATCH 01/16] Add file import/export --- file_email/__init__.py | 24 ++++ file_email/__openerp__.py | 44 ++++++++ file_email/attachment_metadata.py | 139 ++++++++++++++++++++++++ file_email/attachment_metadata_view.xml | 65 +++++++++++ file_email/fetchmail.py | 69 ++++++++++++ file_email/fetchmail_view.xml | 22 ++++ 6 files changed, 363 insertions(+) create mode 100644 file_email/__init__.py create mode 100644 file_email/__openerp__.py create mode 100644 file_email/attachment_metadata.py create mode 100644 file_email/attachment_metadata_view.xml create mode 100644 file_email/fetchmail.py create mode 100644 file_email/fetchmail_view.xml diff --git a/file_email/__init__.py b/file_email/__init__.py new file mode 100644 index 00000000000..0b520f764e5 --- /dev/null +++ b/file_email/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# file_email for OpenERP +# Copyright (C) 2012-TODAY Akretion . +# @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 . import attachment_metadata +from . import fetchmail diff --git a/file_email/__openerp__.py b/file_email/__openerp__.py new file mode 100644 index 00000000000..e3709038981 --- /dev/null +++ b/file_email/__openerp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# file_email for OpenERP +# Copyright (C) 2012-TODAY Akretion . +# @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 . +# +############################################################################### + +{ + 'name': 'file_email', + 'version': '0.1', + 'category': 'Generic Modules/Others', + '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 attachment_metadata 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': ['external_file_location', 'fetchmail'], + 'init_xml': [], + 'update_xml': [ + "fetchmail_view.xml", + "attachment_metadata_view.xml", + ], + 'demo_xml': [], + 'installable': True, + 'active': False, +} diff --git a/file_email/attachment_metadata.py b/file_email/attachment_metadata.py new file mode 100644 index 00000000000..78650c9b2e3 --- /dev/null +++ b/file_email/attachment_metadata.py @@ -0,0 +1,139 @@ +# -*- coding: utf-8 -*- +############################################################################### +# +# file_email for OpenERP +# Copyright (C) 2012-TODAY Akretion . +# @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 import models, fields, api +import base64 + + +class IrAttachmentMetadata(models.Model): + _inherit = "ir.attachment.metadata" + + fetchmail_server_id = fields.Many2one('fetchmail.server', + string='Email Server') + + def message_process(self, cr, uid, model, message, custom_values=None, + save_original=False, strip_attachments=False, + thread_id=None, context=None): + if context is None: + context = {} + context['no_post'] = True + return True + + def message_post(self, cr, uid, thread_id, body='', subject=None, + type='notification', subtype=None, parent_id=False, + attachments=None, content_subtype='html', context=None, + **kwargs): + if context.get('no_post'): + return None + return True + + @api.model + def _get_attachment_metadata_data(self, condition, msg, att): + values = { + 'file_type': condition.server_id.file_type, + 'name': msg['subject'], + 'direction': 'input', + 'date': msg['date'], + 'ext_id': msg['message_id'], + 'datas_fname': att[0], + 'datas': base64.b64encode(att[1]), + 'state': 'pending' + } + return values + + @api.model + def prepare_data_from_basic_condition(self, condition, msg): + vals = {} + if (condition.from_email in msg['from'] + and condition.mail_subject in msg['subject']): + for att in msg['attachments']: + if condition.file_extension in att[0]: + vals = self._get_attachment_metadata_data(condition, + msg, att) + break + return vals + + @api.model + def _prepare_data_for_attachment_metadata(self, msg): + """Method to prepare the data for creating a attachment metadata. + :param msg: a dictionnary with the email data + :type: dict + + :return: a list of dictionnary that containt + the attachment metadata data + :rtype: list + """ + res = [] + server_id = self._context.get('fetchmail_server_id', False) + file_condition_obj = self.env['ir.attachment.metadata.condition'] + cond_ids = file_condition_obj.search([('server_id', '=', server_id)]) + if cond_ids: + for cond in cond_ids: + if cond.type == 'normal': + vals = self.prepare_data_from_basic_condition(cond, msg) + else: + vals = getattr(self, cond.type)(cond, msg) + if vals: + res.append(vals) + return res + + @api.model + def message_new(self, msg, custom_values): + created_ids = [] + res = self._prepare_data_for_attachment_metadata(msg) + if res: + for vals in res: + default = self._context.get('default_attachment_metadata_vals') + if default: + for key in default: + if key not in vals: + vals[key] = default[key] + created_ids.append(self.create(vals)) + self._cr.commit() + return created_ids[0].id + return None + + +class IrAttachmentMetadataCondition(models.Model): + _name = "ir.attachment.metadata.condition" + _description = "Attachment Metadata Conditions" + + @api.model + def _get_attachment_metadata_condition_type(self): + return self.get_attachment_metadata_condition_type() + + def get_attachment_metadata_condition_type(self): + return [('normal', 'Normal')] + + from_email = fields.Char(string='Email', size=64) + mail_subject = fields.Char(size=64) + type = fields.Selection( + selection='_get_attachment_metadata_condition_type', + help="Create your own type if the normal type \ + do not correspond to your need", + required=True, + default='normal' + ) + file_extension = fields.Char(size=64, + help="File extension or file name", + required=True) + server_id = fields.Many2one('fetchmail.server', string='Server Mail') diff --git a/file_email/attachment_metadata_view.xml b/file_email/attachment_metadata_view.xml new file mode 100644 index 00000000000..4b23fbfab42 --- /dev/null +++ b/file_email/attachment_metadata_view.xml @@ -0,0 +1,65 @@ + + + + + + + ir.attachment.metadata.search + ir.attachment.metadata + search + + + + + + + + + + + view_attachment_metadata_condition_tree + ir.attachment.metadata.condition + + + + + + + + + + + + + view_attachment_metadata_condition_form + ir.attachment.metadata.condition + +
+ + + + + + + + + +
+
+
+ + + Configuration + ir.attachment.metadata.condition + form + tree,form + + + + +
+
+ diff --git a/file_email/fetchmail.py b/file_email/fetchmail.py new file mode 100644 index 00000000000..bb0ed6c2019 --- /dev/null +++ b/file_email/fetchmail.py @@ -0,0 +1,69 @@ +# -*- 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 import models, fields, api + + +class fetchmail_server(models.Model): + _inherit = 'fetchmail.server' + + @api.model + def get_file_type(self): + return [] + + @api.model + def _get_file_type(self): + return self.get_file_type() + + def company_default_get(self): + company_id = (self.env['res.company']. + _company_default_get('fetchmail.server')) + return self.env['res.company'].browse(company_id) + + file_type = fields.Selection( + selection='_get_file_type', + help='The file type will show some special option') + company_id = fields.Many2one( + 'res.company', + string='Company', + required=True, + default=company_default_get + ) # Why this field do not exist by default? + attachment_metadata_condition_ids = fields.One2many( + 'ir.attachment.metadata.condition', 'server_id', string='Attachment') + + @api.one + def get_context_for_server(self): + if self._context is None: + ctx = {} + else: + ctx = self._context.copy() + ctx['default_attachment_metadata_vals'] = {} + ctx['default_company_id'] = self.company_id.id + ctx['default_fetchmail_server_id'] = self.id + return ctx + + @api.multi + def fetch_mail(self): + for server in self: + super(fetchmail_server, server).fetch_mail() + return True diff --git a/file_email/fetchmail_view.xml b/file_email/fetchmail_view.xml new file mode 100644 index 00000000000..5dfd091ab9b --- /dev/null +++ b/file_email/fetchmail_view.xml @@ -0,0 +1,22 @@ + + + + + + fetchmail.server + + + + + + + + + + + + + + + + From 668a8a7583db9b3c270cfaa7f85b5f2d0ccf50aa Mon Sep 17 00:00:00 2001 From: David Beal Date: Tue, 23 Feb 2016 21:51:34 +0100 Subject: [PATCH 02/16] [FIX] python header in akretion modules --- file_email/__init__.py | 22 ---------------------- file_email/__openerp__.py | 22 ++-------------------- file_email/attachment_metadata.py | 26 ++++---------------------- file_email/fetchmail.py | 22 ++-------------------- 4 files changed, 8 insertions(+), 84 deletions(-) diff --git a/file_email/__init__.py b/file_email/__init__.py index 0b520f764e5..24911370ff8 100644 --- a/file_email/__init__.py +++ b/file_email/__init__.py @@ -1,24 +1,2 @@ -# -*- coding: utf-8 -*- -############################################################################### -# -# file_email for OpenERP -# Copyright (C) 2012-TODAY Akretion . -# @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 . import attachment_metadata from . import fetchmail diff --git a/file_email/__openerp__.py b/file_email/__openerp__.py index e3709038981..598eceb7c58 100644 --- a/file_email/__openerp__.py +++ b/file_email/__openerp__.py @@ -1,24 +1,6 @@ -# -*- coding: utf-8 -*- -############################################################################### -# -# file_email for OpenERP -# Copyright (C) 2012-TODAY Akretion . +# coding: utf-8 # @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 . -# -############################################################################### +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'file_email', diff --git a/file_email/attachment_metadata.py b/file_email/attachment_metadata.py index 78650c9b2e3..7ee8e6f5048 100644 --- a/file_email/attachment_metadata.py +++ b/file_email/attachment_metadata.py @@ -1,24 +1,6 @@ -# -*- coding: utf-8 -*- -############################################################################### -# -# file_email for OpenERP -# Copyright (C) 2012-TODAY Akretion . +# coding: utf-8 # @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 . -# -############################################################################### +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api import base64 @@ -63,8 +45,8 @@ def _get_attachment_metadata_data(self, condition, msg, att): @api.model def prepare_data_from_basic_condition(self, condition, msg): vals = {} - if (condition.from_email in msg['from'] - and condition.mail_subject in msg['subject']): + if (condition.from_email in msg['from'] and + condition.mail_subject in msg['subject']): for att in msg['attachments']: if condition.file_extension in att[0]: vals = self._get_attachment_metadata_data(condition, diff --git a/file_email/fetchmail.py b/file_email/fetchmail.py index bb0ed6c2019..63ac330ba90 100644 --- a/file_email/fetchmail.py +++ b/file_email/fetchmail.py @@ -1,24 +1,6 @@ -# -*- coding: utf-8 -*- -############################################################################### -# -# file_email for OpenERP -# Copyright (C) 2013 Akretion (http://www.akretion.com). +# coding: utf-8 # @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 . -# -############################################################################### +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api From a90cc444202445961e8a70fa8ae4b60c3b9db072 Mon Sep 17 00:00:00 2001 From: David Beal Date: Fri, 26 Feb 2016 13:46:36 +0100 Subject: [PATCH 03/16] =?UTF-8?q?[FIX]=C2=A0file=20structure,=20readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .travis.yml | 1 + file_email/README.rst | 80 +++++++++++++++++++ file_email/__init__.py | 3 +- file_email/__openerp__.py | 32 ++++---- file_email/attachment_metadata_view.xml | 65 --------------- file_email/fetchmail_view.xml | 22 ----- file_email/models/__init__.py | 2 + .../attachment.py} | 24 +++--- file_email/{ => models}/fetchmail.py | 29 +++---- file_email/views/attachment_view.xml | 65 +++++++++++++++ file_email/views/fetchmail_view.xml | 22 +++++ 11 files changed, 210 insertions(+), 135 deletions(-) create mode 100644 file_email/README.rst delete mode 100644 file_email/attachment_metadata_view.xml delete mode 100644 file_email/fetchmail_view.xml create mode 100644 file_email/models/__init__.py rename file_email/{attachment_metadata.py => models/attachment.py} (86%) rename file_email/{ => models}/fetchmail.py (72%) create mode 100644 file_email/views/attachment_view.xml create mode 100644 file_email/views/fetchmail_view.xml diff --git a/.travis.yml b/.travis.yml index e31ccc1cea7..e17ae79257a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ virtualenv: system_site_packages: true install: + - git clone https://github.com/akretion/server-tools.git ${HOME}/server-tools-attachm -b 8-attachm-meta - git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} - travis_install_nightly diff --git a/file_email/README.rst b/file_email/README.rst new file mode 100644 index 00000000000..fb6ec5c39b3 --- /dev/null +++ b/file_email/README.rst @@ -0,0 +1,80 @@ + +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========== +File Email +========== + +Abstract module for importing and processing the + attachment of an email. The attachment of the email will be imported + as an ir.attachment.metadata and then in your custom module + you can process it. + +An example of processing can be found in account_statement_email + + +Usage +===== + +Go the menu Settings > File Exchange > Configuration + +A implementation must define in your own module to test this module on a use case + + + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/8.0 + + +Known issues / Roadmap +====================== + +The purpose of this module is not to import the data of the file but only exchange files with external application. + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed `feedback +`_. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + + +Contributors +------------ + +* Valentin CHEMIERE +* Sebastien BEAU +* Joel Grand-Guillaume Camptocamp +* initOS + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://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 https://odoo-community.org. diff --git a/file_email/__init__.py b/file_email/__init__.py index 24911370ff8..0650744f6bc 100644 --- a/file_email/__init__.py +++ b/file_email/__init__.py @@ -1,2 +1 @@ -from . import attachment_metadata -from . import fetchmail +from . import models diff --git a/file_email/__openerp__.py b/file_email/__openerp__.py index 598eceb7c58..641d32fc2d5 100644 --- a/file_email/__openerp__.py +++ b/file_email/__openerp__.py @@ -1,26 +1,24 @@ # coding: utf-8 -# @author Sébastien BEAU +# @author Sébastien BEAU @ Akretion +# @author Florian DA COSTA @ Akretion +# @author Benoit GUILLOT @ Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'file_email', - 'version': '0.1', - 'category': 'Generic Modules/Others', + 'name': 'File Email', + 'version': '8.0.1.0.0', + 'author': 'Akretion,Odoo Community Association (OCA)', + 'category': 'Generic Modules', '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 attachment_metadata 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': ['external_file_location', 'fetchmail'], - 'init_xml': [], - 'update_xml': [ - "fetchmail_view.xml", - "attachment_metadata_view.xml", + 'depends': [ + 'attachment.metadata', + 'fetchmail' + ], + 'data': [ + "views/fetchmail_view.xml", + "views/attachment_view.xml", ], - 'demo_xml': [], + 'demo': [], 'installable': True, - 'active': False, } diff --git a/file_email/attachment_metadata_view.xml b/file_email/attachment_metadata_view.xml deleted file mode 100644 index 4b23fbfab42..00000000000 --- a/file_email/attachment_metadata_view.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - ir.attachment.metadata.search - ir.attachment.metadata - search - - - - - - - - - - - view_attachment_metadata_condition_tree - ir.attachment.metadata.condition - - - - - - - - - - - - - view_attachment_metadata_condition_form - ir.attachment.metadata.condition - -
- - - - - - - - - -
-
-
- - - Configuration - ir.attachment.metadata.condition - form - tree,form - - - - -
-
- diff --git a/file_email/fetchmail_view.xml b/file_email/fetchmail_view.xml deleted file mode 100644 index 5dfd091ab9b..00000000000 --- a/file_email/fetchmail_view.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - fetchmail.server - - - - - - - - - - - - - - - - diff --git a/file_email/models/__init__.py b/file_email/models/__init__.py new file mode 100644 index 00000000000..3d9d7edd669 --- /dev/null +++ b/file_email/models/__init__.py @@ -0,0 +1,2 @@ +from . import attachment +from . import fetchmail diff --git a/file_email/attachment_metadata.py b/file_email/models/attachment.py similarity index 86% rename from file_email/attachment_metadata.py rename to file_email/models/attachment.py index 7ee8e6f5048..0e808010447 100644 --- a/file_email/attachment_metadata.py +++ b/file_email/models/attachment.py @@ -1,5 +1,7 @@ # coding: utf-8 -# @author Sébastien BEAU +# @author Sébastien BEAU @ Akretion +# @author Florian DA COSTA @ Akretion +# @author Benoit GUILLOT @ Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api @@ -49,8 +51,8 @@ def prepare_data_from_basic_condition(self, condition, msg): condition.mail_subject in msg['subject']): for att in msg['attachments']: if condition.file_extension in att[0]: - vals = self._get_attachment_metadata_data(condition, - msg, att) + vals = self._get_attachment_metadata_data( + condition, msg, att) break return vals @@ -106,16 +108,14 @@ def _get_attachment_metadata_condition_type(self): def get_attachment_metadata_condition_type(self): return [('normal', 'Normal')] - from_email = fields.Char(string='Email', size=64) - mail_subject = fields.Char(size=64) + from_email = fields.Char(string='Email') + mail_subject = fields.Char() type = fields.Selection( selection='_get_attachment_metadata_condition_type', - help="Create your own type if the normal type \ - do not correspond to your need", + required=True, default='normal', + help="Create your own type if the normal type " + "do not correspond to your need") + file_extension = fields.Char( required=True, - default='normal' - ) - file_extension = fields.Char(size=64, - help="File extension or file name", - required=True) + help="File extension or file name") server_id = fields.Many2one('fetchmail.server', string='Server Mail') diff --git a/file_email/fetchmail.py b/file_email/models/fetchmail.py similarity index 72% rename from file_email/fetchmail.py rename to file_email/models/fetchmail.py index 63ac330ba90..fa8996bee1e 100644 --- a/file_email/fetchmail.py +++ b/file_email/models/fetchmail.py @@ -1,38 +1,33 @@ # coding: utf-8 -# @author Sébastien BEAU +# @author Sébastien BEAU @ Akretion +# @author Florian DA COSTA @ Akretion +# @author Benoit GUILLOT @ Akretion # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api -class fetchmail_server(models.Model): +class FetchmailServer(models.Model): _inherit = 'fetchmail.server' - @api.model - def get_file_type(self): - return [] - - @api.model - def _get_file_type(self): - return self.get_file_type() - def company_default_get(self): company_id = (self.env['res.company']. _company_default_get('fetchmail.server')) return self.env['res.company'].browse(company_id) file_type = fields.Selection( - selection='_get_file_type', + selection='get_file_type', help='The file type will show some special option') company_id = fields.Many2one( - 'res.company', - string='Company', - required=True, - default=company_default_get - ) # Why this field do not exist by default? + 'res.company', string='Company', + required=True, default=company_default_get) attachment_metadata_condition_ids = fields.One2many( 'ir.attachment.metadata.condition', 'server_id', string='Attachment') + @api.model + def get_file_type(self): + return [] + @api.one def get_context_for_server(self): if self._context is None: @@ -47,5 +42,5 @@ def get_context_for_server(self): @api.multi def fetch_mail(self): for server in self: - super(fetchmail_server, server).fetch_mail() + super(FetchmailServer, server).fetch_mail() return True diff --git a/file_email/views/attachment_view.xml b/file_email/views/attachment_view.xml new file mode 100644 index 00000000000..f3de83ad804 --- /dev/null +++ b/file_email/views/attachment_view.xml @@ -0,0 +1,65 @@ + + + + + + + ir.attachment.metadata.search + ir.attachment.metadata + search + + + + + + + + + + + view_attachment_metadata_condition_tree + ir.attachment.metadata.condition + + + + + + + + + + + + + view_attachment_metadata_condition_form + ir.attachment.metadata.condition + +
+ + + + + + + + + +
+
+
+ + + Configuration + ir.attachment.metadata.condition + form + tree,form + + + + +
+
+ diff --git a/file_email/views/fetchmail_view.xml b/file_email/views/fetchmail_view.xml new file mode 100644 index 00000000000..793ced1cbd0 --- /dev/null +++ b/file_email/views/fetchmail_view.xml @@ -0,0 +1,22 @@ + + + + + + fetchmail.server + + + + + + + + + + + + + + + + From a7f0f8b975eef1be99996fcaef2e1c8a305b7a83 Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Tue, 8 Mar 2016 11:40:46 +0100 Subject: [PATCH 04/16] [IMP] rename to FetchmailAttachmentCondition --- file_email/models/attachment.py | 24 +----------------------- file_email/models/fetchmail.py | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/file_email/models/attachment.py b/file_email/models/attachment.py index 0e808010447..fc0b7b05765 100644 --- a/file_email/models/attachment.py +++ b/file_email/models/attachment.py @@ -68,7 +68,7 @@ def _prepare_data_for_attachment_metadata(self, msg): """ res = [] server_id = self._context.get('fetchmail_server_id', False) - file_condition_obj = self.env['ir.attachment.metadata.condition'] + file_condition_obj = self.env['fetchmail.attachment.condition'] cond_ids = file_condition_obj.search([('server_id', '=', server_id)]) if cond_ids: for cond in cond_ids: @@ -97,25 +97,3 @@ def message_new(self, msg, custom_values): return None -class IrAttachmentMetadataCondition(models.Model): - _name = "ir.attachment.metadata.condition" - _description = "Attachment Metadata Conditions" - - @api.model - def _get_attachment_metadata_condition_type(self): - return self.get_attachment_metadata_condition_type() - - def get_attachment_metadata_condition_type(self): - return [('normal', 'Normal')] - - from_email = fields.Char(string='Email') - mail_subject = fields.Char() - type = fields.Selection( - selection='_get_attachment_metadata_condition_type', - required=True, default='normal', - help="Create your own type if the normal type " - "do not correspond to your need") - file_extension = fields.Char( - required=True, - help="File extension or file name") - server_id = fields.Many2one('fetchmail.server', string='Server Mail') diff --git a/file_email/models/fetchmail.py b/file_email/models/fetchmail.py index fa8996bee1e..b94fe247c12 100644 --- a/file_email/models/fetchmail.py +++ b/file_email/models/fetchmail.py @@ -22,7 +22,7 @@ def company_default_get(self): 'res.company', string='Company', required=True, default=company_default_get) attachment_metadata_condition_ids = fields.One2many( - 'ir.attachment.metadata.condition', 'server_id', string='Attachment') + 'fetchmail.attachment.condition"', 'server_id', string='Attachment') @api.model def get_file_type(self): @@ -44,3 +44,27 @@ def fetch_mail(self): for server in self: super(FetchmailServer, server).fetch_mail() return True + + +class FetchmailAttachmentCondition(models.Model): + _name = "fetchmail.attachment.condition" + _description = "Fetchmail Attachment Conditions" + + @api.model + def _get_attachment_metadata_condition_type(self): + return self.get_attachment_metadata_condition_type() + + def get_attachment_metadata_condition_type(self): + return [('normal', 'Normal')] + + from_email = fields.Char(string='Email') + mail_subject = fields.Char() + type = fields.Selection( + selection='_get_attachment_metadata_condition_type', + required=True, default='normal', + help="Create your own type if the normal type " + "do not correspond to your need") + file_extension = fields.Char( + required=True, + help="File extension or file name") + server_id = fields.Many2one('fetchmail.server', string='Server Mail') From ddf8abc4509e3ec5c8b478fb68213dbcaed05f4d Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Tue, 8 Mar 2016 17:34:38 +0100 Subject: [PATCH 05/16] [FIX] module dependency --- file_email/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file_email/__openerp__.py b/file_email/__openerp__.py index 641d32fc2d5..d5d43e56da5 100644 --- a/file_email/__openerp__.py +++ b/file_email/__openerp__.py @@ -12,7 +12,7 @@ 'license': 'AGPL-3', 'website': 'http://www.akretion.com/', 'depends': [ - 'attachment.metadata', + 'attachment_metadata', 'fetchmail' ], 'data': [ From 484122ac3bcc4bc9d0421d86048401a0e1982bea Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Tue, 8 Mar 2016 17:41:50 +0100 Subject: [PATCH 06/16] [FIX] xml view after rename to FetchmailAttachmentCondition --- file_email/models/fetchmail.py | 4 +-- file_email/views/attachment_view.xml | 46 ++----------------------- file_email/views/fetchmail_view.xml | 51 ++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/file_email/models/fetchmail.py b/file_email/models/fetchmail.py index b94fe247c12..06e7e69f793 100644 --- a/file_email/models/fetchmail.py +++ b/file_email/models/fetchmail.py @@ -22,7 +22,7 @@ def company_default_get(self): 'res.company', string='Company', required=True, default=company_default_get) attachment_metadata_condition_ids = fields.One2many( - 'fetchmail.attachment.condition"', 'server_id', string='Attachment') + 'fetchmail.attachment.condition', 'server_id', string='Attachment') @api.model def get_file_type(self): @@ -47,7 +47,7 @@ def fetch_mail(self): class FetchmailAttachmentCondition(models.Model): - _name = "fetchmail.attachment.condition" + _name = 'fetchmail.attachment.condition' _description = "Fetchmail Attachment Conditions" @api.model diff --git a/file_email/views/attachment_view.xml b/file_email/views/attachment_view.xml index f3de83ad804..dc3756bf934 100644 --- a/file_email/views/attachment_view.xml +++ b/file_email/views/attachment_view.xml @@ -11,54 +11,12 @@ + - - - view_attachment_metadata_condition_tree - ir.attachment.metadata.condition - - - - - - - - - - - - - view_attachment_metadata_condition_form - ir.attachment.metadata.condition - -
- - - - - - - - - -
-
-
- - - Configuration - ir.attachment.metadata.condition - form - tree,form - - - + diff --git a/file_email/views/fetchmail_view.xml b/file_email/views/fetchmail_view.xml index 793ced1cbd0..6de1de58935 100644 --- a/file_email/views/fetchmail_view.xml +++ b/file_email/views/fetchmail_view.xml @@ -12,11 +12,56 @@ - - - + + + + + + view_fetchmail_attachment_condition_tree + fetchmail.attachment.condition + + + + + + + + + + + + + view_fetchmail_attachment_condition_form + fetchmail.attachment.condition + +
+ + + + + + + + + +
+
+
+ + + From 43b294806bc4afe282fd6315bc8232ba83e4176e Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Tue, 8 Mar 2016 17:42:57 +0100 Subject: [PATCH 07/16] [IMP] Add relation to FetchmailAttachmentCondition in ir_attachemnt --- file_email/models/attachment.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/file_email/models/attachment.py b/file_email/models/attachment.py index fc0b7b05765..61f9f753003 100644 --- a/file_email/models/attachment.py +++ b/file_email/models/attachment.py @@ -11,8 +11,17 @@ class IrAttachmentMetadata(models.Model): _inherit = "ir.attachment.metadata" - fetchmail_server_id = fields.Many2one('fetchmail.server', - string='Email Server') + fetchmail_attachment_condition_id = fields.Many2one( + 'fetchmail.attachment.condition', + string='FetchMail condition', + help="The Fetchemail attachment condition used" + "to create this attachment") + fetchmail_server_id = fields.Many2one( + 'fetchmail.server', + string='Email Server', + related='fetchmail_attachment_condition_id.server_id', store=True, + readonly=True, + help="The email server used to create this attachment") def message_process(self, cr, uid, model, message, custom_values=None, save_original=False, strip_attachments=False, @@ -33,6 +42,7 @@ def message_post(self, cr, uid, thread_id, body='', subject=None, @api.model def _get_attachment_metadata_data(self, condition, msg, att): values = { + 'fetchmail_attachment_condition_id': condition.id, 'file_type': condition.server_id.file_type, 'name': msg['subject'], 'direction': 'input', @@ -95,5 +105,3 @@ def message_new(self, msg, custom_values): self._cr.commit() return created_ids[0].id return None - - From 4f4e6a2ed42efd7f0c0ae0090f09d1a8f0a1616b Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Fri, 11 Mar 2016 15:04:51 +0100 Subject: [PATCH 08/16] [IMP] add ir.model.access security --- file_email/__openerp__.py | 1 + file_email/security/ir.model.access.csv | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 file_email/security/ir.model.access.csv diff --git a/file_email/__openerp__.py b/file_email/__openerp__.py index d5d43e56da5..bbfbb282a05 100644 --- a/file_email/__openerp__.py +++ b/file_email/__openerp__.py @@ -16,6 +16,7 @@ 'fetchmail' ], 'data': [ + 'security/ir.model.access.csv', "views/fetchmail_view.xml", "views/attachment_view.xml", ], diff --git a/file_email/security/ir.model.access.csv b/file_email/security/ir.model.access.csv new file mode 100644 index 00000000000..9fff725bf35 --- /dev/null +++ b/file_email/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_fetchmail_attachment_condition_manager,fetchmail.attachment.condition.user,model_fetchmail_attachment_condition,base.group_system,1,1,1,1 +access_fetchmail_attachment_condition_user,fetchmail.attachment.condition.user,model_fetchmail_attachment_condition,base.group_user,1,0,0,0 From 49f8b5e498b8b71089325f6d7fac2ca1fbbe9042 Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Wed, 16 Mar 2016 14:43:38 +0100 Subject: [PATCH 09/16] [FIX] bug import move from file_mail --- file_email/models/attachment.py | 11 ++++++----- file_email/models/fetchmail.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/file_email/models/attachment.py b/file_email/models/attachment.py index 61f9f753003..092f2dfdf81 100644 --- a/file_email/models/attachment.py +++ b/file_email/models/attachment.py @@ -82,10 +82,11 @@ def _prepare_data_for_attachment_metadata(self, msg): cond_ids = file_condition_obj.search([('server_id', '=', server_id)]) if cond_ids: for cond in cond_ids: - if cond.type == 'normal': - vals = self.prepare_data_from_basic_condition(cond, msg) - else: - vals = getattr(self, cond.type)(cond, msg) + # this part of code raise an expetion if type != normal + # if cond.type == 'normal': + vals = self.prepare_data_from_basic_condition(cond, msg) + # else: + # vals = getattr(self, cond.type)(cond, msg) if vals: res.append(vals) return res @@ -103,5 +104,5 @@ def message_new(self, msg, custom_values): vals[key] = default[key] created_ids.append(self.create(vals)) self._cr.commit() - return created_ids[0].id + return created_ids[0] return None diff --git a/file_email/models/fetchmail.py b/file_email/models/fetchmail.py index 06e7e69f793..2d8878b547a 100644 --- a/file_email/models/fetchmail.py +++ b/file_email/models/fetchmail.py @@ -26,7 +26,7 @@ def company_default_get(self): @api.model def get_file_type(self): - return [] + return [('basic_import', 'Basic import')] @api.one def get_context_for_server(self): From 7cfbb95b2ca7055407ea7474ed9a1a87d62b7f49 Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Wed, 16 Mar 2016 14:44:43 +0100 Subject: [PATCH 10/16] [IMP] add name to fetchmail condition --- file_email/models/fetchmail.py | 2 ++ file_email/views/fetchmail_view.xml | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/file_email/models/fetchmail.py b/file_email/models/fetchmail.py index 2d8878b547a..7943da54c44 100644 --- a/file_email/models/fetchmail.py +++ b/file_email/models/fetchmail.py @@ -2,6 +2,7 @@ # @author Sébastien BEAU @ Akretion # @author Florian DA COSTA @ Akretion # @author Benoit GUILLOT @ Akretion +# @author Mourad EL HADJ MIMOUNE # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api @@ -57,6 +58,7 @@ def _get_attachment_metadata_condition_type(self): def get_attachment_metadata_condition_type(self): return [('normal', 'Normal')] + name = fields.Char(string='Name', required=True,) from_email = fields.Char(string='Email') mail_subject = fields.Char() type = fields.Selection( diff --git a/file_email/views/fetchmail_view.xml b/file_email/views/fetchmail_view.xml index 6de1de58935..1ff41a969db 100644 --- a/file_email/views/fetchmail_view.xml +++ b/file_email/views/fetchmail_view.xml @@ -24,6 +24,7 @@ fetchmail.attachment.condition + @@ -39,6 +40,10 @@
+

+

From 38181f82080ba8abbcff35eaddfd77bdbfb8293f Mon Sep 17 00:00:00 2001 From: Mourad Elhadj Mimoune Date: Wed, 25 May 2016 11:54:06 +0200 Subject: [PATCH 11/16] [FIX] add oca_dependencies --- file_email/__openerp__.py | 3 ++- oca_dependencies.txt | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 oca_dependencies.txt diff --git a/file_email/__openerp__.py b/file_email/__openerp__.py index bbfbb282a05..88baa95ac72 100644 --- a/file_email/__openerp__.py +++ b/file_email/__openerp__.py @@ -19,7 +19,8 @@ 'security/ir.model.access.csv', "views/fetchmail_view.xml", "views/attachment_view.xml", - ], + ], 'demo': [], 'installable': True, + 'images': [], } diff --git a/oca_dependencies.txt b/oca_dependencies.txt new file mode 100644 index 00000000000..d72e90060a8 --- /dev/null +++ b/oca_dependencies.txt @@ -0,0 +1 @@ +server-tools-file https://github.com/akretion/server-tools.git server-tools-file 8-file-loc \ No newline at end of file From d311894b7f45761d3e784a3478598872884adf47 Mon Sep 17 00:00:00 2001 From: Mourad El Hadj Mimoune Date: Wed, 25 May 2016 13:40:31 +0000 Subject: [PATCH 12/16] [FIX] fix pylint --- file_email/models/attachment.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/file_email/models/attachment.py b/file_email/models/attachment.py index 092f2dfdf81..5fb552e62fe 100644 --- a/file_email/models/attachment.py +++ b/file_email/models/attachment.py @@ -12,10 +12,10 @@ class IrAttachmentMetadata(models.Model): _inherit = "ir.attachment.metadata" fetchmail_attachment_condition_id = fields.Many2one( - 'fetchmail.attachment.condition', - string='FetchMail condition', - help="The Fetchemail attachment condition used" - "to create this attachment") + 'fetchmail.attachment.condition', + string='FetchMail condition', + help="The Fetchemail attachment condition used" + "to create this attachment") fetchmail_server_id = fields.Many2one( 'fetchmail.server', string='Email Server', @@ -25,7 +25,8 @@ class IrAttachmentMetadata(models.Model): def message_process(self, cr, uid, model, message, custom_values=None, save_original=False, strip_attachments=False, - thread_id=None, context=None): + thread_id=None, + context=None): if context is None: context = {} context['no_post'] = True From da47945eaf91bdd29cca8a6bc016fd8b76de20d5 Mon Sep 17 00:00:00 2001 From: Mourad Elhadj Mimoune Date: Wed, 25 May 2016 16:33:03 +0200 Subject: [PATCH 13/16] [FIX] add oca_dependencies branch name --- oca_dependencies.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oca_dependencies.txt b/oca_dependencies.txt index d72e90060a8..9d1f48d11e4 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1 @@ -server-tools-file https://github.com/akretion/server-tools.git server-tools-file 8-file-loc \ No newline at end of file +server-tools-file https://github.com/akretion/server-tools.git 8-attachm-meta \ No newline at end of file From 8097d7b01da823e4c9b16758dd7f4e389fd6a069 Mon Sep 17 00:00:00 2001 From: Mourad Elhadj Mimoune Date: Thu, 26 May 2016 11:25:15 +0200 Subject: [PATCH 14/16] [FIX] fix pylint --- file_email/models/fetchmail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file_email/models/fetchmail.py b/file_email/models/fetchmail.py index 7943da54c44..944a7c719dc 100644 --- a/file_email/models/fetchmail.py +++ b/file_email/models/fetchmail.py @@ -23,7 +23,7 @@ def company_default_get(self): 'res.company', string='Company', required=True, default=company_default_get) attachment_metadata_condition_ids = fields.One2many( - 'fetchmail.attachment.condition', 'server_id', string='Attachment') + 'fetchmail.attachment.condition', 'server_id', string='Attachment') @api.model def get_file_type(self): From beb262c779d99914bb5def3f555d2e9c641c76a9 Mon Sep 17 00:00:00 2001 From: Mourad Elhadj Mimoune Date: Thu, 26 May 2016 11:58:14 +0200 Subject: [PATCH 15/16] [FIX] fix attachment.metadata search view inherit --- file_email/views/attachment_view.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/file_email/views/attachment_view.xml b/file_email/views/attachment_view.xml index dc3756bf934..f1f9e2b1913 100644 --- a/file_email/views/attachment_view.xml +++ b/file_email/views/attachment_view.xml @@ -7,7 +7,8 @@ ir.attachment.metadata.search ir.attachment.metadata search - + From dbb8f1b6bf273c711a44473de928bb81dcbbe740 Mon Sep 17 00:00:00 2001 From: Mourad Elhadj Mimoune Date: Fri, 3 Jun 2016 10:28:19 +0200 Subject: [PATCH 16/16] [FIX] add python-fs to requirements.txt & remove dependency to Akretion repository --- oca_dependencies.txt | 2 +- requirements.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/oca_dependencies.txt b/oca_dependencies.txt index 9d1f48d11e4..8b137891791 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1 +1 @@ -server-tools-file https://github.com/akretion/server-tools.git 8-attachm-meta \ No newline at end of file + diff --git a/requirements.txt b/requirements.txt index c489fc0eb7f..249f8179d76 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ pysftp acme_tiny IPy + python-fs