From 3ff7b48a811bf04aafa70a6ce0db73122cee4bcc Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 14 May 2014 10:59:20 +0200 Subject: [PATCH] [FIX] gamification: make sure than a cron running more than once a day will not report the progress more than once --- addons/gamification/models/challenge.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/addons/gamification/models/challenge.py b/addons/gamification/models/challenge.py index 8ed3890ce69..222e5cca49e 100644 --- a/addons/gamification/models/challenge.py +++ b/addons/gamification/models/challenge.py @@ -329,19 +329,20 @@ class gamification_challenge(osv.Model): self.write(cr, uid, [challenge.id], {'user_ids': [(4, user.id) for user in challenge.autojoin_group_id.users]}, context=context) self.generate_goals_from_challenge(cr, uid, [challenge.id], context=context) - # goals closed but still opened at the last report date - closed_goals_to_report = goal_obj.search(cr, uid, [ - ('challenge_id', '=', challenge.id), - ('start_date', '>=', challenge.last_report_date), - ('end_date', '<=', challenge.last_report_date) - ]) + if challenge.last_report_date != fields.date.today(): + # goals closed but still opened at the last report date + closed_goals_to_report = goal_obj.search(cr, uid, [ + ('challenge_id', '=', challenge.id), + ('start_date', '>=', challenge.last_report_date), + ('end_date', '<=', challenge.last_report_date) + ]) - if len(closed_goals_to_report) > 0: - # some goals need a final report - self.report_progress(cr, uid, challenge, subset_goal_ids=closed_goals_to_report, context=context) + if fields.date.today() >= challenge.next_report_date: + self.report_progress(cr, uid, challenge, context=context) - if fields.date.today() == challenge.next_report_date: - self.report_progress(cr, uid, challenge, context=context) + elif len(closed_goals_to_report) > 0: + # some goals need a final report + self.report_progress(cr, uid, challenge, subset_goal_ids=closed_goals_to_report, context=context) self.check_challenge_reward(cr, uid, ids, context=context) return True