Are you tired of dealing with pesky rescue sessions in Odoo? Do you find yourself constantly checking for inactive sessions and manually changing their status? Fear not, for we have a solution!

Introducing our revolutionary tutorial on how to automatically change the status of rescue sessions in Odoo. With just a few simple steps, you can finally say goodbye to the never-ending cycle of monitoring and updating these sessions.

Rescue sessions can be created for various reasons but for simplicity, lets consider the following.

For example,

Imagine you're running a business and you only have one physical POS terminal and on it and you have a regular POS session opened. When its time for you to close, you will begin by executing the required steps to close that session.

During this time, a customer decides to walk in and you will need to serve them. Since the regular session is in “closing control” mode, open a new browser tab and navigate to the POS front-end URL. If you complete a transaction now, it will be assigned to a “Rescue Session”.

Later, once you are ready to open a new session, you will follow the standard procedure and proceed with the steps. Now, if you go to the list of POS sessions, you will see that, a regular session and a Rescue session will be open. Although, its fine to have both at the same time, you will have issues with accounting and tallying up the total.

Method #1

To help with this issue, you can create the following Automated Actions which will help with that. See the example trigger below for guidance.

Here are the values for ease of copy and paste.

Title: Automatically close Rescue sessions and post entries

Trigger: On Creation & Update

Before update: ["&","rescue","=",False,["state","=","opening_control"]]

Apply on: ["&","state","=","opened",["rescue","=",False]]

Action to do: Execute Python Code

Here is the python code to execute.

rescue_session = env['pos.session'].search([('state', '=', 'opening_control'),('name', 'ilike', 'RESCUE FOR POS')])rescue_orders = env['pos.order'].search([('state', '=', 'paid'),('session_id', 'ilike', 'RESCUE FOR POS')])if rescue_orders:  rescue_orders.write({'state': 'done'})  rescue_session.action_pos_session_closing_control()Code language: JavaScript (javascript)

Method #2

  1. First, create a new scheduled action that runs every few minutes or hours (depending on how often you want to check for inactive sessions). To do this, go to Settings > Automation > Scheduled Actions and click “Create”.
  2. In the “Action Type” field, select “Execute Python Code”. Then, give your scheduled action a name and set the interval at which you want it to run.
  3. In the “Python Code” field, paste the following code:
from datetime import datetime, timedeltarescue_sessions = env['rescue.session'].search([('state', '=', 'in_progress')])for session in rescue_sessions:    last_activity_time = datetime.strptime(session.last_activity, '%Y-%m-%d %H:%M:%S')    time_since_last_activity = datetime.now() - last_activity_time    if time_since_last_activity > timedelta(minutes=30):        session.write({'state': 'cancelled'})Code language: JavaScript (javascript)

This code will search for all rescue sessions that are in progress and have been inactive for more than 30 minutes. It will then change the state of these sessions to “Cancelled”.

  1. Save your scheduled action.
  2. Finally, go to Settings > Technical > Automation > Scheduled Actions and find your scheduled action in the list. Make sure it is enabled by checking the “Active” checkbox.

That's it! Your scheduled action will now automatically change the status of any rescue sessions that have been inactive for more than 30 minutes to “Cancelled”. You can modify the code to change the status to “Closed” or any other status as per your requirement.

If you find this useful, feel free to leave a comment below.

Similar Posts

Leave a Reply