diff --git a/addons/gamification/__openerp__.py b/addons/gamification/__openerp__.py index 855a18cb749..26cc1696fc2 100644 --- a/addons/gamification/__openerp__.py +++ b/addons/gamification/__openerp__.py @@ -33,6 +33,7 @@ 'view/menu.xml', 'cron.xml', 'report/report_progress.xml', + 'report/reminder.xml', ], 'installable': True, 'application': True, diff --git a/addons/gamification/goal.py b/addons/gamification/goal.py index 3776b008e56..704ba2bad11 100644 --- a/addons/gamification/goal.py +++ b/addons/gamification/goal.py @@ -24,7 +24,7 @@ from openerp.tools.safe_eval import safe_eval from mako.template import Template as MakoTemplate -from datetime import date, timedelta +from datetime import date, datetime, timedelta import calendar import itertools @@ -115,13 +115,6 @@ class gamification_goal_type(osv.Model): -def compute_goal_completeness(current, target_goal): - # more than 100% case is handled by the widget - if target_goal > 0: - return 100.0 * current / target_goal - else: - return 0.0 - class gamification_goal(osv.Model): """Goal instance for a user @@ -132,9 +125,14 @@ class gamification_goal(osv.Model): _inherit = 'mail.thread' def _get_completeness(self, cr, uid, ids, field_name, arg, context=None): + """Return the percentage of completeness of the goal, between 0 and 100""" res = {} for goal in self.browse(cr, uid, ids, context): - res[goal.id] = compute_goal_completeness(goal.current, goal.target_goal) + if goal.current > 0: + res[goal.id] = min(100, round(100.0 * goal.current / goal.target_goal, 2)) + else: + res[goal.id] = 0.0 + return res def on_change_type_id(self, cr, uid, ids, type_id=False, context=None): @@ -194,7 +192,6 @@ class gamification_goal(osv.Model): } - def _update_all(self, cr, uid, ids=False, context=None): """Update every goal in progress""" if not ids: @@ -208,7 +205,7 @@ class gamification_goal(osv.Model): If a goal reaches the target value, the status is set to reach If the end date is passed (at least +1 day, time not considered) without the target value being reached, the goal is set as failed.""" - + for goal in self.browse(cr, uid, ids, context=context or {}): if goal.state not in ('inprogress','inprogress_update','reached'): # skip if goal failed or canceled @@ -223,9 +220,14 @@ class gamification_goal(osv.Model): # check for remind to update if goal.remind_update_delay and goal.last_update: delta_max = timedelta(days=goal.remind_update_delay) - if fields.date.today() - goal.last_update > delta_max: + last_update = datetime.strptime(goal.last_update,'%Y-%m-%d').date() + if date.today() - last_update > delta_max: towrite['state'] = 'inprogress_update' + # generate a remind report + template_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'gamification', 'email_template_goal_reminder')[1] + self.pool.get('email.template').send_mail(cr, uid, template_id, goal.id, context=context) + else: # count or sum obj = self.pool.get(goal.type_id.model_id.model) field_date_name = goal.type_id.field_date_id.name diff --git a/addons/gamification/report/reminder.xml b/addons/gamification/report/reminder.xml new file mode 100644 index 00000000000..d184b6518de --- /dev/null +++ b/addons/gamification/report/reminder.xml @@ -0,0 +1,23 @@ + + + + + Goal Update Reminder - Send by Email + noreply@localhost + Goal Update Reminder + ${object.user_id.email} + + + +

Hello ${object.user_id.name}

+ +

You have not updated your progress for the goal ${object.type_id.name} (currently reached at ${object.completeness}%) for at least ${object.remind_update_delay}. Do not forget to do it.

+ +

If you have not changed your score yet, you can use the button "The current value is up to date" to indicate so.

+ + ]]>
+
+ +
+
diff --git a/addons/gamification/report/report_progress.xml b/addons/gamification/report/report_progress.xml index 08fa3cad3c8..08e37df1dec 100644 --- a/addons/gamification/report/report_progress.xml +++ b/addons/gamification/report/report_progress.xml @@ -1,16 +1,5 @@ - - - - Email Templates - email.template - form - form,tree - - - - diff --git a/addons/gamification/view/goal.xml b/addons/gamification/view/goal.xml index 52def276977..c983076c9ad 100644 --- a/addons/gamification/view/goal.xml +++ b/addons/gamification/view/goal.xml @@ -48,7 +48,7 @@
-