'This route/function is called when we want to synchronize openERP calendar with Google Calendar
Function return a dictionary with the status :  need_config_from_admin, need_auth, need_refresh, success if not calendar_event
The dictionary may contains an url, to allow OpenERP Client to redirect user on this URL for authorization for example'

@http.route('/google_calendar/sync_data', type='json', auth='user')
def sync_data(self, arch, fields, model, **kw):

    if (model == 'calendar.event'):
        GoogleService = request.env['google.service']
        GoogleCal = request.env['google.calendar']
        context = kw.get('local_context', {})
        client_id = GoogleService.with_context(context).get_client_id('calendar')
        if ((not client_id) or (client_id == '')):
            action_id = ''
            if GoogleCal.can_authorize_google():
                action_id = request.env.ref('google_calendar.action_config_settings_google_calendar').id
            return {'status': 'need_config_from_admin', 'url': '', 'action': action_id}
        if GoogleCal.need_authorize():
            url = GoogleCal.with_context(context).authorize_google_uri(from_url=kw.get('fromurl'))
            return {'status': 'need_auth', 'url': url}
        return GoogleCal.with_context(context).synchronize_events()
    return {'status': 'success'}
