~initos.com/openerp-connector-magento/7.0-import_customer_lang

« back to all changes in this revision

Viewing changes to server_env_magentoerpconnect/magento_model.py

  • Committer: Guewen Baconnier
  • Date: 2014-02-04 11:04:31 UTC
  • mto: This revision was merged to the branch mainline in revision 956.
  • Revision ID: guewen.baconnier@camptocamp.com-20140204110431-rg77rdn3pymuc3us
Add server_env_magentoerpconnect to enable server environments with the connector

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Author: Guewen Baconnier
 
5
#    Copyright 2014 Camptocamp SA
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as
 
9
#    published by the Free Software Foundation, either version 3 of the
 
10
#    License, or (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 Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
import logging
 
23
from openerp.osv import fields, orm
 
24
try:
 
25
    from server_environment import serv_config
 
26
except ImportError:
 
27
    logging.getLogger('openerp.module').warning('server_environment not available in addons path. '
 
28
                                                'server_env_magentoerpconnect will not be usable')
 
29
 
 
30
_logger = logging.getLogger(__name__)
 
31
 
 
32
 
 
33
class magento_backend(orm.Model):
 
34
    _inherit = 'magento.backend'
 
35
 
 
36
    def _get_environment_config_by_name(self, cr, uid, ids, field_names,
 
37
                                        arg, context=None):
 
38
        values = {}
 
39
        for backend in self.browse(cr, uid, ids, context=context):
 
40
            values[backend.id] = {}
 
41
            for field_name in field_names:
 
42
                section_name = '.'.join((self._name.replace('.', '_'),
 
43
                                         backend.name))
 
44
                try:
 
45
                    value = serv_config.get(section_name, field_name)
 
46
                    values[backend.id][field_name] = value
 
47
                except:
 
48
                    _logger.exception('error trying to read field %s '
 
49
                                      'in section %s', field_name,
 
50
                                      section_name)
 
51
                    values[backend.id][field_name] = False
 
52
        return values
 
53
 
 
54
    _columns = {
 
55
        'location': fields.function(
 
56
            _get_environment_config_by_name,
 
57
            string='Location',
 
58
            type='char',
 
59
            multi='connection_config'),
 
60
        'username': fields.function(
 
61
            _get_environment_config_by_name,
 
62
            string='Username',
 
63
            type='char',
 
64
            multi='connection_config'),
 
65
        'password': fields.function(
 
66
            _get_environment_config_by_name,
 
67
            string='Password',
 
68
            type='char',
 
69
            multi='connection_config'),
 
70
    }