diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py
index facf623e905..976ea5ce8ef 100644
--- a/addons/gamification/goal.py
+++ b/addons/gamification/goal.py
@@ -309,25 +309,22 @@ class gamification_goal(osv.Model):
"""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',
- }
+ :return: action description in a dictionnary
"""
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',
+ 'target': 'new',
}
if goal.computation_mode == 'manually':
action['res_model'] = 'gamification.goal.wizard'
+ action['views'] = [[False, 'form']]
+ action['context'] = {'default_goal_id': goal_id, 'default_current': goal.current},
else:
- action['res_model'] = goal.type_id.model_id # TOCHECK
+ action['res_model'] = goal.type_id.model_id.model
+ action['views'] = [[False, 'tree']]
return action
@@ -336,5 +333,22 @@ class goal_manual_wizard(osv.TransientModel):
_name = 'gamification.goal.wizard'
_columns = {
'goal_id': fields.many2one("gamification.goal", string='Goal'),
- 'current': fields.text('Current'),
+ 'current': fields.float('Current'),
}
+
+ def action_update_current(self, cr, uid, ids, context=None):
+ """Wizard action for updating the current value"""
+ if context is None:
+ context = {}
+
+ 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,
+ }
+ print(towrite)
+ 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/goal_view.xml b/addons/gamification/goal_view.xml
index 7f3cdd764c6..cc5f5027e04 100644
--- a/addons/gamification/goal_view.xml
+++ b/addons/gamification/goal_view.xml
@@ -246,6 +246,26 @@
+
+
+ Update the current value of the Goal
+ gamification.goal.wizard
+
+
+
+
+
+
diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js
index cf6542b3456..d24e0b4159c 100644
--- a/addons/gamification/static/src/js/gamification.js
+++ b/addons/gamification/static/src/js/gamification.js
@@ -27,29 +27,16 @@ openerp.gamification = function(instance) {
'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]);
+ var goal_action = new instance.web.Model('gamification.goal').call('get_action', [goal_id]).then(function(res) {
+ goal_action['action'] = res;
+ });
+ $.when(goal_action).done(function() {
+ console.log(goal_action);
+ var action_manager = new instance.web.ActionManager(this);
+ action_manager.do_action(goal_action.action);
- 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();
- // });
+ //var form = action_manager.dialog_widget.views.form.controller;
+ });
}
},