wiz_send_email.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
  6. # Copyright (C) 2011-Today Serpent Consulting Services PVT. LTD.
  7. # (<http://www.serpentcs.com>)
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp import models, fields, api
  23. class SendEmail(models.TransientModel):
  24. _name = "send.email"
  25. note = fields.Text('Text')
  26. # def send_email(self, cr, uid, ids, context=None):
  27. # subject = 'Emergency mail'
  28. # body = ''
  29. # email_template = self.pool.get('email.template')
  30. # template_id = email_template.search(cr, uid, [('model', '=',
  31. # 'student.student')],
  32. # context=context)
  33. # if template_id:
  34. # email_template_brw = email_template.browse(cr, uid,
  35. # template_id[0])
  36. # for i in self.browse(cr, uid, ids):
  37. # body += '\n' + i.note
  38. # email_template.send_mail(cr, uid , template_id[0],
  39. # context.get('active_id'), force_send=True)
  40. # return {'type': 'ir.actions.act_window_close'}
  41. @api.multi
  42. def send_email(self):
  43. body = ''
  44. email_template_obj = self.env['email.template']
  45. template_id = email_template_obj.search([('model', '=',
  46. 'student.student')], limit=1)
  47. if template_id:
  48. for i in self:
  49. body += '\n' + i.note
  50. email_template_obj.send_mail(template_id.id,
  51. self._context.get('active_id'),
  52. force_send=True)
  53. return {'type': 'ir.actions.act_window_close'}