From 587f3ff41da36c332e94c2552e61470e4199d717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Jun 2012 10:10:16 +0200 Subject: [PATCH 001/164] [ADD] mail.thread: added boolean field for read/unread. bzr revid: tde@openerp.com-20120604081016-3x21acf0zccgeyhv --- addons/mail/mail_thread.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index b1b6c68e4cc..b821edb5165 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -72,6 +72,8 @@ class mail_thread(osv.osv): _columns = { 'message_ids': fields.function(_get_message_ids, method=True, type='one2many', obj='mail.message', string='Temp messages', _fields_id = 'res_id'), + 'thread_read': fields.boolean('Read', + help="When checked, new messages require your attention."), } #------------------------------------------------------ From fcf07cc65f9dfe618c38ccf9e107c2ab85d539a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Jun 2012 11:33:24 +0200 Subject: [PATCH 002/164] [IMP] mail_thread: thread_read -> thread_is_read; added API methods to mark read/unread; small code cleaning. bzr revid: tde@openerp.com-20120604093324-x3mtl4lu4883lqz0 --- addons/mail/mail_thread.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index b821edb5165..3deb7f25769 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -71,8 +71,9 @@ class mail_thread(osv.osv): # OpenChatter: message_ids is a dummy field that should not be used _columns = { 'message_ids': fields.function(_get_message_ids, method=True, - type='one2many', obj='mail.message', string='Temp messages', _fields_id = 'res_id'), - 'thread_read': fields.boolean('Read', + type='one2many', obj='mail.message', string='Temp messages', _fields_id = 'res_id', + help="Functional field holding messages related to the current document."), + 'thread_is_read': fields.boolean('Read', help="When checked, new messages require your attention."), } @@ -81,10 +82,11 @@ class mail_thread(osv.osv): #------------------------------------------------------ def create(self, cr, uid, vals, context=None): - """Automatically subscribe the creator""" - thread_id = super(mail_thread, self).create(cr, uid, vals, context=context); - self.message_subscribe(cr, uid, [thread_id], [uid], context=context) - return thread_id; + """Automatically subscribe the creator """ + thread_id = super(mail_thread, self).create(cr, uid, vals, context=context) + if thread_id: + self.message_subscribe(cr, uid, [thread_id], [uid], context=context) + return thread_id def write(self, cr, uid, ids, vals, context=None): """Automatically subscribe the writer""" @@ -103,8 +105,6 @@ class mail_thread(osv.osv): a foreign key with a 'cascade' ondelete attribute. Notifications will be deleted with messages """ - if context is None: - context = {} subscr_obj = self.pool.get('mail.subscription') msg_obj = self.pool.get('mail.message') # delete subscriptions @@ -121,13 +121,14 @@ class mail_thread(osv.osv): #------------------------------------------------------ def message_create(self, cr, uid, thread_id, vals, context=None): - """OpenSocial: wrapper of mail.message create method + """ OpenChatter: wrapper of mail.message create method - creates the mail.message - automatically subscribe the message writer - push the message to subscribed users """ if context is None: context = {} + message_obj = self.pool.get('mail.message') subscription_obj = self.pool.get('mail.subscription') notification_obj = self.pool.get('mail.notification') @@ -793,4 +794,15 @@ class mail_thread(osv.osv): to_del_notif_ids = notif_obj.search(cr, uid, ['&', ('user_id', '=', uid), ('message_id', 'in', notif_msg_ids)], context=context) return notif_obj.unlink(cr, uid, to_del_notif_ids, context=context) + #------------------------------------------------------ + # Thread_state + #------------------------------------------------------ + + def message_mark_as_read(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'thread_is_read': True}, context=context) + + def message_mark_as_unread(self, cr, uid, ids, context=None): + return self.write(cr, uid, ids, {'thread_is_read': False}, context=context) + + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From 9aacbba3da01710a369bc13c81c8b1f929e8ed36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Jun 2012 12:20:49 +0200 Subject: [PATCH 003/164] [IMP] crm_lead: updated mail_gateway, removed state update as this will be managed by mail.thread. bzr revid: tde@openerp.com-20120604102049-0ytmcv3dy8t2pc97 --- addons/crm/crm_lead.py | 116 ++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 59 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 0b58975bca2..93c6ac48d29 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -756,64 +756,6 @@ class crm_lead(base_stage, osv.osv): 'type': 'ir.actions.act_window', } - - def message_new(self, cr, uid, msg, custom_values=None, context=None): - """Automatically calls when new email message arrives""" - res_id = super(crm_lead, self).message_new(cr, uid, msg, custom_values=custom_values, context=context) - subject = msg.get('subject') or _("No Subject") - body = msg.get('body_text') - - msg_from = msg.get('from') - priority = msg.get('priority') - vals = { - 'name': subject, - 'email_from': msg_from, - 'email_cc': msg.get('cc'), - 'description': body, - 'user_id': False, - } - if priority: - vals['priority'] = priority - vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False))) - self.write(cr, uid, [res_id], vals, context) - return res_id - - def message_update(self, cr, uid, ids, msg, vals=None, default_act='pending', context=None): - if isinstance(ids, (str, int, long)): - ids = [ids] - if vals == None: - vals = {} - super(crm_lead, self).message_update(cr, uid, ids, msg, context=context) - - if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES): - vals['priority'] = msg.get('priority') - maps = { - 'cost':'planned_cost', - 'revenue': 'planned_revenue', - 'probability':'probability' - } - vls = {} - for line in msg['body_text'].split('\n'): - line = line.strip() - res = tools.misc.command_re.match(line) - if res and maps.get(res.group(1).lower()): - key = maps.get(res.group(1).lower()) - vls[key] = res.group(2).lower() - vals.update(vls) - - # Unfortunately the API is based on lists - # but we want to update the state based on the - # previous state, so we have to loop: - for case in self.browse(cr, uid, ids, context=context): - values = dict(vals) - if case.state in CRM_LEAD_PENDING_STATES: - #re-open - values.update(state=crm.AVAILABLE_STATES[1][0]) - if not case.date_open: - values['date_open'] = time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) - res = self.write(cr, uid, [case.id], values, context=context) - return res - def action_makeMeeting(self, cr, uid, ids, context=None): """ This opens Meeting's calendar view to schedule meeting on current Opportunity @@ -868,7 +810,63 @@ class crm_lead(base_stage, osv.osv): if stage.on_change: vals['probability'] = stage.probability return super(crm_lead,self).write(cr, uid, ids, vals, context) - + + # ---------------------------------------- + # Mail Gateway + # ---------------------------------------- + + def message_new(self, cr, uid, msg, custom_values=None, context=None): + """ mail_thread message_new that is called by the mailgateway: + - create a new record of the related model + - add the message to the thread + This override also updates the lead according to the email. + """ + res_id = super(crm_lead, self).message_new(cr, uid, msg, custom_values=custom_values, context=context) + + name = msg.get('subject') or _("No Subject") + description = msg.get('body') + email_from = msg.get('from') + email_cc = msg.get('cc') + vals = { + 'name': name, + 'email_from': email_from, + 'email_cc': email_cc, + 'description': description, + 'user_id': False, + } + if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES): + vals['priority'] = msg.get('priority') + vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False), context=context)) + self.write(cr, uid, [res_id], vals, context=context) + return res_id + + def message_update(self, cr, uid, ids, msg, vals=None, default_act='pending', context=None): + """ mail_thread message_update that is called by the mailgateway: + - add the message to the thread + This override also updates the lead according to the email. + """ + if isinstance(ids, (str, int, long)): + ids = [ids] + if vals == None: + vals = {} + update_res = super(crm_lead, self).message_update(cr, uid, ids, msg, context=context) + + if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES): + vals['priority'] = msg.get('priority') + maps = { + 'cost':'planned_cost', + 'revenue': 'planned_revenue', + 'probability':'probability' + } + for line in msg['body_text'].split('\n'): + line = line.strip() + res = tools.misc.command_re.match(line) + if res and maps.get(res.group(1).lower()): + key = maps.get(res.group(1).lower()) + vals[key] = res.group(2).lower() + self.write(cr, uid, ids, vals, context=context) + return update_res + # ---------------------------------------- # OpenChatter methods and notifications # ---------------------------------------- From 445b690488e3aeb7ddf87c3692008b033c54496c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Jun 2012 12:24:35 +0200 Subject: [PATCH 004/164] [IMP] mail_thread: message_process now automatically set the thread as unread. bzr revid: tde@openerp.com-20120604102435-hcdo3i6oqdhu6j8j --- addons/mail/mail_thread.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 3deb7f25769..d52804308a3 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -535,6 +535,8 @@ class mail_thread(osv.osv): res_id = create_record(msg) #To forward the email to other followers self.message_forward(cr, uid, model, [res_id], msg_txt, context=context) + # Set as Unread + self.message_mark_as_unreadcr, uid, [res_id], context=context) return res_id def message_new(self, cr, uid, msg_dict, custom_values=None, context=None): From 0bf38a496c6bd4c8f84c0881b63ecb9f91441e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 4 Jun 2012 12:27:51 +0200 Subject: [PATCH 005/164] [FIX] mail_thread: added forgotten '\('. bzr revid: tde@openerp.com-20120604102751-b61hsx03guhpbye0 --- addons/mail/mail_thread.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index d52804308a3..bfe0bc9559a 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -536,7 +536,7 @@ class mail_thread(osv.osv): #To forward the email to other followers self.message_forward(cr, uid, model, [res_id], msg_txt, context=context) # Set as Unread - self.message_mark_as_unreadcr, uid, [res_id], context=context) + self.message_mark_as_unread(cr, uid, [res_id], context=context) return res_id def message_new(self, cr, uid, msg_dict, custom_values=None, context=None): 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: [PATCH 006/164] [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/crm/crm_lead.py | 58 +++++++--------- addons/crm/crm_lead_view.xml | 6 ++ addons/crm_claim/crm_claim.py | 66 ++++++++---------- addons/crm_fundraising/crm_fundraising.py | 29 ++++---- addons/crm_helpdesk/crm_helpdesk.py | 61 ++++++++-------- addons/hr_recruitment/hr_recruitment.py | 65 +++++++++-------- addons/mail/mail_thread.py | 33 ++++++--- addons/project_issue/project_issue.py | 77 +++++++++------------ addons/project_mailgate/project_mailgate.py | 43 ++++++------ 9 files changed, 216 insertions(+), 222 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 93c6ac48d29..71432c284ae 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -262,11 +262,10 @@ class crm_lead(base_stage, osv.osv): def get_needaction_user_ids(self, cr, uid, ids, context=None): result = dict.fromkeys(ids, []) for obj in self.browse(cr, uid, ids, context=context): - # salesman must perform an action when in draft mode - if obj.state == 'draft' and obj.user_id: + if obj.thread_is_read == False and hasattr(obj, 'user_id') and obj.user_id: result[obj.id] = [obj.user_id.id] return result - + def create(self, cr, uid, vals, context=None): obj_id = super(crm_lead, self).create(cr, uid, vals, context) self.create_send_note(cr, uid, [obj_id], context=context) @@ -816,56 +815,47 @@ class crm_lead(base_stage, osv.osv): # ---------------------------------------- def message_new(self, cr, uid, msg, custom_values=None, context=None): - """ mail_thread message_new that is called by the mailgateway: - - create a new record of the related model - - add the message to the thread - This override also updates the lead according to the email. + """ Overrides mail_thread message_new that is called by the mailgateway + through message_process. + This override updates the document according to the email. """ - res_id = super(crm_lead, self).message_new(cr, uid, msg, custom_values=custom_values, context=context) - - name = msg.get('subject') or _("No Subject") - description = msg.get('body') - email_from = msg.get('from') - email_cc = msg.get('cc') - vals = { - 'name': name, - 'email_from': email_from, - 'email_cc': email_cc, - 'description': description, + if custom_values is None: custom_values = {} + custom_values.update({ + 'name': msg.get('subject') or _("No Subject"), + 'description': msg.get('body_text'), + 'email_from': msg.get('from'), + 'email_cc': msg.get('cc'), 'user_id': False, - } + }) if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES): - vals['priority'] = msg.get('priority') - vals.update(self.message_partner_by_email(cr, uid, msg.get('from', False), context=context)) - self.write(cr, uid, [res_id], vals, context=context) - return res_id + custom_values['priority'] = msg.get('priority') + custom_values.update(self.message_partner_by_email(cr, uid, msg.get('from', False), context=context)) + return super(crm_lead, self).message_new(cr, uid, msg, custom_values=custom_values, context=context) - def message_update(self, cr, uid, ids, msg, vals=None, default_act='pending', context=None): - """ mail_thread message_update that is called by the mailgateway: - - add the message to the thread - This override also updates the lead according to the email. + 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 document according to the email. """ if isinstance(ids, (str, int, long)): ids = [ids] - if vals == None: - vals = {} - update_res = super(crm_lead, self).message_update(cr, uid, ids, msg, context=context) + if update_vals is None: update_vals = {} if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES): vals['priority'] = msg.get('priority') maps = { 'cost':'planned_cost', 'revenue': 'planned_revenue', - 'probability':'probability' + 'probability':'probability', } - for line in msg['body_text'].split('\n'): + for line in msg.get('body_text', '').split('\n'): line = line.strip() res = tools.misc.command_re.match(line) if res and maps.get(res.group(1).lower()): key = maps.get(res.group(1).lower()) vals[key] = res.group(2).lower() - self.write(cr, uid, ids, vals, context=context) - return update_res + + return super(crm_lead, self).message_update(cr, uid, ids, msg, update_vals=update_vals, context=context) # ---------------------------------------- # OpenChatter methods and notifications diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 07e295d4e4c..3308e080a57 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -70,6 +70,10 @@ states="cancel"/> - -