feat: implement PosController override to redirect users to the POS dashboard when no active session exists

This commit is contained in:
Suherdy Yacob 2026-05-21 09:20:36 +07:00
parent a93a0bc3b8
commit f5f5af9025
4 changed files with 18 additions and 1 deletions

View File

@ -10,6 +10,7 @@ By default, Odoo prevents a POS session from closing if there are still unpaid o
2. **Morning Shift Validation Bypass**: If a cashier attempts to close a session *before* the configured cutoff time, the standard Odoo check for draft orders is bypassed.
3. **Automatic Order Transfer**: When the next session (Afternoon shift) is opened for the same POS, the module automatically scans previously closed sessions and moves any remaining draft orders to the newly opened session.
4. **Standard Night Flow Restriction**: If a session is closed *after* the cutoff time (i.e., at the end of the day), the standard Odoo behavior applies, and the session cannot be closed until all pending orders are either paid or cancelled.
5. **Session Closure Redirection Fix**: Prevents Odoo from automatically creating and opening a new session immediately after a successful closure by cleanly redirecting the browser back to the backend POS dashboard.
## Setup & Configuration
1. Install the module `pos_shift_close` on your Odoo 19 instance.
@ -19,5 +20,6 @@ By default, Odoo prevents a POS session from closing if there are still unpaid o
## Technical Details
- **Dependency**: Requires `point_of_sale`.
- **Overrides**: Implements specific overrides in `_check_if_no_draft_orders` and `_set_opening_control_data` inside `pos.session` model.
- **Overrides (Python Models)**: Implements specific overrides in `_check_if_no_draft_orders` and `_set_opening_control_data` inside the `pos.session` model.
- **Overrides (Controllers)**: Inherits standard Odoo's `PosController` and overrides the `pos_web` method/route to intercept direct `/pos/ui/<config_id>` loads. If there is no active session (`has_active_session` is `False`) and the request is not from backend dashboard (`from_backend` is `False`), the user is redirected back to the backend.
- Time conversions correctly compare against the user's localized timezone (`self.env.user.tz`).

View File

@ -1 +1,2 @@
from . import models
from . import controllers

1
controllers/__init__.py Normal file
View File

@ -0,0 +1 @@
from . import main

13
controllers/main.py Normal file
View File

@ -0,0 +1,13 @@
from odoo import http
from odoo.http import request
from odoo.addons.point_of_sale.controllers.main import PosController
class PosControllerInherit(PosController):
@http.route(["/pos/ui/<config_id>", "/pos/ui/<config_id>/<path:subpath>"], auth="user", type='http')
def pos_web(self, config_id=False, from_backend=False, subpath=None, **k):
if config_id:
pos_config = request.env['pos.config'].sudo().browse(int(config_id))
if pos_config.exists() and not pos_config.has_active_session and not from_backend:
return request.redirect('/odoo/action-point_of_sale.action_client_pos_menu')
return super().pos_web(config_id=config_id, from_backend=from_backend, subpath=subpath, **k)