ir_mail_server.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # BizzAppDev
  5. # Copyright (C) 2015-TODAY bizzappdev(<http://www.bizzappdev.com>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp import _, models
  22. from openerp.osv import osv
  23. from openerp.tools import config
  24. class ir_mail_server(models.Model):
  25. _inherit = "ir.mail_server"
  26. def get_mode(self, dbname):
  27. mode = config.get('develop', {}).get(
  28. dbname, False) and 'develop' or False
  29. mode = not mode and config.get('test', {}).get(
  30. dbname, False) and 'test' or mode
  31. return mode
  32. def send_email(self, cr, uid, message, mail_server_id=None, smtp_server=None, smtp_port=None,
  33. smtp_user=None, smtp_password=None, smtp_encryption=None, smtp_debug=False,
  34. context=None):
  35. if self.get_mode(cr.dbname):
  36. raise osv.except_osv(
  37. _("OpenERP Mode"),
  38. _("You Can not Send Mail Because OpenERP is in Test/Develop mode"))
  39. return super(ir_mail_server, self).send_email(
  40. cr, uid, message, mail_server_id=mail_server_id,
  41. smtp_server=smtp_server, smtp_port=smtp_port,
  42. smtp_user=smtp_user, smtp_password=smtp_password,
  43. smtp_encryption=smtp_encryption, smtp_debug=smtp_debug, context=None)
  44. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: