summaryrefslogtreecommitdiff
path: root/addons/gamification/wizard
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/gamification/wizard
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/gamification/wizard')
-rw-r--r--addons/gamification/wizard/__init__.py5
-rw-r--r--addons/gamification/wizard/grant_badge.py34
-rw-r--r--addons/gamification/wizard/grant_badge.xml31
-rw-r--r--addons/gamification/wizard/update_goal.py24
-rw-r--r--addons/gamification/wizard/update_goal.xml19
5 files changed, 113 insertions, 0 deletions
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 @@
+<odoo>
+ <record id="view_badge_wizard_grant" model="ir.ui.view">
+ <field name="name">Grant Badge User Form</field>
+ <field name="model">gamification.badge.user.wizard</field>
+ <field name="arch" type="xml">
+ <form string="Grant Badge To">
+ Who would you like to reward?
+ <field name="badge_id" invisible="1"/>
+ <group>
+ <field name="user_id" nolabel="1" colspan="4"/>
+ <field name="comment" nolabel="1" placeholder="Describe what they did and why it matters (will be public)" colspan="4"/>
+ </group>
+ <footer>
+ <button string="Grant Badge" type="object" name="action_grant_badge" class="btn-primary" />
+ <button string="Cancel" special="cancel" class="btn-secondary"/>
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="action_grant_wizard" model="ir.actions.act_window">
+ <field name="name">Grant Badge</field>
+ <field name="res_model">gamification.badge.user.wizard</field>
+ <field name="view_id" ref="gamification.view_badge_wizard_grant"/>
+ <field name="target">new</field>
+ <field name="context">{
+ 'default_badge_id': active_id,
+ 'badge_id': active_id
+ }</field>
+ </record>
+</odoo>
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 @@
+<odoo>
+ <record id="view_goal_wizard_update_current" model="ir.ui.view">
+ <field name="name">Update the current value of the Goal</field>
+ <field name="model">gamification.goal.wizard</field>
+ <field name="arch" type="xml">
+ <form string="Grant Badge To">
+ Set the current value you have reached for this goal
+ <group>
+ <field name="goal_id" invisible="1"/>
+ <field name="current" />
+ </group>
+ <footer>
+ <button string="Update" type="object" name="action_update_current" class="btn-primary" />
+ <button string="Cancel" special="cancel" class="btn-secondary"/>
+ </footer>
+ </form>
+ </field>
+ </record>
+</odoo>