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/100] [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/100] [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/100] [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/100] [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/100] [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/100] [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"/> - or Import + + or Import + From 376014e00f9dceed23a804ecfc4ba8b1196f4c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 2 Jul 2012 18:13:06 +0200 Subject: [PATCH 072/100] [DOC] mail.thread: added some comments. bzr revid: tde@openerp.com-20120702161306-az3en2qc1330yn2r --- addons/mail/doc/mail_state.rst | 2 +- addons/mail/ir_needaction.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/mail/doc/mail_state.rst b/addons/mail/doc/mail_state.rst index bd8052656d2..527a31ba835 100644 --- a/addons/mail/doc/mail_state.rst +++ b/addons/mail/doc/mail_state.rst @@ -24,5 +24,5 @@ mechanism [REF]. result = super(ir_needaction_mixin, self).get_needaction_user_ids(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): if obj.message_state == False and obj.user_id: - result[obj.id].add(obj.user_id.id) + result[obj.id].append(obj.user_id.id) return result diff --git a/addons/mail/ir_needaction.py b/addons/mail/ir_needaction.py index ce306050e26..8193ac4f385 100644 --- a/addons/mail/ir_needaction.py +++ b/addons/mail/ir_needaction.py @@ -22,15 +22,18 @@ from osv import osv class ir_needaction_mixin(osv.Model): - """ Update of res.users class - - add a preference about sending emails about notificatoins - - make a new user follow itself + """ Update of ir.needaction_mixin class + - override the get_needaction_user_ids method to define the default + mail gateway need_action: when the object is unread, the object + responsible has an action to perform. """ _name = 'ir.needaction_mixin' _inherit = ['ir.needaction_mixin'] def get_needaction_user_ids(self, cr, uid, ids, context=None): - """ Returns the user_ids that have to perform an action + """ Returns the user_ids that have to perform an action. It the + document mail state is unread (False), return object.user_id.id + as need_action uid. :return: dict { record_id: [user_ids], } """ result = super(ir_needaction_mixin, self).get_needaction_user_ids(cr, uid, ids, context=context) From 1ac5f6fa99fb15a1f58c1f7232ef9e0a803a63c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 2 Jul 2012 18:13:23 +0200 Subject: [PATCH 073/100] [REVIEW] Some cleaning after review and before merging. bzr revid: tde@openerp.com-20120702161323-wvd0j6ng3dz56ifj --- addons/mail/mail_thread.py | 2 +- addons/project/project.py | 4 +++- addons/project_issue/project_issue_demo.xml | 2 +- addons/purchase/purchase.py | 2 +- addons/sale/sale.py | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index f69ccb39d7b..5668709af17 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -584,7 +584,7 @@ class mail_thread(osv.Model): # referenced thread was not found, we'll have to create a new one res_id = False if not res_id: - res_id = int(create_record(msg)) + res_id = create_record(msg) # To forward the email to other followers self.message_forward(cr, uid, model, [res_id], msg_txt, context=context) return res_id diff --git a/addons/project/project.py b/addons/project/project.py index f614d257594..487daa834bb 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -1138,7 +1138,9 @@ class task(base_stage, osv.osv): return 'Task' def get_needaction_user_ids(self, cr, uid, ids, context=None): - """ Returns the user_ids that have to perform an action + """ Returns the user_ids that have to perform an action. + Add to the previous results given by super the document responsible + when in draft mode. :return: dict { record_id: [user_ids], } """ result = super(task, self).get_needaction_user_ids(cr, uid, ids, context=context) diff --git a/addons/project_issue/project_issue_demo.xml b/addons/project_issue/project_issue_demo.xml index 9b7b5a6761d..b3fb4582cf2 100644 --- a/addons/project_issue/project_issue_demo.xml +++ b/addons/project_issue/project_issue_demo.xml @@ -227,7 +227,7 @@ - + diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 7bb56d2f351..e74ca83a92b 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -736,7 +736,7 @@ class purchase_order(osv.osv): result = super(purchase_order, self).get_needaction_user_ids(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): if obj.state == 'approved': - result[obj.id] = [obj.validator.id] + result[obj.id].append(obj.validator.id) return result def create_send_note(self, cr, uid, ids, context=None): diff --git a/addons/sale/sale.py b/addons/sale/sale.py index d6c6caca933..0a3ebbe72ac 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1025,7 +1025,7 @@ class sale_order(osv.osv): result = super(sale_order, self).get_needaction_user_ids(cr, uid, ids, context=context) for obj in self.browse(cr, uid, ids, context=context): if (obj.state == 'manual' or obj.state == 'progress'): - result[obj.id] = [obj.user_id.id] + result[obj.id].append(obj.user_id.id) return result def create_send_note(self, cr, uid, ids, context=None): From 9739a2fda5fe2cb5838967b6783898a901dadff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 2 Jul 2012 18:16:22 +0200 Subject: [PATCH 074/100] [CLEAN] crm_lead_view: removed debug and test code in views (buttons and fields). bzr revid: tde@openerp.com-20120702161622-u42h97or9yu7wl4w --- addons/crm/crm_lead_view.xml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index cef33be0240..629d2f43446 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -127,10 +127,6 @@ states="cancel"/>