diff options
| author | Stephane Wirtel <stw@openerp.com> | 2011-09-13 16:00:16 +0200 |
|---|---|---|
| committer | Stephane Wirtel <stw@openerp.com> | 2011-09-13 16:00:16 +0200 |
| commit | 2a59ce92e3ea35cca00a314d44556b522b3c2fa8 (patch) | |
| tree | 6e7eec2157a513284e6740a95f2e39b7f04aef79 /addons/project_mailgate | |
| parent | 8a2bc42c3c45b4d3c94070a29fa76636256f3da7 (diff) | |
| parent | 2a40f9a4997eecc6f997ab0e43dc6334263b9cad (diff) | |
[MERGE] Email Framework - lp:~openerp-dev/openobject-addons/trunk-emails-unified
bzr revid: stw@openerp.com-20110913140016-zzfynrnjdaap0tfb
Diffstat (limited to 'addons/project_mailgate')
| -rw-r--r-- | addons/project_mailgate/__openerp__.py | 20 | ||||
| -rw-r--r-- | addons/project_mailgate/project_mailgate.py | 128 | ||||
| -rw-r--r-- | addons/project_mailgate/project_mailgate_view.xml | 11 | ||||
| -rw-r--r-- | addons/project_mailgate/security/ir.model.access.csv | 4 |
4 files changed, 67 insertions, 96 deletions
diff --git a/addons/project_mailgate/__openerp__.py b/addons/project_mailgate/__openerp__.py index 4551d19bb1f..76ff6dbbc47 100644 --- a/addons/project_mailgate/__openerp__.py +++ b/addons/project_mailgate/__openerp__.py @@ -21,20 +21,28 @@ { - "name": "Project MailGateWay", + "name": "Project Tasks - Mail Integration", "version": "1.1", "author": "OpenERP SA", "website": "http://www.openerp.com", "category": "Project Management", 'complexity': "easy", "images": ["images/project_mailgate_task.jpeg"], - "depends": ["project", "mail_gateway"], + "depends": ["project", "mail"], "description": """ -This module is an interface that synchronises mails with OpenERP Project Task. -============================================================================== +This module can automatically create Project Tasks based on incoming emails +=========================================================================== + +Allows creating tasks based on new emails arriving at a given mailbox, +similarly to what the CRM application has for Leads/Opportunities. +There are two common alternatives to configure the mailbox integration: + + * Install the ``fetchmail`` module and configure a new mailbox, then select + ``Project Tasks`` as the target for incoming emails. + * Set it up manually on your mail server based on the 'mail gateway' script + provided in the ``mail`` module - and connect it to the `project.task` model. + -It allows creating tasks as soon as a new mail arrives in our configured mail server. -Moreover, it keeps track of all further communications and task states. """, "init_xml": [], "update_xml": ["security/ir.model.access.csv", diff --git a/addons/project_mailgate/project_mailgate.py b/addons/project_mailgate/project_mailgate.py index 2325d533c03..9715a32c151 100644 --- a/addons/project_mailgate/project_mailgate.py +++ b/addons/project_mailgate/project_mailgate.py @@ -21,121 +21,85 @@ from osv import fields, osv from tools.translate import _ +import tools import binascii class project_tasks(osv.osv): _name = "project.task" - _inherit = ['mailgate.thread', 'project.task'] + _inherit = ['mail.thread','project.task'] - _columns={ - 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model', '=', _name)], readonly=True), - } + _columns = { + 'message_ids': fields.one2many('mail.message', 'res_id', 'Messages', domain=[('model','=',_name)], readonly=True), + } - def message_new(self, cr, uid, msg, context=None): -# """ -# 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 -# """ - mailgate_obj = self.pool.get('email.server.tools') + def message_new(self, cr, uid, msg, custom_values=None, context=None): + res_id = super(project_tasks,self).message_new(cr, uid, msg, custom_values=custom_values, context=context) subject = msg.get('subject') - body = msg.get('body') + body = msg.get('body_text') msg_from = msg.get('from') - #TODO map email priority with openerp task priority - priority = msg.get('priority') - data = { 'name': subject, 'description': body, 'planned_hours': 0.0, } - res = mailgate_obj.get_partner(cr, uid, msg_from) - if res: - data.update(res) - res = self.create(cr, uid, data) - - attachments = msg.get('attachments', []) - for attachment in attachments or []: - data_attach = { - 'name': attachment, - 'datas': binascii.b2a_base64(str(attachments.get(attachment))), - 'datas_fname': attachment, - 'description': 'Mail attachment', - 'res_model': self._name, - 'res_id': res, - } - self.pool.get('ir.attachment').create(cr, uid, data_attach) + data.update(self.message_partner_by_email(cr, uid, msg_from)) + self.write(cr, uid, [res_id], data, context) + return res_id - return res - - def message_update(self, cr, uid, id, msg, data={}, default_act='pending'): - mailgate_obj = self.pool.get('email.server.tools') - msg_actions, body_data = mailgate_obj.msg_act_get(msg) + def message_update(self, cr, uid, ids, msg, data={}, default_act='pending'): data.update({ - 'description': body_data, + 'description': msg['body_text'], }) act = 'do_'+default_act - if 'state' in msg_actions: - if msg_actions['state'] in ['draft', 'close', 'cancel', 'open', 'pending']: - act = 'do_' + msg_actions['state'] - - for k1, k2 in [('cost', 'planned_hours')]: - try: - data[k2] = float(msg_actions[k1]) - except: - pass - if 'priority' in msg_actions: - if msg_actions['priority'] in ('1', '2', '3', '4', '5'): - data['priority'] = msg_actions['priority'] - - self.write(cr, uid, [id], data) - getattr(self, act)(cr, uid, [id]) - return True - - def message_followers(self, cr, uid, ids, context=None): - res = [] - if isinstance(ids, (str, int, long)): - select = [ids] - else: - select = ids - for task in self.browse(cr, uid, select, context=context): - user_email = (task.user_id and task.user_id.user_email) or False - res += [(user_email, False, False, task.priority)] - if isinstance(ids, (str, int, long)): - return len(res) and res[0] or False - return res - - def msg_send(self, cr, uid, id, *args, **argv): + maps = { + 'cost':'planned_hours', + } + for line in msg['body_text'].split('\n'): + line = line.strip() + res = tools.misc.command_re.match(line) + if res: + match = res.group(1).lower() + field = maps.get(match) + if field: + try: + data[field] = float(res.group(2).lower()) + except (ValueError, TypeError): + pass + elif match.lower() == 'state' \ + and res.group(2).lower() in ['cancel','close','draft','open','pending']: + act = 'do_%s' % res.group(2).lower() + + self.write(cr, uid, ids, data, context=context) + getattr(self,act)(cr, uid, ids, context=context) + self.message_append_dict(cr, uid, [res_id], msg, context=context) return True - def _history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, email_from=False, message_id=False, attach=[], context=None): - mailgate_pool = self.pool.get('mailgate.thread') - return mailgate_pool.history(cr, uid, cases, keyword, history=history,\ - subject=subject, email=email, \ - details=details, email_from=email_from,\ - message_id=message_id, attach=attach, \ - context=context) + def message_thread_followers(self, cr, uid, ids, context=None): + followers = super(project_tasks,self).message_thread_followers(cr, uid, ids, context=context) + for task in self.browse(cr, uid, followers.keys(), context=context): + task_followers = set(followers[task.id]) + task_followers.add(task.user_id.user_email) + followers[task.id] = filter(None, task_followers) + return followers def do_draft(self, cr, uid, ids, context=None): res = super(project_tasks, self).do_draft(cr, uid, ids, context) tasks = self.browse(cr, uid, ids, context=context) - self._history(cr, uid, tasks, _('Draft'), context=context) + self.message_append(cr, uid, tasks, _('Draft'), context=context) return res def do_open(self, cr, uid, ids, context=None): res = super(project_tasks, self).do_open(cr, uid, ids, context) tasks = self.browse(cr, uid, ids, context=context) - self._history(cr, uid, tasks, _('Open'), context=context) + self.message_append(cr, uid, tasks, _('Open'), context=context) return res def do_pending(self, cr, uid, ids, context=None): res = super(project_tasks, self).do_pending(cr, uid, ids, context) tasks = self.browse(cr, uid, ids, context=context) - self._history(cr, uid, tasks, _('Pending'), context=context) + self.message_append(cr, uid, tasks, _('Pending'), context=context) return res def do_close(self, cr, uid, ids, context=None): @@ -143,13 +107,13 @@ class project_tasks(osv.osv): tasks = self.browse(cr, uid, ids, context=context) for task in tasks: if task.state == 'done': - self._history(cr, uid, tasks, _('Done'), context=context) + self.message_append(cr, uid, tasks, _('Done'), context=context) return res def do_cancel(self, cr, uid, ids, context=None): res = super(project_tasks, self).do_cancel(cr, uid, ids, context=context) tasks = self.browse(cr, uid, ids, context=context) - self._history(cr, uid, tasks, _('Cancel'), context=context) + self.message_append(cr, uid, tasks, _('Cancel'), context=context) return res project_tasks() diff --git a/addons/project_mailgate/project_mailgate_view.xml b/addons/project_mailgate/project_mailgate_view.xml index 8c8816ebbd5..c3cd4bf9db2 100644 --- a/addons/project_mailgate/project_mailgate_view.xml +++ b/addons/project_mailgate/project_mailgate_view.xml @@ -9,7 +9,7 @@ <field name="arch" type="xml"> <xpath expr="/form/notebook/page[@string='Extra Info']" position="before"> <page string="History"> - <field name="message_ids" colspan="4" nolabel="1" mode="tree,form"> + <field name="message_ids" colspan="4" nolabel="1" mode="tree,form" readonly="1"> <tree string="History"> <field name="display_text" string="History Information"/> </tree> @@ -19,15 +19,14 @@ <field name="date"/> <field name="email_to" widget="char" size="512"/> <field name="email_cc" widget="char" size="512"/> - <field name="name" colspan="4" widget="char" size="512"/> - <field name="history" invisible="1"/> + <field name="subject" colspan="4" widget="char" size="512"/> </group> <notebook colspan="4"> <page string="Details"> - <group attrs="{'invisible': [('history', '!=', True)]}"> - <field name="description" colspan="4" nolabel="1" height="250"/> + <group attrs="{'invisible': [('email_from', '=', False)]}"> + <field name="body_text" colspan="4" nolabel="1" height="250"/> </group> - <group attrs="{'invisible': [('history', '=', True)]}"> + <group attrs="{'invisible': [('email_from', '!=', False)]}"> <field name="display_text" colspan="4" nolabel="1" height="250"/> </group> </page> diff --git a/addons/project_mailgate/security/ir.model.access.csv b/addons/project_mailgate/security/ir.model.access.csv index 1a840d89e9a..cf9a08b958d 100644 --- a/addons/project_mailgate/security/ir.model.access.csv +++ b/addons/project_mailgate/security/ir.model.access.csv @@ -1,3 +1,3 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_mailgate_message_project_manager","project.mailgate.message.manager","mail_gateway.model_mailgate_message","project.group_project_manager",1,1,1,0 -"access_mailgate_message_project_user","project.mailgate.message.user","mail_gateway.model_mailgate_message","project.group_project_user",1,1,1,0 +"access_mail_message_project_manager","project.mail.message.manager","mail.model_mail_message","project.group_project_manager",1,1,1,0 +"access_mail_message_project_user","project.mail.message.user","mail.model_mail_message","project.group_project_user",1,1,1,0 |
