1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2013 OpenERP SA (<http://www.openerp.com>)
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.
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.
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/>
20 ##############################################################################
22 from openerp.osv import fields, osv
23 from openerp.tools.translate import _
26 class grant_badge_wizard(osv.TransientModel):
27 """ Wizard allowing to grant a badge to a user"""
29 _name = 'gamification.badge.user.wizard'
31 'user_id': fields.many2one("res.users", string='User', required=True),
32 'badge_id': fields.many2one("gamification.badge", string='Badge', required=True),
33 'comment': fields.text('Comment'),
36 def action_grant_badge(self, cr, uid, ids, context=None):
37 """Wizard action for sending a badge to a chosen user"""
39 badge_user_obj = self.pool.get('gamification.badge.user')
41 for wiz in self.browse(cr, uid, ids, context=context):
42 if uid == wiz.user_id.id:
43 raise osv.except_osv(_('Warning!'), _('You can not grant a badge to yourself'))
47 'user_id': wiz.user_id.id,
49 'badge_id': wiz.badge_id.id,
50 'comment': wiz.comment,
52 badge_user = badge_user_obj.create(cr, uid, values, context=context)
53 result = badge_user_obj._send_badge(cr, uid, badge_user, context=context)