From bb5f7d384d574461fc031de1cf41181a5bd6a90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Jun 2012 16:12:54 +0200 Subject: [IMP] crm_lead, crm_claim, crm_fundraising, crm_helpdesk, hr_recruitment, project_issue, project_mailgate: cleaned and updated message_new and message_update to have a cleaner mailgate. Deleted references to state update. bzr revid: tde@openerp.com-20120604141254-4m2tnzwi88w8h2aj --- addons/project_mailgate/project_mailgate.py | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'addons/project_mailgate/project_mailgate.py') diff --git a/addons/project_mailgate/project_mailgate.py b/addons/project_mailgate/project_mailgate.py index a36366f450e..0ca2687b7f0 100644 --- a/addons/project_mailgate/project_mailgate.py +++ b/addons/project_mailgate/project_mailgate.py @@ -19,30 +19,35 @@ # ############################################################################## +import binascii from osv import fields, osv from tools.translate import _ import tools -import binascii - class project_tasks(osv.osv): _inherit = 'project.task' 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') - msg_from = msg.get('from') - data = { + """ Overrides mail_thread message_new that is called by the mailgateway + through message_process. + This override updates the document according to the email. + """ + if custom_values is None: custom_values = {} + custom_values.update({ 'name': subject, 'planned_hours': 0.0, - } - data.update(self.message_partner_by_email(cr, uid, msg_from)) - self.write(cr, uid, [res_id], data, context) - return res_id - - def message_update(self, cr, uid, ids, msg, data={}, default_act='pending'): - act = 'do_'+default_act + 'subject': msg.get('subject'), + }) + custom_values.update(self.message_partner_by_email(cr, uid, msg.get('from', False), context=context)) + return super(project_tasks,self).message_new(cr, uid, msg, custom_values=custom_values, context=context) + def message_update(self, cr, uid, ids, msg, update_vals=None, context=None): + """ Overrides mail_thread message_update that is called by the mailgateway + through message_process. + This method updates the task according to the email. + """ + if update_vals is None: update_vals = {} + act = False maps = { 'cost':'planned_hours', } @@ -54,17 +59,15 @@ class project_tasks(osv.osv): field = maps.get(match) if field: try: - data[field] = float(res.group(2).lower()) + update_vals[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_note(cr, uid, [res_id], body=msg, context=context) - return True + if act: + getattr(self,act)(cr, uid, ids, context=context) + return super(project_tasks,self).message_update(cr, uid, msg, update_vals=update_vals, 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) @@ -74,5 +77,5 @@ class project_tasks(osv.osv): followers[task.id] = filter(None, task_followers) return followers -project_tasks() + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: -- cgit v1.2.3