diff options
| author | Martin Trigaux <mat@openerp.com> | 2013-03-27 11:50:40 +0100 |
|---|---|---|
| committer | Martin Trigaux <mat@openerp.com> | 2013-03-27 11:50:40 +0100 |
| commit | b08a2f2bbc8f615b778ec75e4b8f410626c52800 (patch) | |
| tree | a782a6cbad8f2f220d7b4113c467638975662daa /addons | |
| parent | 6674de3e04d258d9408034f15270ac98f4e31c9e (diff) | |
[ADD] user defined action for goal update
bzr revid: mat@openerp.com-20130327105040-ezlg1ml0xvoe5z58
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/gamification/goal.py | 26 | ||||
| -rw-r--r-- | addons/gamification/goal_base_data.xml | 2 | ||||
| -rw-r--r-- | addons/gamification/plan.py | 4 | ||||
| -rw-r--r-- | addons/gamification/res_users.py | 6 | ||||
| -rw-r--r-- | addons/gamification/static/src/js/gamification.js | 3 | ||||
| -rw-r--r-- | addons/gamification/static/src/xml/gamification.xml | 4 |
6 files changed, 28 insertions, 17 deletions
diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py index 40cc304806c..a020e98e6e5 100644 --- a/addons/gamification/goal.py +++ b/addons/gamification/goal.py @@ -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): diff --git a/addons/gamification/goal_base_data.xml b/addons/gamification/goal_base_data.xml index cc757a0126b..fca4a2cd04f 100644 --- a/addons/gamification/goal_base_data.xml +++ b/addons/gamification/goal_base_data.xml @@ -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')" /> diff --git a/addons/gamification/plan.py b/addons/gamification/plan.py index 607f04ca98b..9bd658703ed 100644 --- a/addons/gamification/plan.py +++ b/addons/gamification/plan.py @@ -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 diff --git a/addons/gamification/res_users.py b/addons/gamification/res_users.py index 70d8054b3cb..123bb49c7f0 100644 --- a/addons/gamification/res_users.py +++ b/addons/gamification/res_users.py @@ -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, diff --git a/addons/gamification/static/src/js/gamification.js b/addons/gamification/static/src/js/gamification.js index 62de4835842..dfd8b2f607b 100644 --- a/addons/gamification/static/src/js/gamification.js +++ b/addons/gamification/static/src/js/gamification.js @@ -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()); }); } }); diff --git a/addons/gamification/static/src/xml/gamification.xml b/addons/gamification/static/src/xml/gamification.xml index 31664f4c4f4..6eca4093084 100644 --- a/addons/gamification/static/src/xml/gamification.xml +++ b/addons/gamification/static/src/xml/gamification.xml @@ -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> |
