[MERGE] forward port of branch 7.0 up to revid 10037 mat@openerp.com-20140507133552...
[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
27 class project_configuration(osv.TransientModel):
28     _inherit = 'base.config.settings'
29
30     _columns = {
31         'alias_domain': fields.char('Alias Domain',
32                                      help="If you have setup a catch-all email domain redirected to "
33                                           "the OpenERP server, enter the domain name here."),
34     }
35
36     def get_default_alias_domain(self, cr, uid, ids, context=None):
37         alias_domain = self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", default=None, context=context)
38         if alias_domain is None:
39             domain = self.pool.get("ir.config_parameter").get_param(cr, uid, "web.base.url", context=context)
40             try:
41                 alias_domain = urlparse.urlsplit(domain).netloc.split(':')[0]
42             except Exception:
43                 pass
44         return {'alias_domain': alias_domain or False}
45
46     def set_alias_domain(self, cr, uid, ids, context=None):
47         config_parameters = self.pool.get("ir.config_parameter")
48         for record in self.browse(cr, uid, ids, context=context):
49             config_parameters.set_param(cr, uid, "mail.catchall.domain", record.alias_domain or '', context=context)