Hi,
I need to log out my session on a specific time, how i do that? i did but i get an error, how i solve this? I created a scheduled action for this. I found out the problem is that, we can't use the http.request in the cron job. So what method i can use in this to logout the session on a specific time?
@api.modelBy using this code, i get an error,
def logout_users_at_midnight(self):
users = self.sudo().search([('active', '=', True)])
for user in users:
user_timezone = pytz.timezone(user.tz or 'UTC')
current_time = datetime.now(user_timezone)
if current_time.hour == 5 and current_time.minute == 35:
self.logout_user(user)
def logout_user(self, user):
if request.session:
request.session.logout()
raise RuntimeError("object unbound")
RuntimeError: object unbound
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
ValueError: <class 'RuntimeError'>: "object unbound" while evaluating
'model.logout_users_at_midnight()'
During handling of the above exception, another exception occurred: