~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: Julio Serna
  • Date: 2014-07-03 23:59:25 UTC
  • mto: (543.7.533 7.0-addons-vauxoo)
  • mto: This revision was merged to the branch mainline in revision 865.
  • Revision ID: julio@vauxoo.com-20140703235925-0c1u35duqoku0va9
[ADD] added module that added followers from template

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
        if values.get('partner_ids', False):
 
38
            partners_to_notify = set([])
 
39
            partner_follower = self.pool.get('mail.followers')
 
40
            
 
41
            fol_ids = partner_follower.search(cr, SUPERUSER_ID, [
 
42
                ('res_model', '=', context.get('active_model')),
 
43
                ('res_id', '=', context.get('active_id')),
 
44
                ], context=context)
 
45
                
 
46
            partners_to_notify |= set(fo.partner_id.id\
 
47
                    for fo in partner_follower.browse(cr, SUPERUSER_ID, fol_ids, context=context))
 
48
                    
 
49
            partners_followers_notify = values.get('partner_ids', []) + list(partners_to_notify)
 
50
            values.update({'partner_ids': list(set(partners_followers_notify))})
 
51
        return values
 
52