Launchpad automatic translations update.
[odoo/odoo.git] / addons / mail / res_config.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2012-Today OpenERP SA (<http://www.openerp.com>)
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU General Public License as published by
9 #    the Free Software Foundation, either version 3 of the License, or
10 #    (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 General Public License for more details.
16 #
17 #    You should have received a copy of the GNU General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>
19 #
20 ##############################################################################
21
22 import urlparse
23
24 from openerp.osv import osv, fields
25
26 class project_configuration(osv.TransientModel):
27     _inherit = 'base.config.settings'
28
29     _columns = {
30         'alias_domain' : fields.char('Alias Domain',
31                                      help="If you have setup a catch-all email domain redirected to "
32                                           "the OpenERP server, enter the domain name here."),
33     }
34
35     def get_default_alias_domain(self, cr, uid, ids, context=None):
36         alias_domain = self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", context=context)
37         if not alias_domain:
38             domain = self.pool.get("ir.config_parameter").get_param(cr, uid, "web.base.url", context=context)
39             try:
40                 alias_domain = urlparse.urlsplit(domain).netloc.split(':')[0]
41             except Exception:
42                 pass
43         return {'alias_domain': alias_domain}
44
45     def set_alias_domain(self, cr, uid, ids, context=None):
46         config_parameters = self.pool.get("ir.config_parameter")
47         for record in self.browse(cr, uid, ids, context=context):
48             config_parameters.set_param(cr, uid, "mail.catchall.domain", record.alias_domain or '', context=context)