Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
1399 Vues

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.model
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()
By using this code, i get an error,
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:

Avatar
Ignorer
Meilleure réponse

Hi,

Please refer to the module:

https://apps.odoo.com/apps/modules/17.0/auto_logout_idle_user_odoo

You can find the latest version from V14 to V18.


Hope it helps.

Avatar
Ignorer
Meilleure réponse

Implementing a scheduled user logout in Odoo 17 can enhance security and ensure compliance with organizational policies. The approach involves creating a scheduled action that logs out users at a specified time. However, as you've encountered errors with your current implementation, here's a refined method to achieve this:​

1. Utilize the auth_session_timeout Module:

The Inactive Sessions Timeout module, developed by the Odoo Community Association (OCA), allows administrators to define a timeout for inactive sessions. This module can be configured to log out users after a specified period of inactivity. You can set the session validity duration by adjusting the inactive_session_time_out_delay parameter, which defines the session validity in seconds (default is 2 hours). ​

2. Implement Custom Scheduled Actions:

If a specific logout time is required (e.g., midnight), you can create a scheduled action within Odoo:​

  • Define the Scheduled Action:
    • Navigate to Settings > Technical > Automation > Scheduled Actions.​
    • Create a new scheduled action that calls a custom method to terminate user sessions at the desired time.​
  • Develop the Custom Method:
    • Create a method in a custom module that identifies active sessions and terminates them.​
    • Ensure proper handling of session termination to avoid errors and ensure system stability.​

3. Addressing Implementation Errors:

Errors in scheduled actions can arise from various factors, including incorrect method definitions or access rights issues. It's crucial to review the error logs to identify the specific cause. Ensuring that the method has the necessary permissions and correctly interacts with the session management system is vital.​

At Wan Buffer Services, we specialize in customizing Odoo functionalities to align with organizational requirements. Implementing scheduled user logouts can be tailored to your specific needs, ensuring both security and compliance.

Avatar
Ignorer
Publications associées Réponses Vues Activité
2
juin 25
1094
0
août 24
1609
4
juin 25
2040
0
mars 25
974
0
mai 24
1241