1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2013 credativ (http://www.credativ.co.uk). All Rights Reserved
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.
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.
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/>.
20
##############################################################################
22
from openerp.osv import osv, fields
23
from redmine_osv import Connection
26
_logger = logging.getLogger(__name__)
27
_logger.setLevel(logging.DEBUG)
31
Add a redmine login name field to res.users.
33
_inherit = 'res.users'
35
def _get_rm_user_id(self, cr, uid, ids, field, args, context=None):
36
referential_type_pool = self.pool.get('external.referential.type')
37
type_ids = referential_type_pool.search(cr, uid, [('name','ilike','redmine')], context=context)
39
referential_pool = self.pool.get('external.referential')
40
referential_ids = referential_pool.search(cr, uid, [('type_id','in',type_ids)], context=context)
42
if len(referential_ids) == 1:
43
referential = referential_pool.browse(cr, uid, referential_ids[0], context=context)
45
conn = Connection(referential.location, referential.apiusername, referential.apipass)
46
return dict([(user.id, conn.call('Users.find', user.rm_login))
47
for user in self.browse(cr, uid, ids, context=context)])
49
_logger.error('Redmine: could not retrieve redmine user ID(s): %s' % (str(e),))
50
elif len(referential_ids) > 0:
51
raise osv.except_osv('Integrity error',
52
'Found multiple external referentials of type Redmine')
54
raise osv.except_osv('Integrity error',
55
'Could not find an external referential of type Redmine')
57
def _update_rm_user_id(self, cr, uid, ids, context=None):
58
return self._get_rm_user_id(cr, uid, ids, field='rm_user_id', args=[], context=context)
61
'rm_login': fields.char(
64
help='This user\'s login name on Redmine'),
65
# FIXME Seems like access to users.xml is further restricted somehow
66
# 'rm_user_id': fields.function(
68
# store={'res.users': (_update_rm_user_id, ['rm_login'], 10)},
70
# string='Redmine user ID',
72
# FIXME For now we'll just required that the user ID is manually entered
73
'rm_user_id': fields.integer(
74
string='Redmine user ID'),