[FIX] gamification: call _send_badge on right object
[odoo/odoo.git] / addons / gamification / wizard / grant_badge.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2013 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 from openerp.osv import fields, osv
23 from openerp.tools.translate import _
24
25
26 class grant_badge_wizard(osv.TransientModel):
27     """ Wizard allowing to grant a badge to a user"""
28
29     _name = 'gamification.badge.user.wizard'
30     _columns = {
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'),
34     }
35
36     def action_grant_badge(self, cr, uid, ids, context=None):
37         """Wizard action for sending a badge to a chosen user"""
38
39         badge_user_obj = self.pool.get('gamification.badge.user')
40
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'))
44
45             #create the badge
46             values = {
47                 'user_id': wiz.user_id.id,
48                 'sender_id': uid,
49                 'badge_id': wiz.badge_id.id,
50                 'comment': wiz.comment,
51             }
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)
54
55         return result