diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/gamification/wizard/grant_badge.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/gamification/wizard/grant_badge.py')
| -rw-r--r-- | addons/gamification/wizard/grant_badge.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/gamification/wizard/grant_badge.py b/addons/gamification/wizard/grant_badge.py new file mode 100644 index 00000000..84b764c5 --- /dev/null +++ b/addons/gamification/wizard/grant_badge.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _, exceptions + + +class grant_badge_wizard(models.TransientModel): + """ Wizard allowing to grant a badge to a user""" + _name = 'gamification.badge.user.wizard' + _description = 'Gamification User Badge Wizard' + + user_id = fields.Many2one("res.users", string='User', required=True) + badge_id = fields.Many2one("gamification.badge", string='Badge', required=True) + comment = fields.Text('Comment') + + def action_grant_badge(self): + """Wizard action for sending a badge to a chosen user""" + + BadgeUser = self.env['gamification.badge.user'] + + uid = self.env.uid + for wiz in self: + if uid == wiz.user_id.id: + raise exceptions.UserError(_('You can not grant a badge to yourself.')) + + #create the badge + BadgeUser.create({ + 'user_id': wiz.user_id.id, + 'sender_id': uid, + 'badge_id': wiz.badge_id.id, + 'comment': wiz.comment, + })._send_badge() + + return True |
