You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2012-2016 Camptocamp SA
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
  4. from odoo import api, fields, models
  5. from odoo.addons.server_environment import serv_config
  6. class IrMailServer(models.Model):
  7. _inherit = "ir.mail_server"
  8. smtp_host = fields.Char(compute='_compute_server_env',
  9. required=False,
  10. readonly=True)
  11. smtp_port = fields.Integer(compute='_compute_server_env',
  12. required=False,
  13. readonly=True)
  14. smtp_user = fields.Char(compute='_compute_server_env',
  15. required=False,
  16. readonly=True)
  17. smtp_pass = fields.Char(compute='_compute_server_env',
  18. required=False,
  19. readonly=True)
  20. smtp_encryption = fields.Selection(compute='_compute_server_env',
  21. required=False,
  22. readonly=True)
  23. @api.depends()
  24. def _compute_server_env(self):
  25. for server in self:
  26. global_section_name = 'outgoing_mail'
  27. # default vals
  28. config_vals = {'smtp_port': 587}
  29. if serv_config.has_section(global_section_name):
  30. config_vals.update((serv_config.items(global_section_name)))
  31. custom_section_name = '.'.join((global_section_name, server.name))
  32. if serv_config.has_section(custom_section_name):
  33. config_vals.update(serv_config.items(custom_section_name))
  34. if config_vals.get('smtp_port'):
  35. config_vals['smtp_port'] = int(config_vals['smtp_port'])
  36. server.update(config_vals)