Web Timezone Switcher
by Apexive Solutions LLC https://github.com/smartops-aero/smartops-odoo-flight| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 565 |
| Technical Name |
web_tz_switcher |
| License | LGPL-3 |
| Website | https://github.com/smartops-aero/smartops-odoo-flight |
| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 565 |
| Technical Name |
web_tz_switcher |
| License | LGPL-3 |
| Website | https://github.com/smartops-aero/smartops-odoo-flight |
Web Timezone Switcher
Real-time timezone switching for Odoo display without database modifications. Switch between timezones instantly — all datetime fields update automatically.
What Is It?
This module adds a systray dropdown that allows users to switch their display timezone in real-time without modifying any database records. All datetime fields automatically re-render in the selected timezone. Perfect for aviation operations, global teams, and multi-timezone business operations.
See It In Action
Systray dropdown with live clock, search, and one-click reset.
Key Features
Session-Based Switching
No database modifications. Timezone preference is stored in session context only, keeping your user records clean.
Auto Re-rendering
All datetime fields update immediately when you switch timezone. No manual refresh needed.
Persistent Preference
Your timezone choice survives page reloads via localStorage. Resets after logout for security.
Full IANA Support
Complete pytz timezone database with 400+ timezones. Search by city, country, or region.
Smart Search
Quick timezone lookup with search-as-you-type. Timezones organized by region for easy browsing.
Live Clock Display
Shows current time in selected timezone with live updates. Override indicator when using non-default timezone.
Use Cases
Aviation Operations
View flight times in departure, arrival, or UTC timezone. Perfect for dispatchers and operations teams working across time zones.
Global Support Teams
Switch to customer's timezone to understand when issues occurred. Better communication and faster resolution.
Multi-Region Business
View reports in regional timezones: APAC, EMEA, Americas. Make sense of data in local context.
How It Works
- Click the timezone dropdown in the systray (top-right corner)
- Search or browse available timezones by region
- Select a timezone — all datetime fields re-render immediately
- Reset to default — click "Reset to Default" when in override mode
Technical Highlights
No Database Modifications
All times in the database remain in UTC. Only the display is affected. User records are never modified.
Developer Friendly
Provides a timezone_switcher service for programmatic access. Easy integration with custom components.
Ready to Go Global?
Install now and switch timezones instantly. No configuration needed!
All database times remain in UTC
Web Timezone Switcher
Real-time timezone switching for Odoo display without database modifications.
Overview
This module adds a systray dropdown that allows users to switch their display timezone in real-time without modifying any database records. All datetime fields automatically re-render in the selected timezone.
Key Features
- Session-based switching - No database modifications
- Systray integration - Easy access from any page
- Auto re-rendering - Datetime fields update immediately
- Persistent preference - Survives page reloads via localStorage
- User default fallback - Gracefully falls back to user's configured timezone
- IANA timezone support - Full pytz timezone database
- Search functionality - Quick timezone lookup
- UTC offset display - Shows offset for each timezone
- Current time display - Live clock in selected timezone
- Override indicator - Badge shows when using non-default timezone
Installation
- Copy the web_tz_switcher module to your addons directory
- Update the module list: Settings → Technical → Database Structure → Update Apps List
- Install the module: Apps → Search "Web Timezone Switcher" → Install
No configuration needed - works immediately after installation!
Usage
Basic Usage
- Click the timezone dropdown in the systray (top-right corner)
- Search or browse available timezones by region
- Select a timezone - All datetime fields re-render immediately
- Reset to default - Click "Reset to Default" button when in override mode
Features
Live Time Display
The systray shows:
- Current timezone abbreviation (e.g., "New York (14:30)")
- Live clock updating every second
- Warning badge when using override timezone
Smart Timezone Selection
The dropdown provides:
- Search box - Type to filter timezones (e.g., "york", "tokyo")
- Regional grouping - Timezones organized by continent
- UTC offsets - Each timezone shows its current UTC offset
- Current indicator - Checkmark shows active timezone
- Show All Regions - Toggle to see all available regions
Session Persistence
Your timezone preference:
- Persists across page navigation
- Survives browser refresh (localStorage)
- Resets after logout
- Independent per browser/device
Technical Details
Architecture
┌─────────────────────────────────────────────────┐
│ Frontend (Browser) │
│ ┌───────────────────────────────────────────┐ │
│ │ Systray Component │ │
│ │ - Timezone dropdown UI │ │
│ │ - Search & selection │ │
│ └───────────────────────────────────────────┘ │
│ ┌───────────────────────────────────────────┐ │
│ │ Timezone Service │ │
│ │ - RPC calls to backend │ │
│ │ - User context updates │ │
│ │ - View re-rendering │ │
│ │ - localStorage persistence │ │
│ └───────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
│ JSON-RPC
▼
┌─────────────────────────────────────────────────┐
│ Backend (Odoo Server) │
│ ┌───────────────────────────────────────────┐ │
│ │ Controller │ │
│ │ /web/timezone/switch │ │
│ │ /web/timezone/reset │ │
│ │ /web/timezone/current │ │
│ │ /web/timezone/list │ │
│ └───────────────────────────────────────────┘ │
│ ┌───────────────────────────────────────────┐ │
│ │ Session Context │ │
│ │ request.session.context['tz'] = 'UTC+5' │ │
│ └───────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Database (PostgreSQL) │
│ - All datetime fields remain in UTC │
│ - No user records modified │
│ - No timezone data stored │
└─────────────────────────────────────────────────┘
How It Works
- User selects timezone in systray dropdown
- Service calls backend via /web/timezone/switch
- Backend validates timezone against pytz database
- Session context updated with tz parameter
- User context patched via user.updateContext({ tz })
- Current view reloads triggering datetime re-rendering
- Preference stored in browser localStorage
- All datetime fields now display in selected timezone
Key Design Principles
No Database Modifications
# NEVER does this: user.write({'tz': 'America/New_York'}) # ONLY does this: request.session.context['tz'] = 'America/New_York'
Session-Based Storage
// Frontend updates user context (affects rendering only) user.updateContext({ tz: timezone }); // Backend updates session context request.session.context = { ...context, tz: timezone };
Graceful Fallback
Selected Timezone (session context)
↓ (if not set)
User's Default Timezone (res.users.tz)
↓ (if not set)
UTC
API Reference
Backend Endpoints
POST /web/timezone/switch
Switch to a new timezone.
Request:
{ "timezone": "America/New_York" }
Response:
{ "success": true, "timezone": "America/New_York", "user_context": { "tz": "America/New_York" } }
POST /web/timezone/reset
Reset to user's default timezone.
Response:
{ "success": true, "timezone": "UTC", "user_context": {} }
POST /web/timezone/current
Get current timezone information.
Response:
{ "timezone": "America/New_York", "is_override": true, "user_default": "UTC", "session_context": {} }
POST /web/timezone/list
Get available timezones.
Request:
{ "common_only": true }
Response:
{ "timezones": ["America/New_York", "Europe/London"], "grouped": { "America": ["America/New_York"], "Europe": ["Europe/London"] }, "count": 400 }
Frontend Service
import { useService } from "@web/core/utils/hooks"; const timezoneSwitcher = useService("timezone_switcher"); // Get current timezone const tz = await timezoneSwitcher.getCurrentTimezone(); // Switch timezone await timezoneSwitcher.switchTimezone("Europe/Paris"); // Reset to default await timezoneSwitcher.resetTimezone(); // List timezones const { timezones, grouped } = await timezoneSwitcher.listTimezones(true);
Use Cases
Aviation Operations
Perfect for flight operations spanning multiple timezones:
User in London (GMT) viewing: - Flight departure: Los Angeles 10:00 PST - Flight arrival: New York 18:00 EST Switch to PST: - Departure: 10:00 PST ✓ - Arrival: 15:00 PST Switch to EST: - Departure: 13:00 EST - Arrival: 18:00 EST ✓
Global Support Teams
Support staff can switch to customer's timezone:
Support Agent in India (IST): Customer ticket timestamp: 2024-12-03 09:00 PST Switch to PST: Ticket created: 09:00 PST (customer's local time)
Multi-Region Business
View reports in different regional timezones:
Sales Manager reviewing regional reports: - APAC sales: Switch to Asia/Tokyo - EMEA sales: Switch to Europe/London - Americas sales: Switch to America/New_York
Compatibility
- Odoo Version: 18.0
- Python: 3.10+
- Dependencies: web (core Odoo module)
- Browser: Modern browsers with localStorage support
Testing
Run the included test suite:
# Run all tests odoo-bin -c odoo.conf --test-enable --stop-after-init \ --test-tags=web_tz_switcher -d test_db -u web_tz_switcher # Run specific test odoo-bin -c odoo.conf --test-enable --stop-after-init \ --test-tags=web_tz_switcher.test_timezone_controller -d test_db
Test coverage:
- Valid timezone switching
- Invalid timezone handling
- Reset to default
- Session persistence
- Override flag behavior
- Timezone listing (common & all)
Troubleshooting
Timezone not persisting after refresh
Cause: localStorage disabled or browser in private mode
Solution: Enable localStorage or accept that timezone resets each session
Datetime fields not updating
Cause: Custom datetime widgets not using Odoo's standard context
Solution: Ensure custom widgets read user.context.tz
Timezone dropdown not appearing
Cause: Asset bundle not loaded
Solution: Clear browser cache and reload: Ctrl+Shift+R
Performance issues with many datetime fields
Cause: Full page reload on timezone switch
Solution: Consider selective re-rendering (advanced customization)
License
LGPL-3.0
Author
Apexive Solutions LLC
Website: https://apexive.com
Credits
Built with:
- Odoo OWL framework
- Luxon datetime library
- Python pytz library
- Bootstrap styling
Remember: This module only changes display. All database times remain in UTC!
Please log in to comment on this module