'Daily cron check.
- Start planned challenges (in draft and with start_date = today)
- Create the missing goals (eg: modified the challenge to add lines)
- Update every running challenge'

@api.model
def _cron_update(self, ids=False):

    planned_challenges = self.search([('state', '=', 'draft'), ('start_date', '<=', fields.Date.today())])
    if planned_challenges:
        planned_challenges.write({'state': 'inprogress'})
    scheduled_challenges = self.search([('state', '=', 'inprogress'), ('end_date', '<', fields.Date.today())])
    if scheduled_challenges:
        scheduled_challenges.write({'state': 'done'})
    records = (self.browse(ids) if ids else self.search([('state', '=', 'inprogress')]))
    return records.with_context(commit_gamification=True)._update_all()
