diff --git a/addons/gamification/cron.xml b/addons/gamification/cron.xml index d61c6a3a318..084a878982d 100644 --- a/addons/gamification/cron.xml +++ b/addons/gamification/cron.xml @@ -20,7 +20,7 @@ -1 gamification.badge - check_automatic + _cron_check () diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py index d5357b483ab..facf623e905 100644 --- a/addons/gamification/goal.py +++ b/addons/gamification/goal.py @@ -304,3 +304,37 @@ class gamification_goal(osv.Model): plan_obj = self.pool.get('gamification.goal.plan') plan_obj.report_progress(cr, uid, goal.plan_id, users=[goal.user_id], context=context) return super(gamification_goal, self).write(cr, uid, ids, vals, context=context) + + def get_action(self, cr, uid, goal_id, context=None): + """Get the ir.action related to update the goal + + In case of a manual goal, should return a wizard to update the value + :return: dict like + { + 'name':'Action name', + 'id': goal_id, + 'type': 'ir.actions.act_window', + 'res_model': goal.type_id.model_id, + 'view': 'form', + } + """ + goal = self.browse(cr, uid, goal_id, context=context) + action = { + 'name': "Update %s" % goal.type_id.name, + 'id': goal_id, + 'type': 'ir.actions.act_window', + } + if goal.computation_mode == 'manually': + action['res_model'] = 'gamification.goal.wizard' + else: + action['res_model'] = goal.type_id.model_id # TOCHECK + return action + + +class goal_manual_wizard(osv.TransientModel): + """Wizard type to update a manual goal""" + _name = 'gamification.goal.wizard' + _columns = { + 'goal_id': fields.many2one("gamification.goal", string='Goal'), + 'current': fields.text('Current'), + } diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 485f18b67dd..cf6542b3456 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -24,6 +24,34 @@ openerp.gamification = function(instance) { var goal_id = parseInt(event.currentTarget.id); this.$el.find('.oe_type_description_'+goal_id).toggle(10); }, + 'click a.oe_goal_action': function(event) { + var self = this; + var goal_id = parseInt(event.currentTarget.id); + var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]); + + console.log(goal_action); + // var action = { + // name : 'Complete Profile', + // type: 'ir.actions.act_window', + // res_model: 'res.users', + // views: [[false, 'form']], + // res_id : event.data.uid, + // target: 'new', + // flags : { action_buttons: true }, + // }; + // var action_manager = new instance.web.ActionManager(this); + // action_manager.do_action(action); + // var form = action_manager.dialog_widget.views.form.controller; + // form.on('load_record', self, function(){ + // form.fields[$(self).attr('id')].$el.find("input").focus() + // }) + // form.on("on_button_cancel", action_manager.dialog, action_manager.dialog.close); + // form.on('save', self, function() { + // action_manager.dialog.close(); + // location.reload(); + // }); + + } }, renderElement: function() { var self = this; diff --git a/addons/gamification/static/src/xml/gamification.xml b/addons/gamification/static/src/xml/gamification.xml index 768000ba74e..2019a9f86c8 100644 --- a/addons/gamification/static/src/xml/gamification.xml +++ b/addons/gamification/static/src/xml/gamification.xml @@ -7,9 +7,9 @@