mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-26 18:38:41 -06:00
Merge remote-tracking branch 'file_email/7.0' into 8.0-external_file_sync
This commit is contained in:
commit
1abf6202ca
24
file_email/__init__.py
Normal file
24
file_email/__init__.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# file_email for OpenERP
|
||||||
|
# Copyright (C) 2012-TODAY Akretion <http://www.akretion.com>.
|
||||||
|
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
import file_document
|
||||||
|
import fetchmail
|
44
file_email/__openerp__.py
Normal file
44
file_email/__openerp__.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# file_email for OpenERP
|
||||||
|
# Copyright (C) 2012-TODAY Akretion <http://www.akretion.com>.
|
||||||
|
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
{
|
||||||
|
'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 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_document', 'fetchmail'],
|
||||||
|
'init_xml': [],
|
||||||
|
'update_xml': [
|
||||||
|
"fetchmail_view.xml",
|
||||||
|
"file_document_view.xml",
|
||||||
|
],
|
||||||
|
'demo_xml': [],
|
||||||
|
'installable': True,
|
||||||
|
'active': False,
|
||||||
|
}
|
62
file_email/fetchmail.py
Normal file
62
file_email/fetchmail.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# file_email for OpenERP
|
||||||
|
# Copyright (C) 2013 Akretion (http://www.akretion.com).
|
||||||
|
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
from openerp.osv import fields, orm
|
||||||
|
|
||||||
|
|
||||||
|
class fetchmail_server(orm.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'),
|
||||||
|
'company_id': fields.many2one('res.company', 'Company', required=True),#Why this field do not exist by default?
|
||||||
|
'file_document_condition_ids': fields.one2many('file.document.condition', 'server_id', 'File Document ')
|
||||||
|
}
|
||||||
|
|
||||||
|
_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):
|
||||||
|
for server_id in ids:
|
||||||
|
ctx = self.get_context_for_server(cr, uid, server_id, context=context)
|
||||||
|
super(fetchmail_server, self).fetch_mail(cr, uid, [server_id], context=ctx)
|
||||||
|
return True
|
22
file_email/fetchmail_view.xml
Normal file
22
file_email/fetchmail_view.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="view_email_server_form">
|
||||||
|
<field name="model">fetchmail.server</field>
|
||||||
|
<field name="inherit_id" ref="fetchmail.view_email_server_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="date" position="after">
|
||||||
|
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||||
|
</field>
|
||||||
|
<field name="object_id" position="after">
|
||||||
|
<field name="file_type"/> <!-- TODO attrs="{'invisible': [('object_id','!=', 'file.document')]}"/>-->
|
||||||
|
</field>
|
||||||
|
<field name="action_id" position="after">
|
||||||
|
<field name="file_document_condition_ids" nolabel="1"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
153
file_email/file_document.py
Normal file
153
file_email/file_document.py
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
###############################################################################
|
||||||
|
#
|
||||||
|
# file_email for OpenERP
|
||||||
|
# Copyright (C) 2012-TODAY Akretion <http://www.akretion.com>.
|
||||||
|
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
||||||
|
#
|
||||||
|
# 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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
from openerp.osv import fields, orm
|
||||||
|
import base64
|
||||||
|
|
||||||
|
|
||||||
|
class file_document(orm.Model):
|
||||||
|
_inherit = "file.document"
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'fetchmail_server_id': fields.many2one('fetchmail.server', '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 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 _get_file_document_data(self, cr, uid, condition, msg, att, context=None):
|
||||||
|
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])
|
||||||
|
}
|
||||||
|
return values
|
||||||
|
|
||||||
|
def prepare_data_from_basic_condition(self, cr, uid, condition, msg, context=None):
|
||||||
|
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_file_document_data(cr, uid, condition, msg, att, context=context)
|
||||||
|
break
|
||||||
|
return vals
|
||||||
|
|
||||||
|
|
||||||
|
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 document data
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
res = []
|
||||||
|
server_id = context.get('default_fetchmail_server_id', False)
|
||||||
|
doc_file_condition_obj = self.pool.get('file.document.condition')
|
||||||
|
cond_ids = doc_file_condition_obj.search(cr, uid, [('server_id', '=', server_id)])
|
||||||
|
if cond_ids:
|
||||||
|
for cond in doc_file_condition_obj.browse(cr, uid, cond_ids):
|
||||||
|
if cond.type == 'normal':
|
||||||
|
vals = self.prepare_data_from_basic_condition(cr, uid, cond, msg, context=context)
|
||||||
|
else:
|
||||||
|
vals = getattr(self, cond.type)(cr, uid, cond, msg, context=context)
|
||||||
|
if vals:
|
||||||
|
res.append(vals)
|
||||||
|
return res
|
||||||
|
|
||||||
|
def message_new(self, cr, uid, msg, custom_values, context=None):
|
||||||
|
created_ids = []
|
||||||
|
res = self._prepare_data_for_file_document(cr, uid, msg, context=context)
|
||||||
|
if res:
|
||||||
|
for vals in res:
|
||||||
|
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))
|
||||||
|
cr.commit()
|
||||||
|
context['created_ids'] = created_ids
|
||||||
|
return created_ids[0]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class file_document_condition(orm.Model):
|
||||||
|
_name = "file.document.condition"
|
||||||
|
_description = "File Document Conditions"
|
||||||
|
|
||||||
|
def _get_file_document_condition_type(self, cr, uid, context=None):
|
||||||
|
return self.get_file_document_condition_type(cr, uid, context=context)
|
||||||
|
|
||||||
|
def get_file_document_condition_type(self, cr, uid, context=None):
|
||||||
|
return [('normal', 'Normal')]
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'from_email': fields.char('Email', size=64),
|
||||||
|
'mail_subject': fields.char('Mail Subject', size=64),
|
||||||
|
'type': fields.selection(_get_file_document_condition_type,
|
||||||
|
'Type', help="Create your own type if the normal type \
|
||||||
|
do not correspond to your need", required=True),
|
||||||
|
'file_extension' : fields.char('File Extension', size=64,
|
||||||
|
help="File extension or file name",
|
||||||
|
required=True),
|
||||||
|
'server_id': fields.many2one('fetchmail.server', 'Server Mail'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_defaults = {
|
||||||
|
'type': 'normal'
|
||||||
|
}
|
||||||
|
|
61
file_email/file_document_view.xml
Normal file
61
file_email/file_document_view.xml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<!-- SEARCH -->
|
||||||
|
<record id="file_document_view_search" model="ir.ui.view">
|
||||||
|
<field name="name">file.document.search</field>
|
||||||
|
<field name="model">file.document</field>
|
||||||
|
<field name="type">search</field>
|
||||||
|
<field name="inherit_id" ref="file_document.file_document_view_search"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="ext_id" position="after">
|
||||||
|
<field name="fetchmail_server_id"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- Views and menus for the new object prepare.file.document -->
|
||||||
|
<record id="view_file_document_condition_tree" model="ir.ui.view">
|
||||||
|
<field name="name">view_file_document_condition_tree</field>
|
||||||
|
<field name="model">file.document.condition</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Configuration for File Document">
|
||||||
|
<field name="from_email"/>
|
||||||
|
<field name="mail_subject"/>
|
||||||
|
<field name="type"/>
|
||||||
|
<field name="file_extension"/>
|
||||||
|
<field name="server_id"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_file_document_condition_form" model="ir.ui.view">
|
||||||
|
<field name="name">view_file_document_condition_form</field>
|
||||||
|
<field name="model">file.document.condition</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Configuration for File Document">
|
||||||
|
<field name="from_email" attrs="{'required': [('type', '=', 'normal')]}"/>
|
||||||
|
<field name="mail_subject" attrs="{'required': [('type', '=', 'normal')]}"/>
|
||||||
|
<field name="type"/>
|
||||||
|
<field name="file_extension"/>
|
||||||
|
<field name="server_id"/>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_file_document_configuration" model="ir.actions.act_window">
|
||||||
|
<field name="name">Configuration</field>
|
||||||
|
<field name="res_model">file.document.condition</field>
|
||||||
|
<field name="view_type">form</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem id="menu_file_document_configuration"
|
||||||
|
action="action_file_document_configuration"
|
||||||
|
parent="file_document.menu_file_exchange_root"
|
||||||
|
sequence="50" />
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user