From 548e308a7ac6f1f5ff43b5014c89436e743612a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Beau?= Date: Thu, 11 Jul 2013 01:09:07 +0200 Subject: [PATCH 1/3] [IMP] file_email: fix default value, add company on email server, add sql constraint for uniqueness --- __openerp__.py | 1 + fetchmail.py | 9 +++++++++ fetchmail_view.xml | 4 ++++ file_document.py | 17 ++++++++++++++--- file_document_view.xml | 21 +++++++++++++++++++++ 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 file_document_view.xml diff --git a/__openerp__.py b/__openerp__.py index 8dcc25e3..125a27aa 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -36,6 +36,7 @@ 'init_xml': [], 'update_xml': [ "fetchmail_view.xml", + "file_document_view.xml", ], 'demo_xml': [], 'installable': True, diff --git a/fetchmail.py b/fetchmail.py index d8fcdfe3..9710338b 100644 --- a/fetchmail.py +++ b/fetchmail.py @@ -35,14 +35,23 @@ class fetchmail_server(orm.Model): _columns = { 'file_type': fields.selection(_get_file_type, 'File Type', help='The file type will show some special option'), + 'company_id': fields.many2one('res.company', 'Company', required=True),#Why this field do not exist by default? } + _defaults = { + 'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'fetchmail.server', context=c), + } + + 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'] = {} + server = self.browse(cr, uid, server_id, context=context) + ctx['default_company_id'] = server.company_id.id + ctx['default_fetchmail_server_id'] = server_id return ctx def fetch_mail(self, cr, uid, ids, context=None): diff --git a/fetchmail_view.xml b/fetchmail_view.xml index e9eaf732..e83d2d74 100644 --- a/fetchmail_view.xml +++ b/fetchmail_view.xml @@ -8,6 +8,10 @@ form + + + + diff --git a/file_document.py b/file_document.py index ab59be0d..af5277c8 100644 --- a/file_document.py +++ b/file_document.py @@ -26,6 +26,15 @@ from openerp.osv import fields, orm class file_document(orm.Model): _inherit = "file.document" + _columns = { + 'fetchmail_server_id': fields.many2one('fetchmail.server', 'Email Server'), + } + + _sql_constraints = [ + ('fecthmail_server_ext_id_uniq', 'unique(fetchmail_server_id, ext_id)', + 'The combination of Email Server and External id must be unique !'), + ] + 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 @@ -41,9 +50,11 @@ class file_document(orm.Model): res = self._prepare_data_for_file_document(cr, uid, msg, context=context) if res: for vals in res: - if context.get('default_file_document_vals'): - vals.update(context['default_file_document_vals']) + default = context.get('default_file_document_vals') + if default: + for key in default: + if not key in vals: + vals[key] = default[key] created_ids.append(self.create(cr, uid, vals, context=context)) - print "create message", vals['date'] return created_ids return None diff --git a/file_document_view.xml b/file_document_view.xml new file mode 100644 index 00000000..1529e47d --- /dev/null +++ b/file_document_view.xml @@ -0,0 +1,21 @@ + + + + + + + file.document.search + file.document + search + + + + + + + + + + + + From 4af45fce4ecbaa9e15739a97ada5f366b21e0083 Mon Sep 17 00:00:00 2001 From: Arthur Vuillard Date: Thu, 8 Aug 2013 16:47:19 +0200 Subject: [PATCH 2/3] Add a missing dependency to fetchmail --- __openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__openerp__.py b/__openerp__.py index 125a27aa..0d88bca3 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -32,7 +32,7 @@ """, 'author': 'Akretion', 'website': 'http://www.akretion.com/', - 'depends': ['file_document'], + 'depends': ['file_document', 'fetchmail'], 'init_xml': [], 'update_xml': [ "fetchmail_view.xml", From 4e67654e3bb8d9fb800a163972b9effd5b2a533a Mon Sep 17 00:00:00 2001 From: Sebastien Beau Date: Tue, 26 Nov 2013 19:21:08 +0100 Subject: [PATCH 3/3] [FIX] fix email import for V7 --- fetchmail_view.xml | 5 +---- file_document.py | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/fetchmail_view.xml b/fetchmail_view.xml index e83d2d74..7a63ad83 100644 --- a/fetchmail_view.xml +++ b/fetchmail_view.xml @@ -3,17 +3,14 @@ - fetchmail.server.form fetchmail.server - form - - + diff --git a/file_document.py b/file_document.py index af5277c8..7e26412c 100644 --- a/file_document.py +++ b/file_document.py @@ -35,6 +35,39 @@ class file_document(orm.Model): 'The combination of Email Server and External id must be unique !'), ] + + 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 super(file_document, self).message_process(self, cr, uid, model, + message, + custom_values=custom_values, + save_original=save_original, + strip_attachments=strip_attachments, + thread_id=thread_id, + context=context) + + def message_post(self, cr, uid, thread_id, body='', subject=None, type='notification', + subtype=None, parent_id=False, attachments=None, context=None, + content_subtype='html', **kwargs): + if context.get('no_post'): + return None + return super(file_document, self).message_post(cr, uid, thread_id, + body=body, + subject=subject, + type='notification', + subtype=subtype, + parent_id=parent_id, + attachments=attachments, + context=context, + content_subtype=content_subtype, + **kwargs) + + + 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 @@ -56,5 +89,8 @@ class file_document(orm.Model): if not key in vals: vals[key] = default[key] created_ids.append(self.create(cr, uid, vals, context=context)) - return created_ids + cr.commit() + context['created_ids'] = created_ids + return created_ids[0] return None +