From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/gamification/wizard/__init__.py | 5 +++++ addons/gamification/wizard/grant_badge.py | 34 ++++++++++++++++++++++++++++++ addons/gamification/wizard/grant_badge.xml | 31 +++++++++++++++++++++++++++ addons/gamification/wizard/update_goal.py | 24 +++++++++++++++++++++ addons/gamification/wizard/update_goal.xml | 19 +++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 addons/gamification/wizard/__init__.py create mode 100644 addons/gamification/wizard/grant_badge.py create mode 100644 addons/gamification/wizard/grant_badge.xml create mode 100644 addons/gamification/wizard/update_goal.py create mode 100644 addons/gamification/wizard/update_goal.xml (limited to 'addons/gamification/wizard') diff --git a/addons/gamification/wizard/__init__.py b/addons/gamification/wizard/__init__.py new file mode 100644 index 00000000..9160eb68 --- /dev/null +++ b/addons/gamification/wizard/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import update_goal +from . import grant_badge 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 diff --git a/addons/gamification/wizard/grant_badge.xml b/addons/gamification/wizard/grant_badge.xml new file mode 100644 index 00000000..dde5b011 --- /dev/null +++ b/addons/gamification/wizard/grant_badge.xml @@ -0,0 +1,31 @@ + + + Grant Badge User Form + gamification.badge.user.wizard + +
+ Who would you like to reward? + + + + + +
+
+ +
+
+ + + Grant Badge + gamification.badge.user.wizard + + new + { + 'default_badge_id': active_id, + 'badge_id': active_id + } + +
diff --git a/addons/gamification/wizard/update_goal.py b/addons/gamification/wizard/update_goal.py new file mode 100644 index 00000000..e9664e05 --- /dev/null +++ b/addons/gamification/wizard/update_goal.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, fields + +class goal_manual_wizard(models.TransientModel): + """Wizard to update a manual goal""" + _name = 'gamification.goal.wizard' + _description = 'Gamification Goal Wizard' + + goal_id = fields.Many2one("gamification.goal", string='Goal', required=True) + current = fields.Float('Current') + + def action_update_current(self): + """Wizard action for updating the current value""" + for wiz in self: + wiz.goal_id.write({ + 'current': wiz.current, + 'goal_id': wiz.goal_id.id, + 'to_update': False, + }) + wiz.goal_id.update_goal() + + return False diff --git a/addons/gamification/wizard/update_goal.xml b/addons/gamification/wizard/update_goal.xml new file mode 100644 index 00000000..53275077 --- /dev/null +++ b/addons/gamification/wizard/update_goal.xml @@ -0,0 +1,19 @@ + + + Update the current value of the Goal + gamification.goal.wizard + +
+ Set the current value you have reached for this goal + + + + + +
+
+
+
-- cgit v1.2.3