Automating Your Retail Workflow: How to Close POS Sessions in Odoo 17 via Server Actions

Managing a busy retail environment means every second counts. In Odoo 17, while the Point of Sale (POS) is more fluid than ever, managers often find themselves needing a faster way to wrap up the day or handle multiple sessions at once.

Today at Ozonlayer, we’re diving into a quick technical “hack” to streamline your end-of-day operations using Server Actions.

Why Use a Server Action to Close Sessions?

Normally, closing a session involves several clicks: closing the interface, validating the orders, and clicking “Close Session” in the backend. A Server Action allows you to:

  • Batch Close: Close multiple sessions across different branches simultaneously.
  • Automate: Trigger a close based on specific conditions or schedules.
  • Efficiency: Reduce the manual oversight required for daily accounting entries.

Step-by-Step Guide: Creating the “Quick Close” Action

To get started, ensure you have Developer Mode activated in your Odoo 17 instance.

1. Create the Action

Navigate to Settings > Technical > Actions > Server Actions and create a new record.

  • Action Name: Ozonlayer: Force Close Session
  • Model: pos.session
  • Action To Do: Execute Code

2. The Python Logic

In the code editor, input the following logic. This script targets sessions that are currently open and triggers Odoo’s native closing and posting sequence.

Python

for record in records:
    if record.state == 'opened':
        # Validates and posts the journal entries
        record.action_pos_session_closing_control()

3. Make it Accessible

Click the Create Contextual Action button at the top of the form. This adds your new tool to the “Action” gear icon menu in the POS Session list view.


What Happens Under the Hood?

When you trigger action_pos_session_closing_control(), Odoo 17 performs several critical tasks:

  1. Order Validation: It ensures all orders in the session are synchronized.
  2. Journal Entries: It automatically generates the moves in your Accounting app.
  3. Stock Moves: It finalizes the inventory depletions based on the day’s sales.

Ozonlayer Pro-Tip: If your POS has a cash discrepancy (the “Real” balance doesn’t match the “Expected” balance), Odoo may prevent a background close. Ensure your POS Journal has Default Profit/Loss Accounts configured to allow Odoo to post the difference automatically.


Final Thoughts

At Ozonlayer, we believe Odoo should work for you, not the other way around. By implementing small automations like this Server Action, you free up your management team to focus on what really matters: your customers.

Need help customizing your Odoo 17 workflow? Reach out to the Ozonlayer team today for expert implementation and support!