From 2987991111b79b9fb549110620b981d57c9032ee Mon Sep 17 00:00:00 2001 From: Mantavya Gajjar Date: Thu, 22 Apr 2010 19:15:32 +0530 Subject: [PATCH] [ADD]: add new module document_email to provide facility automatic document will be created when new email arrives bzr revid: mga@tinyerp.com-20100422134532-3wlzcjglo70q72hw --- addons/document_email/__init__.py | 24 ++++++ addons/document_email/__openerp__.py | 44 ++++++++++ addons/document_email/document_email.py | 103 +++++++++++++++++++++++ addons/document_email/document_email.xml | 103 +++++++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 addons/document_email/__init__.py create mode 100644 addons/document_email/__openerp__.py create mode 100644 addons/document_email/document_email.py create mode 100644 addons/document_email/document_email.xml diff --git a/addons/document_email/__init__.py b/addons/document_email/__init__.py new file mode 100644 index 00000000000..40d4f14c4d1 --- /dev/null +++ b/addons/document_email/__init__.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# fp@tinyerp.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import document_email diff --git a/addons/document_email/__openerp__.py b/addons/document_email/__openerp__.py new file mode 100644 index 00000000000..5f628b2a02c --- /dev/null +++ b/addons/document_email/__openerp__.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# fp@tinyerp.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + "name" : "Email Integrated Document", + "version" : "1.1", + "depends" : ["base", "document", "mail_gateway"], + "author" : "Tiny", + "description": """Email Integrated Document + * Email based Document submission + * user based document subission + """, + 'author': 'Tiny', + 'website': 'http://www.openerp.com', + 'init_xml': [], + 'update_xml': [ + "document_email.xml" + ], + 'demo_xml': [ + + ], + 'installable': True, + 'active': False +} diff --git a/addons/document_email/document_email.py b/addons/document_email/document_email.py new file mode 100644 index 00000000000..7e5b45bd6cb --- /dev/null +++ b/addons/document_email/document_email.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +#-*- coding:utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved +# fp@tinyerp.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import binascii + +from osv import osv +from osv import fields +from tools.translate import _ + +class email_to_document(osv.osv): + + _name = 'document.email' + _description = "Emails to Documents Gateway" + + _columns = { + 'name':fields.char('Name', size=64, required=True, readonly=False), + 'user_id':fields.many2one('res.users', 'User', required=True), + 'directory_id':fields.many2one('document.directory', 'Directory', required=True), + 'accept_files':fields.char('File Extension', size=1024, required=True), + 'note': fields.text('Description'), + 'server_id': fields.many2one('email.server',"Mail Server", select=True), + } + + _defaults = { + 'accept_files': lambda *a: "['txt', 'ppt', 'doc', 'xls', 'pdf', 'jpg', 'png']", + 'user_id': lambda self, cr, uid, ctx: uid, + } + + _sql_constraints = [ + ('name_uniq', 'unique (user_id, server_id)', 'You can not configure one serve for multiple directory !'), + ] + + def message_new(self, cr, uid, msg, context): + """ + Automatically calls when new email message arrives + + @param self: The object pointer + @param cr: the current row, from the database cursor, + @param uid: the current user’s ID for security checks + """ + server_id = context.get('server_id', False) + file_pool = self.pool.get('ir.attachment') + if server_id: + ids = self.search(cr, uid, [('server_id', '=', server_id)]) + id = self.browse(cr, uid, ids[0]).directory_id.id + + partner = self.pool.get('email.server.tools').get_partner(cr, uid, msg.get('from'), context) + + attachents = msg.get('attachments', []) + for attactment in attachents: + data_attach = { + 'name': attactment, + 'datas':binascii.b2a_base64(str(attachents.get(attactment))), + 'datas_fname': attactment, + 'description': msg.get('body', 'Mail attachment'), + 'parent_id': id, + 'partner_id':partner.get('partner_id', False), + 'res_model': 'document.directory', + 'res_id': id, + } + file_pool.create(cr, uid, data_attach) + + return id + return 0 + + def message_update(self, cr, uid, ids, vals={}, msg="", default_act=None, context={}): + """ + @param self: The object pointer + @param cr: the current row, from the database cursor, + @param uid: the current user’s ID for security checks, + @param ids: List of update mail’s IDs + """ + + return True +email_to_document() + +class document_directory(osv.osv): + _inherit = 'document.directory' + + _columns = { + 'email_ids':fields.one2many('document.email', 'directory_id', 'Document to Email', required=False), + } +document_directory() diff --git a/addons/document_email/document_email.xml b/addons/document_email/document_email.xml new file mode 100644 index 00000000000..9dd550acd7c --- /dev/null +++ b/addons/document_email/document_email.xml @@ -0,0 +1,103 @@ + + + + + + document.directory + document.directory + form + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ + + document.email.tree + document.email + tree + + + + + + + + + + + document.email.form + document.email + form + +
+ + + + + + + + + + + + + + + + + + + +
+
+
+ + + Email to Document + document.email + form + tree,form + + {} + [] + + + + +
+