Use new server.env.mixin in mail_environment

This commit is contained in:
Guewen Baconnier 2018-07-19 22:36:30 +02:00 committed by Adrien Peiffer
parent af21ed2de0
commit 92a34e9cb5
No known key found for this signature in database
GPG Key ID: D9266D898B218452
4 changed files with 57 additions and 106 deletions

View File

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

View File

@ -3,58 +3,46 @@
import operator
from odoo import api, fields, models
from odoo.addons.server_environment import serv_config
class FetchmailServer(models.Model):
"""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',
states={})
port = fields.Integer(compute='_compute_server_env',
states={})
type = fields.Selection(compute='_compute_server_env',
search='_search_type',
states={})
user = fields.Char(compute='_compute_server_env',
states={})
password = fields.Char(compute='_compute_server_env',
states={})
is_ssl = fields.Boolean(compute='_compute_server_env')
attach = fields.Boolean(compute='_compute_server_env')
original = fields.Boolean(compute='_compute_server_env')
@property
def _server_env_fields(self):
base_fields = super()._server_env_fields
mail_fields = {
"server": {},
"port": {
"getter": "getint",
},
"type": {},
"user": {},
"password": {},
"is_ssl": {
"getter": "getbool",
},
"attach": {
"getter": "getbool",
},
"original": {
"getter": "getbool",
},
}
mail_fields.update(base_fields)
return mail_fields
@api.depends()
def _compute_server_env(self):
for fetchmail in self:
global_section_name = 'incoming_mail'
type = fields.Selection(search='_search_type')
key_types = {'port': int,
'is_ssl': lambda a: bool(int(a or 0)),
'attach': lambda a: bool(int(a or 0)),
'original': lambda a: bool(int(a or 0)),
}
@api.model
def _server_env_global_section_name(self):
"""Name of the global section in the configuration files
# default vals
config_vals = {'port': 993,
'is_ssl': 0,
'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)
Can be customized in your model
"""
return 'incoming_mail'
@api.model
def _search_type(self, oper, value):

View File

@ -1,44 +1,32 @@
# Copyright 2012-2018 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
from odoo import api, fields, models
from odoo.addons.server_environment import serv_config
from odoo import api, models
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',
required=False,
readonly=True)
smtp_port = fields.Integer(compute='_compute_server_env',
required=False,
readonly=True)
smtp_user = fields.Char(compute='_compute_server_env',
required=False,
readonly=True)
smtp_pass = fields.Char(compute='_compute_server_env',
required=False,
readonly=True)
smtp_encryption = fields.Selection(compute='_compute_server_env',
required=False,
readonly=True)
@property
def _server_env_fields(self):
base_fields = super()._server_env_fields
mail_fields = {
"smtp_host": {},
"smtp_port": {
"getter": "getint",
},
"smtp_user": {},
"smtp_pass": {},
"smtp_encryption": {},
}
mail_fields.update(base_fields)
return mail_fields
@api.depends()
def _compute_server_env(self):
for server in self:
global_section_name = 'outgoing_mail'
@api.model
def _server_env_global_section_name(self):
"""Name of the global section in the configuration files
# default vals
config_vals = {'smtp_port': 587}
if serv_config.has_section(global_section_name):
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)
Can be customized in your model
"""
return 'outgoing_mail'

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>