[MERGE] forward port of branch saas-3 up to 7dd6954
authorChristophe Simonis <chs@odoo.com>
Tue, 3 Jun 2014 17:14:22 +0000 (19:14 +0200)
committerChristophe Simonis <chs@odoo.com>
Tue, 3 Jun 2014 17:14:22 +0000 (19:14 +0200)
1  2 
.gitignore
addons/mail/mail_thread.py
addons/purchase/purchase.py
addons/sale/sale.py
openerp/addons/base/security/ir.model.access.csv

diff --cc .gitignore
Simple merge
@@@ -1862,35 -1836,3 +1869,35 @@@ class mail_thread(osv.AbstractModel)
              }
              threads.append(data)
          return sorted(threads, key=lambda x: (x['popularity'], x['id']), reverse=True)[:3]
 +
 +    def message_change_thread(self, cr, uid, id, new_res_id, new_model, context=None):
 +        """
 +        Transfert the list of the mail thread messages from an model to another
 +
 +        :param id : the old res_id of the mail.message
 +        :param new_res_id : the new res_id of the mail.message
 +        :param new_model : the name of the new model of the mail.message
 +
 +        Example :   self.pool.get("crm.lead").message_change_thread(self, cr, uid, 2, 4, "project.issue", context) 
 +                    will transfert thread of the lead (id=2) to the issue (id=4)
 +        """
 +
 +        # get the sbtype id of the comment Message
 +        subtype_res_id = self.pool.get('ir.model.data').xmlid_to_res_id(cr, uid, 'mail.mt_comment', raise_if_not_found=True)
 +        
 +        # get the ids of the comment and none-comment of the thread
 +        message_obj = self.pool.get('mail.message')
 +        msg_ids_comment = message_obj.search(cr, uid, [
 +                    ('model', '=', self._name),
 +                    ('res_id', '=', id),
 +                    ('subtype_id', '=', subtype_res_id)], context=context)
 +        msg_ids_not_comment = message_obj.search(cr, uid, [
 +                    ('model', '=', self._name),
 +                    ('res_id', '=', id),
 +                    ('subtype_id', '!=', subtype_res_id)], context=context)
 +        
 +        # update the messages
 +        message_obj.write(cr, uid, msg_ids_comment, {"res_id" : new_res_id, "model" : new_model}, context=context)
 +        message_obj.write(cr, uid, msg_ids_not_comment, {"res_id" : new_res_id, "model" : new_model, "subtype_id" : None}, context=context)
 +        
-         return True
++        return True
Simple merge
Simple merge