From 932ca227132d9ea0da024be973b1734fac6486c3 Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Thu, 19 Jul 2018 22:36:30 +0200 Subject: [PATCH] Use new server.env.mixin in mail_environment --- mail_environment/__manifest__.py | 6 +- mail_environment/models/fetchmail_server.py | 76 ++++++++----------- mail_environment/models/ir_mail_server.py | 58 ++++++-------- .../views/fetchmail_server_views.xml | 23 ------ 4 files changed, 57 insertions(+), 106 deletions(-) delete mode 100644 mail_environment/views/fetchmail_server_views.xml diff --git a/mail_environment/__manifest__.py b/mail_environment/__manifest__.py index 00983c1..46a4b82 100644 --- a/mail_environment/__manifest__.py +++ b/mail_environment/__manifest__.py @@ -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': [], } diff --git a/mail_environment/models/fetchmail_server.py b/mail_environment/models/fetchmail_server.py index 72cd926..ed33312 100644 --- a/mail_environment/models/fetchmail_server.py +++ b/mail_environment/models/fetchmail_server.py @@ -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): diff --git a/mail_environment/models/ir_mail_server.py b/mail_environment/models/ir_mail_server.py index 1f45fd3..b1d53ce 100644 --- a/mail_environment/models/ir_mail_server.py +++ b/mail_environment/models/ir_mail_server.py @@ -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' diff --git a/mail_environment/views/fetchmail_server_views.xml b/mail_environment/views/fetchmail_server_views.xml deleted file mode 100644 index 0c7f113..0000000 --- a/mail_environment/views/fetchmail_server_views.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - fetchmail.server - - - - - - - - - - - - - - - - - -