1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- # -*- coding: utf-8 -*-
- ##############################################################################
- #
- # OpenERP, Open Source Management Solution
- # Copyright (C) 2004-2010 Tiny SPRL (<http:
- # Copyright (C) 2011-2012 Serpent Consulting Services (<http:
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as
- # published by the Free Software Foundation, either version 3 of the
- # License, or (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http:
- #
- ##############################################################################
- from osv import fields, osv
- import email
- from email.header import decode_header
- from email.message import Message
- class email_template(osv.osv):
- _inherit="email.template"
-
- def generate_email(self, cr, uid, template_id, res_id, context=None):
- if context is None:
- context = {}
- ret= super(email_template,self).generate_email(cr, uid, template_id, res_id, context=context)
- if context.get('body_text',False) or context.get('subject',False) or context.get('email_to',False):
- ret['body_text']=context['body_text']
- ret['subject']=context['subject']
- ret['email_to']=context['email_to']
- return ret
- else:
- return ret
- #
- email_template()
- class send_email(osv.osv):
- _name = "send.email"
- _columns = {
- 'note':fields.text('Text',required=True),
-
- }
- def send_email(self, cr, uid, ids, context=None):
- subject = 'Emergency mail'
- body=''
-
- email_template=self.pool.get('email.template')
- template_id=email_template.search(cr,uid,[('model_id.model','=','student.student')],context=context)
- email_template_brw = email_template.browse(cr,uid,template_id[0])
-
- for i in self.browse(cr,uid,ids):
- body = i.note
-
- for student_brw in self.pool.get('student.student').browse(cr,uid,context['active_ids']):
- for emergency_contect_brw in student_brw.emergency_contact_ids:
- context['body_text']=body
- context['subject']=subject
- context['email_to']=emergency_contect_brw.email
- email_template.send_mail(cr, uid ,email_template_brw.id,ids[0],force_send=True,context=context)
- return {'type': 'ir.actions.act_window_close'}
- send_email()
|