From b63950e0dc49220bed8e9e2c1a7f922f5300b490 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 18 Dec 2013 09:59:07 +0100 Subject: [PATCH] [REF] gamification: mode to adequate folders bzr revid: mat@openerp.com-20131218085907-6501sfdif2rk4a0b --- addons/gamification/__openerp__.py | 2 + addons/gamification/models/badge.py | 38 ----------- addons/gamification/models/goal.py | 24 ------- addons/gamification/models/res_users.py | 4 +- addons/gamification/views/badge.xml | 28 -------- addons/gamification/views/goal.xml | 20 ------ addons/gamification/wizard/__init__.py | 23 +++++++ addons/gamification/wizard/grant_badge.py | 58 +++++++++++++++++ addons/gamification/wizard/grant_badge.xml | 33 ++++++++++ addons/gamification/wizard/update_goal.py | 44 +++++++++++++ addons/gamification/wizard/update_goal.xml | 24 +++++++ addons/hr_gamification/__init__.py | 3 +- addons/hr_gamification/__openerp__.py | 3 +- addons/hr_gamification/models/__init__.py | 22 +++++++ .../{ => models}/gamification.py | 45 +------------ .../{ => views}/gamification_view.xml | 42 ------------ addons/hr_gamification/wizard/__init__.py | 22 +++++++ addons/hr_gamification/wizard/grant_badge.py | 65 +++++++++++++++++++ addons/hr_gamification/wizard/grant_badge.xml | 46 +++++++++++++ 19 files changed, 346 insertions(+), 200 deletions(-) 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 create mode 100644 addons/hr_gamification/models/__init__.py rename addons/hr_gamification/{ => models}/gamification.py (74%) rename addons/hr_gamification/{ => views}/gamification_view.xml (72%) create mode 100644 addons/hr_gamification/wizard/__init__.py create mode 100644 addons/hr_gamification/wizard/grant_badge.py create mode 100644 addons/hr_gamification/wizard/grant_badge.xml diff --git a/addons/gamification/__openerp__.py b/addons/gamification/__openerp__.py index 0bf31601876..3780b334cb1 100644 --- a/addons/gamification/__openerp__.py +++ b/addons/gamification/__openerp__.py @@ -46,6 +46,8 @@ Both goals and badges are flexibles and can be adapted to a large range of modul 'security/ir.model.access.csv', 'data/goal_base.xml', 'data/badge.xml', + 'wizard/update_goal.xml', + 'wizard/grant_badge.xml', ], 'test': [ 'test/goal_demo.yml' diff --git a/addons/gamification/models/badge.py b/addons/gamification/models/badge.py index 6aa2f89e74e..ad3767cbbc4 100644 --- a/addons/gamification/models/badge.py +++ b/addons/gamification/models/badge.py @@ -24,7 +24,6 @@ from openerp.osv import fields, osv from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF from openerp.tools.translate import _ -# from templates import TemplateHelper from datetime import date import logging @@ -111,7 +110,6 @@ class gamification_badge(osv.Model): 'name': fields.char('Badge', required=True, translate=True), 'description': fields.text('Description'), 'image': fields.binary("Image", help="This field holds the image used for the badge, limited to 256x256"), - # image_select: selection with a on_change to fill image with predefined picts 'rule_auth': fields.selection([ ('everyone', 'Everyone'), ('users', 'A selected list of users'), @@ -261,39 +259,3 @@ class gamification_badge(osv.Model): # badge.rule_auth == 'everyone' -> no check return 1 - - -class grant_badge_wizard(osv.TransientModel): - """ Wizard allowing to grant a badge to a user""" - - _name = 'gamification.badge.user.wizard' - _columns = { - '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, cr, uid, ids, context=None): - """Wizard action for sending a badge to a chosen user""" - - badge_obj = self.pool.get('gamification.badge') - 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 grant a badge to yourself')) - - #check if the badge granting is legitimate - if badge_obj.check_granting(cr, uid, user_from_id=uid, badge_id=wiz.badge_id.id, context=context): - #create the badge - 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) - #notify the user - result = badge_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context) - - return result -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py index 5a170a904c6..529f706fecd 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -372,27 +372,3 @@ class gamification_goal(osv.Model): return action return False - - -class goal_manual_wizard(osv.TransientModel): - """Wizard to update a manual goal""" - _name = 'gamification.goal.wizard' - _columns = { - 'goal_id': fields.many2one("gamification.goal", string='Goal', required=True), - 'current': fields.float('Current'), - } - - def action_update_current(self, cr, uid, ids, context=None): - """Wizard action for updating the current value""" - - goal_obj = self.pool.get('gamification.goal') - - for wiz in self.browse(cr, uid, ids, context=context): - towrite = { - 'current': wiz.current, - 'goal_id': wiz.goal_id.id, - } - goal_obj.write(cr, uid, [wiz.goal_id.id], towrite, context=context) - goal_obj.update(cr, uid, [wiz.goal_id.id], context=context) - return {} -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/gamification/models/res_users.py b/addons/gamification/models/res_users.py index ef544c95692..6c8ca7646b3 100644 --- a/addons/gamification/models/res_users.py +++ b/addons/gamification/models/res_users.py @@ -61,6 +61,7 @@ class res_users_gamification_group(osv.Model): all_goals_info = [] challenge_obj = self.pool.get('gamification.challenge') + user = self.browse(cr, uid, uid, context=context) challenge_ids = challenge_obj.search(cr, uid, [('user_ids', 'in', uid), ('state', '=', 'inprogress')], context=context) for challenge in challenge_obj.browse(cr, uid, challenge_ids, context=context): # serialize goals info to be able to use it in javascript @@ -68,9 +69,8 @@ class res_users_gamification_group(osv.Model): 'id': challenge.id, 'name': challenge.name, 'visibility_mode': challenge.visibility_mode, + 'currency': user.company_id.currency_id.id } - user = self.browse(cr, uid, uid, context=context) - serialized_goals_info['currency'] = user.company_id.currency_id.id if challenge.visibility_mode == 'ranking': # board report should be grouped by line for all users diff --git a/addons/gamification/views/badge.xml b/addons/gamification/views/badge.xml index af401b1f7de..f0ee1a8423d 100644 --- a/addons/gamification/views/badge.xml +++ b/addons/gamification/views/badge.xml @@ -19,34 +19,6 @@ - - - Grant Badge User Form - gamification.badge.user.wizard - -
- Who would you like to reward? - - - - - -
-
-
-
-
- - - Badge List gamification.badge diff --git a/addons/gamification/views/goal.xml b/addons/gamification/views/goal.xml index 8fa792c0b5a..dbb208ad5fd 100644 --- a/addons/gamification/views/goal.xml +++ b/addons/gamification/views/goal.xml @@ -278,26 +278,6 @@ - - - Update the current value of the Goal - gamification.goal.wizard - -
- Set the current value you have reached for this goal - - - - -
-
-
-
-
- - diff --git a/addons/gamification/wizard/__init__.py b/addons/gamification/wizard/__init__.py new file mode 100644 index 00000000000..638fbef4373 --- /dev/null +++ b/addons/gamification/wizard/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import update_goal +import grant_badge diff --git a/addons/gamification/wizard/grant_badge.py b/addons/gamification/wizard/grant_badge.py new file mode 100644 index 00000000000..725512a55bb --- /dev/null +++ b/addons/gamification/wizard/grant_badge.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## + +from openerp.osv import fields, osv +from openerp.tools.translate import _ + + +class grant_badge_wizard(osv.TransientModel): + """ Wizard allowing to grant a badge to a user""" + + _name = 'gamification.badge.user.wizard' + _columns = { + '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, cr, uid, ids, context=None): + """Wizard action for sending a badge to a chosen user""" + + badge_obj = self.pool.get('gamification.badge') + 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 grant a badge to yourself')) + + #check if the badge granting is legitimate + if badge_obj.check_granting(cr, uid, user_from_id=uid, badge_id=wiz.badge_id.id, context=context): + #create the badge + 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) + #notify the user + result = badge_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context) + + return result diff --git a/addons/gamification/wizard/grant_badge.xml b/addons/gamification/wizard/grant_badge.xml new file mode 100644 index 00000000000..e03dbac4096 --- /dev/null +++ b/addons/gamification/wizard/grant_badge.xml @@ -0,0 +1,33 @@ + + + + + + Grant Badge User Form + gamification.badge.user.wizard + +
+ Who would you like to reward? + + + + + +
+
+
+
+
+ + + +
+
diff --git a/addons/gamification/wizard/update_goal.py b/addons/gamification/wizard/update_goal.py new file mode 100644 index 00000000000..cbda3fefbce --- /dev/null +++ b/addons/gamification/wizard/update_goal.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## + +from openerp.osv import fields, osv + +class goal_manual_wizard(osv.TransientModel): + """Wizard to update a manual goal""" + _name = 'gamification.goal.wizard' + _columns = { + 'goal_id': fields.many2one("gamification.goal", string='Goal', required=True), + 'current': fields.float('Current'), + } + + def action_update_current(self, cr, uid, ids, context=None): + """Wizard action for updating the current value""" + + goal_obj = self.pool.get('gamification.goal') + + for wiz in self.browse(cr, uid, ids, context=context): + towrite = { + 'current': wiz.current, + 'goal_id': wiz.goal_id.id, + } + goal_obj.write(cr, uid, [wiz.goal_id.id], towrite, context=context) + goal_obj.update(cr, uid, [wiz.goal_id.id], context=context) + return {} diff --git a/addons/gamification/wizard/update_goal.xml b/addons/gamification/wizard/update_goal.xml new file mode 100644 index 00000000000..793efab90ff --- /dev/null +++ b/addons/gamification/wizard/update_goal.xml @@ -0,0 +1,24 @@ + + + + + + Update the current value of the Goal + gamification.goal.wizard + +
+ Set the current value you have reached for this goal + + + + +
+
+
+
+
+ +
+
diff --git a/addons/hr_gamification/__init__.py b/addons/hr_gamification/__init__.py index 51cf01dfa09..1896704c7fc 100644 --- a/addons/hr_gamification/__init__.py +++ b/addons/hr_gamification/__init__.py @@ -19,4 +19,5 @@ # ############################################################################## -import gamification +import models +import wizard \ No newline at end of file diff --git a/addons/hr_gamification/__openerp__.py b/addons/hr_gamification/__openerp__.py index d5d79dba074..2d29ccbc60a 100644 --- a/addons/hr_gamification/__openerp__.py +++ b/addons/hr_gamification/__openerp__.py @@ -33,7 +33,8 @@ Badge received are displayed on the user profile. 'data': [ 'security/ir.model.access.csv', 'security/gamification_security.xml', - 'gamification_view.xml', + 'views/gamification.xml', + 'wizard/grant_badge.xml', ], 'js': ['static/src/js/gamification.js'], } diff --git a/addons/hr_gamification/models/__init__.py b/addons/hr_gamification/models/__init__.py new file mode 100644 index 00000000000..51cf01dfa09 --- /dev/null +++ b/addons/hr_gamification/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import gamification diff --git a/addons/hr_gamification/gamification.py b/addons/hr_gamification/models/gamification.py similarity index 74% rename from addons/hr_gamification/gamification.py rename to addons/hr_gamification/models/gamification.py index d6fbc1ce38b..3c92514f338 100644 --- a/addons/hr_gamification/gamification.py +++ b/addons/hr_gamification/models/gamification.py @@ -20,7 +20,6 @@ ############################################################################## from openerp.osv import fields, osv -from openerp.tools.translate import _ from openerp import SUPERUSER_ID @@ -54,7 +53,7 @@ class gamification_badge(osv.Model): """Overwrite the message_post method to send the badge to the employee""" # badge_user included in the send_badge method and 'badge_id' in the wizard view if 'badge_user' in context and 'badge_id' in context: - badge = self.browse(cr, uid, context['badge_id'], context=context) + # badge = self.browse(cr, uid, context['badge_id'], context=context) badge_user = context['badge_user'] if badge_user.employee_id: return self.pool.get('hr.employee').message_post(cr, SUPERUSER_ID, @@ -80,48 +79,6 @@ class gamification_badge(osv.Model): 'domain': [('id', 'in', employee_ids)] } -class hr_grant_badge_wizard(osv.TransientModel): - _name = 'gamification.badge.user.wizard' - _inherit = ['gamification.badge.user.wizard'] - - _columns = { - 'employee_id': fields.many2one("hr.employee", string='Employee', required=True), - 'user_id': fields.related("employee_id", "user_id", - type="many2one", relation="res.users", - store=True, string='User') - } - - 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 = {} - - badge_obj = self.pool.get('gamification.badge') - badge_user_obj = self.pool.get('gamification.badge.user') - - for wiz in self.browse(cr, uid, ids, context=context): - 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.check_granting(cr, uid, - user_from_id=uid, - badge_id=wiz.badge_id.id, - context=context): - - values = { - 'user_id': wiz.user_id.id, - 'badge_id': wiz.badge_id.id, - 'employee_id': wiz.employee_id.id, - 'comment': wiz.comment, - } - badge_user = badge_user_obj.create(cr, uid, values, context=context) - - result = badge_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context) - return result - class hr_employee(osv.osv): _name = "hr.employee" diff --git a/addons/hr_gamification/gamification_view.xml b/addons/hr_gamification/views/gamification_view.xml similarity index 72% rename from addons/hr_gamification/gamification_view.xml rename to addons/hr_gamification/views/gamification_view.xml index 406d1b71a4f..e2d45948b95 100644 --- a/addons/hr_gamification/gamification_view.xml +++ b/addons/hr_gamification/views/gamification_view.xml @@ -2,48 +2,6 @@ - - - - Grant Badge Employee Form - gamification.badge.user.wizard - - - - - - - - - - - - Reward Employee Badge Form - gamification.badge.user.wizard - -
- What are you thank for? - - - - - -
-
-
-
-
- - - Badge Form gamification.badge diff --git a/addons/hr_gamification/wizard/__init__.py b/addons/hr_gamification/wizard/__init__.py new file mode 100644 index 00000000000..bb521f011bb --- /dev/null +++ b/addons/hr_gamification/wizard/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import grant_badge \ No newline at end of file diff --git a/addons/hr_gamification/wizard/grant_badge.py b/addons/hr_gamification/wizard/grant_badge.py new file mode 100644 index 00000000000..95efe444114 --- /dev/null +++ b/addons/hr_gamification/wizard/grant_badge.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2013 OpenERP SA () +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# +############################################################################## + +from openerp.osv import fields, osv +from openerp.tools.translate import _ + +class hr_grant_badge_wizard(osv.TransientModel): + _name = 'gamification.badge.user.wizard' + _inherit = ['gamification.badge.user.wizard'] + + _columns = { + 'employee_id': fields.many2one("hr.employee", string='Employee', required=True), + 'user_id': fields.related("employee_id", "user_id", + type="many2one", relation="res.users", + store=True, string='User') + } + + 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 = {} + + badge_obj = self.pool.get('gamification.badge') + badge_user_obj = self.pool.get('gamification.badge.user') + + for wiz in self.browse(cr, uid, ids, context=context): + 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.check_granting(cr, uid, + user_from_id=uid, + badge_id=wiz.badge_id.id, + context=context): + + values = { + 'user_id': wiz.user_id.id, + 'badge_id': wiz.badge_id.id, + 'employee_id': wiz.employee_id.id, + 'comment': wiz.comment, + } + badge_user = badge_user_obj.create(cr, uid, values, context=context) + + result = badge_obj.send_badge(cr, uid, wiz.badge_id.id, [badge_user], user_from=uid, context=context) + return result \ No newline at end of file diff --git a/addons/hr_gamification/wizard/grant_badge.xml b/addons/hr_gamification/wizard/grant_badge.xml new file mode 100644 index 00000000000..6dcf2d2e7c4 --- /dev/null +++ b/addons/hr_gamification/wizard/grant_badge.xml @@ -0,0 +1,46 @@ + + + + + + Grant Badge Employee Form + gamification.badge.user.wizard + + + + + + + + + + + + Reward Employee Badge Form + gamification.badge.user.wizard + +
+ What are you thank for? + + + + + +
+
+
+
+
+ + + +
+