diff --git a/addons/gamification/badge.py b/addons/gamification/badge.py index ab3bdb81c12..a209eaf822d 100644 --- a/addons/gamification/badge.py +++ b/addons/gamification/badge.py @@ -45,6 +45,8 @@ class gamification_badge_user(osv.Model): 'create_uid': fields.many2one('res.users', 'Creator', readonly=True), } + _order = "create_date desc" + class gamification_badge(osv.Model): """Badge object that users can send and receive""" @@ -357,6 +359,7 @@ class grant_badge_wizard(osv.TransientModel): } def action_grant_badge(self, cr, uid, ids, context=None): + """Wizard action for sending a badge to a chosen user""" if context is None: context = {} @@ -364,13 +367,19 @@ class grant_badge_wizard(osv.TransientModel): badge_user_obj = self.pool.get('gamification.badge.user') for wiz in self.browse(cr, uid, ids, context=context): + if uid == wiz.user_id.id: + raise osv.except_osv(_('Warning!'), _('You can not send a badge to yourself')) + if badge_obj.can_grant_badge(cr, uid, user_from_id=uid, badge_id=wiz.badge_id.id, context=context): - - badge_user = badge_user_obj.create(cr, uid, - {'user_id': wiz.user_id.id, 'badge_id': wiz.badge_id.id, 'comment': wiz.comment}, context=context) + values = { + 'user_id': wiz.user_id.id, + 'badge_id': wiz.badge_id.id, + 'comment': wiz.comment, + } + badge_user = badge_user_obj.create(cr, uid, values, context=context) user_from = self.pool.get('res.users').browse(cr, uid, uid, context=context) diff --git a/addons/gamification/badge_view.xml b/addons/gamification/badge_view.xml index 002424168ce..0a7e32769d4 100644 --- a/addons/gamification/badge_view.xml +++ b/addons/gamification/badge_view.xml @@ -177,9 +177,9 @@ jspW8F2wIbhtSRr0Vf4AD6Nod0TaN4kAAAAASUVORK5CYII=" alt="got-it" /> - +

- Sent by the +

Sent by the

diff --git a/addons/hr_gamification/badge.py b/addons/hr_gamification/badge.py index a278f42d49f..aacac358e27 100644 --- a/addons/hr_gamification/badge.py +++ b/addons/hr_gamification/badge.py @@ -75,6 +75,7 @@ class hr_grant_badge_wizard(osv.TransientModel): } def action_grant_badge(self, cr, uid, ids, context=None): + """Wizard action for sending a badge to a chosen employee""" if context is None: context = {} @@ -85,6 +86,9 @@ class hr_grant_badge_wizard(osv.TransientModel): if not wiz.user_id: raise osv.except_osv(_('Warning!'), _('You can send badges only to employees linked to a user.')) + if uid == wiz.user_id.id: + raise osv.except_osv(_('Warning!'), _('You can not send a badge to yourself')) + if badge_obj.can_grant_badge(cr, uid, user_from_id=uid, badge_id=wiz.badge_id.id, diff --git a/addons/hr_gamification/badge_view.xml b/addons/hr_gamification/badge_view.xml index 38f5a0fd0a0..57557cf63ed 100644 --- a/addons/hr_gamification/badge_view.xml +++ b/addons/hr_gamification/badge_view.xml @@ -2,6 +2,8 @@ + + Grant Badge Employee Form gamification.badge.user.wizard @@ -24,16 +26,49 @@ + + Reward Employee Badge Form + gamification.badge.user.wizard + +
+ Select the badge that the employee will receive + + + + + +
+
+
+
+
+ + + + + + + hr.hr.employee.view.form hr.employee - - - - - + +