diff --git a/addons/analytic_contract_crm/analytic_contract_crm.py b/addons/analytic_contract_crm/analytic_contract_crm.py index fa93b7d2201..a69849faf36 100644 --- a/addons/analytic_contract_crm/analytic_contract_crm.py +++ b/addons/analytic_contract_crm/analytic_contract_crm.py @@ -27,6 +27,7 @@ class account_analytic_account(osv.osv): def create(self, cr, uid, vals, context=None): obj_id = super(account_analytic_account, self).create(cr, uid, vals, context=context) + # subscribe salesteam followers & subtypes to the contract self._subscribe_salesteam_followers_to_contract(cr, uid, [obj_id], context) if obj_id: self.create_send_note(cr, uid, [obj_id], context=context) @@ -36,6 +37,7 @@ class account_analytic_account(osv.osv): if isinstance(ids, (int, long)): ids = [ids] res = super(account_analytic_account, self).write(cr, uid, ids, vals, context=context) + # subscribe new salesteam followers & subtypes to the contract if vals.get('manager_id'): self._subscribe_salesteam_followers_to_contract(cr, uid, ids, context) return res @@ -47,11 +49,15 @@ class account_analytic_account(osv.osv): manager_id = record and record[0].manager_id or False if manager_id: if manager_id.default_section_id: + # fetch subscribers followers = [follow.id for follow in manager_id.default_section_id.message_follower_ids] contract_subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', False), ('res_model', '=', self._name)], context=context) contract_subtypes = subtype_obj.browse(cr, uid, contract_subtype_ids, context=context) + # fetch subscriptions follower_ids = follower_obj.search(cr, uid, [('res_model', '=', 'crm.case.section'), ('res_id', '=', manager_id.default_section_id.id)], context=context) + # when subscribe new salesteam update followers self.write(cr, uid, obj_id, {'message_follower_ids': [(6, 0, followers)]}, context=context) + # copy followers & select subtypes for follower in follower_obj.browse(cr, uid, follower_ids, context=context): if not follower.subtype_ids: continue diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index e8eaca3c4a3..3fdb2c7e57e 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -304,6 +304,7 @@ class crm_lead(base_stage, format_address, osv.osv): def create(self, cr, uid, vals, context=None): obj_id = super(crm_lead, self).create(cr, uid, vals, context) + # subscribe salesteam followers & subtypes to the lead self._subscribe_salesteam_followers_to_lead(cr, uid, [obj_id], context=context) self.create_send_note(cr, uid, [obj_id], context=context) return obj_id @@ -314,11 +315,16 @@ class crm_lead(base_stage, format_address, osv.osv): rec = self.browse(cr, uid, obj_id, context=context) section_id = rec and rec[0].section_id or False if section_id: + # fetch subscribers followers = [follow.id for follow in section_id.message_follower_ids] + # fetch subtypes lead_subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', False), ('res_model', '=', self._name)], context=context) lead_subtypes = subtype_obj.browse(cr, uid, lead_subtype_ids, context=context) + # fetch subscriptions follower_ids = follower_obj.search(cr, uid, [('res_model', '=', 'crm.case.section'), ('res_id', '=', section_id)], context=context) + # when subscribe new salesteam update followers self.write(cr, uid, obj_id, {'message_follower_ids': [(6, 0, followers)]}, context=context) + # copy followers & select subtypes for follower in follower_obj.browse(cr, uid, follower_ids, context=context): if not follower.subtype_ids: continue @@ -928,6 +934,7 @@ class crm_lead(base_stage, format_address, osv.osv): if stage.on_change: vals['probability'] = stage.probability res = super(crm_lead,self).write(cr, uid, ids, vals, context) + # subscribe new salesteam followers & subtypes to the lead if vals.get('section_id'): self._subscribe_salesteam_followers_to_lead(cr, uid, ids, context=context) return res diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py index 378c4752512..3f3b80b8f08 100644 --- a/addons/mail/mail_message.py +++ b/addons/mail/mail_message.py @@ -506,6 +506,7 @@ class mail_message(osv.Model): # fetch parent if threaded, sort messages for message in self.browse(cr, uid, ids, context=context): notified_partner_id = [user.id for user in message.notified_partner_ids] + # fatch only parent meassages & chiled messages which have notified_partner_id if not parent_id or notified_partner_id: message_id = message.id if message_id in message_tree: diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py index bb116807e29..1b6a408f8af 100644 --- a/addons/mail/tests/test_mail.py +++ b/addons/mail/tests/test_mail.py @@ -555,7 +555,9 @@ class test_mail(test_mail_mockup.TestMailMockups): msg_id8 = self.group_pigs.message_post(body='2-1-1', subtype='mt_comment', parent_id=msg_id4) msg_id9 = self.group_pigs.message_post(body='1-1-1', subtype='mt_comment', parent_id=msg_id3) msg_id10 = self.group_pigs.message_post(body='2-1-1', subtype='mt_comment', parent_id=msg_id4) + # list of child message id child_msg_id = [msg_id3, msg_id4,msg_id5,msg_id6,msg_id7,msg_id8,msg_id9,msg_id10] + # update notified_partner_ids in all child message for the subscribe message self.mail_message.write(cr, uid, child_msg_id, {'notified_partner_ids': [(6, 0, [user_admin.id])]}) msg_ids = [msg_id10, msg_id9, msg_id8, msg_id7, msg_id6, msg_id5, msg_id4, msg_id3, msg_id2, msg_id1, msg_id0] ordered_msg_ids = [msg_id2, msg_id4, msg_id6, msg_id8, msg_id10, msg_id1, msg_id3, msg_id5, msg_id7, msg_id9, msg_id0] diff --git a/addons/sale_crm/sale_crm.py b/addons/sale_crm/sale_crm.py index 75005c1f5e9..74383f45bd9 100644 --- a/addons/sale_crm/sale_crm.py +++ b/addons/sale_crm/sale_crm.py @@ -31,6 +31,7 @@ class sale_order(osv.osv): def create(self, cr, uid, vals, context=None): order = super(sale_order, self).create(cr, uid, vals, context=context) + # subscribe salesteam followers & subtypes to the sale order self._subscribe_salesteam_followers_to_order(cr, uid, [order], context=context) return order @@ -40,12 +41,15 @@ class sale_order(osv.osv): rec = self.browse(cr, uid, order, context=context) section_id = rec and rec[0].section_id or False if section_id: + # fetch subscribers followers = [follow.id for follow in section_id.message_follower_ids] order_subtype_ids = subtype_obj.search(cr, uid, ['|', ('res_model', '=', False), ('res_model', '=', self._name)], context=context) order_subtypes = subtype_obj.browse(cr, uid, order_subtype_ids, context=context) - followers = [follow.id for follow in section_id.message_follower_ids] + # fetch subscriptions follower_ids = follower_obj.search(cr, uid, [('res_model', '=', 'crm.case.section'), ('res_id', '=', section_id)], context=context) + # when subscribe new salesteam update followers self.write(cr, uid, order, {'message_follower_ids': [(6, 0, followers)]}, context=context) + # copy followers & select subtypes for follower in follower_obj.browse(cr, uid, follower_ids, context=context): if not follower.subtype_ids: continue @@ -55,6 +59,7 @@ class sale_order(osv.osv): def write(self, cr, uid, ids, vals, context=None): res = super(sale_order, self).write(cr, uid, ids, vals, context=context) + # subscribe new salesteam followers & subtypes to the sale order if vals.get('section_id'): self._subscribe_salesteam_followers_to_order(cr, uid, ids, context=context) return res