'Update the challenges and related goals
:param list(int) ids: the ids of the challenges to update, if False will
update only challenges in progress.'

def _update_all(self):

    if (not self):
        return True
    Goals = self.env['gamification.goal']
    yesterday = fields.Date.to_string((date.today() - timedelta(days=1)))
    self.env.cr.execute("SELECT    gg.id\n                                                                                                FROM    gamification_goal    as    gg,\n                                                                                                                    gamification_challenge    as    gc,\n                                                                                                                    res_users    as    ru,\n                                                                                                                    res_users_log    as    log\n                                                                                            WHERE    gg.challenge_id    =    gc.id\n                                                                                                    AND    gg.user_id    =    ru.id\n                                                                                                    AND    ru.id    =    log.create_uid\n                                                                                                    AND    gg.write_date    <    log.create_date\n                                                                                                    AND    gg.closed    IS    false\n                                                                                                    AND    gc.id    IN    %s\n                                                                                                    AND    (gg.state    =    'inprogress'\n                                                                                                                        OR    (gg.state    =    'reached'\n                                                                                                                                        AND    (gg.end_date    >=    %s    OR    gg.end_date    IS    NULL)))\n                                                                                        GROUP    BY    gg.id\n                                ", [tuple(self.ids), yesterday])
    Goals.browse((goal_id for [goal_id] in self.env.cr.fetchall())).update_goal()
    self._recompute_challenge_users()
    self._generate_goals_from_challenge()
    for challenge in self:
        if (challenge.last_report_date != fields.Date.today()):
            closed_goals_to_report = Goals.search([('challenge_id', '=', challenge.id), ('start_date', '>=', challenge.last_report_date), ('end_date', '<=', challenge.last_report_date)])
            if (challenge.next_report_date and (fields.Date.today() >= challenge.next_report_date)):
                challenge.report_progress()
            elif closed_goals_to_report:
                challenge.report_progress(subset_goals=closed_goals_to_report)
    self._check_challenge_reward()
    return True
