~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to email_template_followers/model/mail_compose_message.py

  • Committer: Jose Morales
  • Date: 2014-07-28 20:00:11 UTC
  • mfrom: (543.7.551 7.0-addons-vauxoo)
  • Revision ID: jose@vauxoo.com-20140728200011-csytovehrzwp24lr
[FORWARD PORT] 7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- encoding: utf-8 -*-
 
3
###########################################################################
 
4
#    Module Writen to OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2013 Vauxoo (<http://vauxoo.com>).
 
6
#    All Rights Reserved
 
7
###############Credits######################################################
 
8
#    Coded by: vauxoo consultores (info@vauxoo.com)
 
9
#############################################################################
 
10
#    This program is free software: you can redistribute it and/or modify
 
11
#    it under the terms of the GNU Affero General Public License as published by
 
12
#    the Free Software Foundation, either version 3 of the License, or
 
13
#    (at your option) any later version.
 
14
#
 
15
#    This program is distributed in the hope that it will be useful,
 
16
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
#    GNU Affero General Public License for more details.
 
19
#
 
20
#    You should have received a copy of the GNU Affero General Public License
 
21
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
################################################################################
 
23
 
 
24
 
 
25
from openerp.osv import osv, fields
 
26
from openerp import tools, SUPERUSER_ID
 
27
 
 
28
class mail_compose_message(osv.TransientModel):
 
29
    
 
30
    _inherit = 'mail.compose.message'
 
31
    
 
32
    def generate_email_for_composer(self, cr, uid, template_id, res_id, context=None):
 
33
        
 
34
        values = super(mail_compose_message, self).generate_email_for_composer(cr, uid,
 
35
                                                        template_id, res_id, context=context)
 
36
        
 
37
        email_template_obj = self.pool.get('email.template')
 
38
        
 
39
        email_template = email_template_obj.browse(cr, uid, template_id, context=context)
 
40
        if values.get('partner_ids', False) and email_template.add_followers:
 
41
            partners_to_notify = set([])
 
42
            partner_follower = self.pool.get('mail.followers')
 
43
            
 
44
            fol_ids = partner_follower.search(cr, SUPERUSER_ID, [
 
45
                ('res_model', '=', context.get('active_model')),
 
46
                ('res_id', '=', context.get('active_id')),
 
47
                ], context=context)
 
48
                
 
49
            partners_to_notify |= set(fo.partner_id.id\
 
50
                    for fo in partner_follower.browse(cr, SUPERUSER_ID, fol_ids, context=context))
 
51
                    
 
52
            partners_followers_notify = values.get('partner_ids', []) + list(partners_to_notify)
 
53
            values.update({'partner_ids': list(set(partners_followers_notify))})
 
54
        return values
 
55