Use new server.env.mixin in mail_environment

This commit is contained in:
Guewen Baconnier 2018-07-19 22:36:30 +02:00
parent aad7dcec81
commit 932ca22713
4 changed files with 57 additions and 106 deletions

View File

@ -3,7 +3,7 @@
{ {
'name': 'Mail configuration with server_environment', 'name': 'Mail configuration with server_environment',
'version': '11.0.1.0.0', 'version': '11.0.1.1.0',
'category': 'Tools', 'category': 'Tools',
'summary': 'Configure mail servers with server_environment_files', 'summary': 'Configure mail servers with server_environment_files',
'author': "Camptocamp, Odoo Community Association (OCA)", 'author': "Camptocamp, Odoo Community Association (OCA)",
@ -13,7 +13,5 @@
'fetchmail', 'fetchmail',
'server_environment', 'server_environment',
], ],
'data': [ 'data': [],
'views/fetchmail_server_views.xml',
],
} }

View File

@ -3,58 +3,46 @@
import operator import operator
from odoo import api, fields, models from odoo import api, fields, models
from odoo.addons.server_environment import serv_config
class FetchmailServer(models.Model): class FetchmailServer(models.Model):
"""Incoming POP/IMAP mail server account""" """Incoming POP/IMAP mail server account"""
_inherit = 'fetchmail.server' _name = 'fetchmail.server'
_inherit = ["fetchmail.server", "server.env.mixin"]
server = fields.Char(compute='_compute_server_env', @property
states={}) def _server_env_fields(self):
port = fields.Integer(compute='_compute_server_env', base_fields = super()._server_env_fields
states={}) mail_fields = {
type = fields.Selection(compute='_compute_server_env', "server": {},
search='_search_type', "port": {
states={}) "getter": "getint",
user = fields.Char(compute='_compute_server_env', },
states={}) "type": {},
password = fields.Char(compute='_compute_server_env', "user": {},
states={}) "password": {},
is_ssl = fields.Boolean(compute='_compute_server_env') "is_ssl": {
attach = fields.Boolean(compute='_compute_server_env') "getter": "getbool",
original = fields.Boolean(compute='_compute_server_env') },
"attach": {
"getter": "getbool",
},
"original": {
"getter": "getbool",
},
}
mail_fields.update(base_fields)
return mail_fields
@api.depends() type = fields.Selection(search='_search_type')
def _compute_server_env(self):
for fetchmail in self:
global_section_name = 'incoming_mail'
key_types = {'port': int, @api.model
'is_ssl': lambda a: bool(int(a or 0)), def _server_env_global_section_name(self):
'attach': lambda a: bool(int(a or 0)), """Name of the global section in the configuration files
'original': lambda a: bool(int(a or 0)),
}
# default vals Can be customized in your model
config_vals = {'port': 993, """
'is_ssl': 0, return 'incoming_mail'
'attach': 0,
'original': 0,
}
if serv_config.has_section(global_section_name):
config_vals.update(serv_config.items(global_section_name))
custom_section_name = '.'.join((global_section_name,
fetchmail.name))
if serv_config.has_section(custom_section_name):
config_vals.update(serv_config.items(custom_section_name))
for key, to_type in key_types.items():
if config_vals.get(key):
config_vals[key] = to_type(config_vals[key])
fetchmail.update(config_vals)
@api.model @api.model
def _search_type(self, oper, value): def _search_type(self, oper, value):

View File

@ -1,44 +1,32 @@
# Copyright 2012-2018 Camptocamp SA # Copyright 2012-2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo import api, fields, models from odoo import api, models
from odoo.addons.server_environment import serv_config
class IrMailServer(models.Model): class IrMailServer(models.Model):
_inherit = "ir.mail_server" _name = "ir.mail_server"
_inherit = ["ir.mail_server", "server.env.mixin"]
smtp_host = fields.Char(compute='_compute_server_env', @property
required=False, def _server_env_fields(self):
readonly=True) base_fields = super()._server_env_fields
smtp_port = fields.Integer(compute='_compute_server_env', mail_fields = {
required=False, "smtp_host": {},
readonly=True) "smtp_port": {
smtp_user = fields.Char(compute='_compute_server_env', "getter": "getint",
required=False, },
readonly=True) "smtp_user": {},
smtp_pass = fields.Char(compute='_compute_server_env', "smtp_pass": {},
required=False, "smtp_encryption": {},
readonly=True) }
smtp_encryption = fields.Selection(compute='_compute_server_env', mail_fields.update(base_fields)
required=False, return mail_fields
readonly=True)
@api.depends() @api.model
def _compute_server_env(self): def _server_env_global_section_name(self):
for server in self: """Name of the global section in the configuration files
global_section_name = 'outgoing_mail'
# default vals Can be customized in your model
config_vals = {'smtp_port': 587} """
if serv_config.has_section(global_section_name): return 'outgoing_mail'
config_vals.update((serv_config.items(global_section_name)))
custom_section_name = '.'.join((global_section_name, server.name))
if serv_config.has_section(custom_section_name):
config_vals.update(serv_config.items(custom_section_name))
if config_vals.get('smtp_port'):
config_vals['smtp_port'] = int(config_vals['smtp_port'])
server.update(config_vals)

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="inherit_fetchmail" model="ir.ui.view">
<field name="model">fetchmail.server</field>
<field name="inherit_id" ref="fetchmail.view_email_server_form"/>
<field name="arch" type="xml">
<field name="server" position="attributes">
<attribute name="attrs" eval="False"/>
</field>
<field name="port" position="attributes">
<attribute name="attrs" eval="False"/>
</field>
<field name="user" position="attributes">
<attribute name="attrs" eval="False"/>
</field>
<field name="password" position="attributes">
<attribute name="attrs" eval="False"/>
</field>
</field>
</record>
</odoo>