[ADD] user defined action for goal update
bzr revid: mat@openerp.com-20130327105040-ezlg1ml0xvoe5z58
This commit is contained in:
@@ -25,6 +25,9 @@ from openerp.tools.safe_eval import safe_eval
|
||||
from templates import TemplateHelper
|
||||
|
||||
from datetime import date, datetime, timedelta
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class gamification_goal_type(osv.Model):
|
||||
@@ -76,6 +79,8 @@ class gamification_goal_type(osv.Model):
|
||||
'sequence': fields.integer('Sequence',
|
||||
help='Sequence number for ordering',
|
||||
required=True),
|
||||
'action_id': fields.char("Action",
|
||||
help="The action xml id that will be called to update the goal value.")
|
||||
}
|
||||
|
||||
_order = 'sequence'
|
||||
@@ -318,16 +323,25 @@ class gamification_goal(osv.Model):
|
||||
'name': "Update %s" % goal.type_id.name,
|
||||
'id': goal_id,
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [[False, 'form']],
|
||||
'target': 'new',
|
||||
}
|
||||
if goal.type_id.action_id:
|
||||
try:
|
||||
model, xml_id = goal.type_id.action_id.split('.', 1)
|
||||
action = self.pool.get('ir.actions.act_window').for_xml_id(cr, uid, model, xml_id, context=context)
|
||||
action['res_id'] = uid
|
||||
action['context'] = context
|
||||
return action
|
||||
except ValueError:
|
||||
_logger.warning("Invalid XML ID '%s' for goal action.", goal.type_id.action_id)
|
||||
|
||||
if goal.computation_mode == 'manually':
|
||||
action['context'] = {'default_goal_id': goal_id, 'default_current': goal.current}
|
||||
action['res_model'] = 'gamification.goal.wizard'
|
||||
action['views'] = [[False, 'form']]
|
||||
action['target'] = 'new'
|
||||
else:
|
||||
action['res_model'] = goal.type_id.model_id.model
|
||||
action['views'] = [[False, 'tree']]
|
||||
return action
|
||||
return action
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class goal_manual_wizard(osv.TransientModel):
|
||||
|
||||
@@ -10,12 +10,14 @@
|
||||
<field name="model_id" eval="ref('base.model_res_users')" />
|
||||
<field name="field_id" eval="ref('base.field_res_partner_tz')" />
|
||||
<field name="domain">[('id','=',user_id),('partner_id.tz', '!=', False)]</field>
|
||||
<field name="action_id">base.action_res_users_my</field>
|
||||
</record>
|
||||
|
||||
<record model="gamification.goal.type" id="type_base_avatar">
|
||||
<field name="name">Change of avatar</field>
|
||||
<field name="description">In your user perference</field>
|
||||
<field name="computation_mode">manually</field>
|
||||
<field name="action_id">base.action_res_users_my</field>
|
||||
<!-- problem : default avatar != False
|
||||
<field name="computation_mode">count</field>
|
||||
<field name="model_id" eval="ref('base.model_res_users')" />
|
||||
|
||||
@@ -327,7 +327,7 @@ class gamification_goal_plan(osv.Model):
|
||||
for planline in plan.planline_ids:
|
||||
goal_ids = goal_obj.search(cr, uid, [('planline_id', '=', planline.id)], context=context)
|
||||
related_goal_ids.extend(goal_ids)
|
||||
|
||||
|
||||
# process the new view
|
||||
if context is None:
|
||||
context = {}
|
||||
@@ -469,7 +469,6 @@ class gamification_goal_plan(osv.Model):
|
||||
related_goal_ids = goal_obj.search(cr, uid, domain, context=context)
|
||||
|
||||
if len(related_goal_ids) == 0:
|
||||
print("no related_goal_ids")
|
||||
return False
|
||||
|
||||
values = {'goals': []}
|
||||
@@ -489,7 +488,6 @@ class gamification_goal_plan(osv.Model):
|
||||
|
||||
if all_done:
|
||||
# skip plans where all goal are done or failed
|
||||
print("all_done")
|
||||
return False
|
||||
else:
|
||||
return values
|
||||
|
||||
@@ -39,11 +39,9 @@ class res_users_gamification_group(osv.Model):
|
||||
|
||||
if plan.visibility_mode == 'board':
|
||||
# board report should be grouped by planline for all users
|
||||
print("board plan")
|
||||
goals_info = plan_obj.get_board_goal_info(cr, uid, plan, subset_goal_ids=False, context=context)
|
||||
|
||||
if not goals_info:
|
||||
print("skipping")
|
||||
continue
|
||||
|
||||
serialized_goals_info['planlines'] = []
|
||||
@@ -54,6 +52,7 @@ class res_users_gamification_group(osv.Model):
|
||||
'type_computation_mode': planline_board['goal_type'].computation_mode,
|
||||
'type_monetary': planline_board['goal_type'].monetary,
|
||||
'type_unit': planline_board['goal_type'].unit,
|
||||
'type_action': planline_board['goal_type'].action_id,
|
||||
'goals': []}
|
||||
for goal in planline_board['board_goals']:
|
||||
vals['goals'].append({
|
||||
@@ -69,11 +68,9 @@ class res_users_gamification_group(osv.Model):
|
||||
|
||||
else:
|
||||
# individual report are simply a list of goal
|
||||
print("individual plan")
|
||||
goals_info = plan_obj.get_indivual_goal_info(cr, uid, uid, plan, subset_goal_ids=False, context=context)
|
||||
|
||||
if not goals_info:
|
||||
print("skipping")
|
||||
continue
|
||||
|
||||
serialized_goals_info['goals'] = []
|
||||
@@ -85,6 +82,7 @@ class res_users_gamification_group(osv.Model):
|
||||
'type_condition': goal.type_id.condition,
|
||||
'type_monetary': goal.type_id.monetary,
|
||||
'type_unit': goal.type_id.unit,
|
||||
'type_action': goal.type_id.action_id,
|
||||
'state': goal.state,
|
||||
'completeness': goal.completeness,
|
||||
'computation_mode': goal.computation_mode,
|
||||
|
||||
@@ -75,6 +75,7 @@ openerp.gamification = function(instance) {
|
||||
var self = this;
|
||||
|
||||
self.dfm = new instance.web.form.DefaultFieldManager(self);
|
||||
// Generate a FieldMonetary for each .oe_goal_field_monetary
|
||||
self.$el.find(".oe_goal_field_monetary").each(function() {
|
||||
money_field = new instance.web.form.FieldMonetary(self.dfm, {
|
||||
attrs: {
|
||||
@@ -84,9 +85,7 @@ openerp.gamification = function(instance) {
|
||||
money_field.set('currency', currency_id);
|
||||
money_field.get_currency_info();
|
||||
money_field.set('value', parseInt($(this).text()));
|
||||
console.log(money_field.get('value'));
|
||||
money_field.replace($(this));
|
||||
console.log(money_field.$el.html());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<ul class="oe_goals_list">
|
||||
<li t-foreach="plan.goals" t-as="goal">
|
||||
<strong t-attf-class="#{goal.state == 'reached' ? 'oe_goal_reached' : goal.state == 'failed' ? 'oe_goal_failed' : ''}" t-att-title="goal.type_description"><t t-esc="goal.type_name" /></strong>
|
||||
<t t-if="goal.computation_mode == 'manually'">
|
||||
<t t-if="goal.computation_mode == 'manually' or goal.type_action">
|
||||
<a class="oe_goal_action" t-att-id="goal.id">modify</a>
|
||||
</t>
|
||||
<!-- <t t-if="goal.type_description">
|
||||
@@ -42,7 +42,7 @@
|
||||
<tr>
|
||||
<th colspan="4" t-attf-title="#{planline.type_description ? planline.type_description : ''}">
|
||||
<t t-esc="planline.type_name"/>
|
||||
<t t-if="planline.type_computation_mode == 'manually'">
|
||||
<t t-if="planline.type_computation_mode == 'manually' or planline.type_action">
|
||||
<a class="oe_goal_action" t-att-id="goal.id">modify</a>
|
||||
</t>
|
||||
</th>
|
||||
|
||||
Reference in New Issue
Block a user