Skip to content

Conversation

@zamberjo
Copy link
Member

@zamberjo zamberjo commented Dec 16, 2025

📝 TL;DR

Real-time UI synchronization for Odoo 17
Say goodbye to manual F5 and the legacy patterns of web_refresher. This module introduces a clean, bus-based approach to keep views updated across different sessions automatically. By using a backend mixin and a dedicated OWL hook (useRecordStream), developers can now ensure users always see the latest data without the overhead of constant polling or manual reloads. A simple way to make Odoo feel more collaborative and reactive.

Grabacion.de.pantalla.desde.2025-12-19.20-38-17.webm

This PR introduces three new modules designed to bring real-time reactivity to Odoo views via the Bus system:

bus_record_events: The core module. It provides a mixin (bus.record.event.mixin) that broadcasts CRUD operations (create, write, unlink) to the Odoo Bus. It also includes specialized JS classes for views (Form, Kanban, List, etc.) that listen to these events and update the interface automatically.
bus_record_events_all: An extension that automatically applies the mixin to all models in the system and injects the reactive JS classes into views globally.
bus_record_events_demo: Contains demo data and examples to showcase the functionality.

Testing Instructions:

To verify the functionality using the demo module (bus_record_events_demo):

  1. Ensure the bus_record_events_demo module is installed.
  2. Open two different browsers (or use an incognito window) to simulate two concurrent sessions.
  3. Log in with the provided demo users:
  • User 1: Login: demo_bus_1 / Password: demo_bus_1
  • User 2: Login: demo_bus_2 / Password: demo_bus_2
  1. Navigate to the Bus Event Demo menu.
  2. Interact with the records (Create, Edit, Delete) in one session and observe the real-time updates in the other session (e.g., open a Form view in one and modify it in the other, or watch the Kanban view update automatically).

JavaScript API:

This module exposes tools for developers to build reactive OWL components easily:

bus_record_event_service: A new service that manages the subscription to record_events channels. It handles the underlying bus connection and dispatches notifications to subscribers.
useRecordStream: A custom OWL hook designed to simplify component integration. It automatically handles the lifecycle of the subscription (adding channels on onWillStart, unsubscribing on onWillUnmount) and provides callbacks for common actions:

  • onReload: Triggered when a record changes (useful for refreshing views).
  • isDirty: Checks if the current view has unsaved changes before acting.
  • onUpdate: Allows custom handling of the event payload.

Example Usage

// So simple it feels native
useRecordStream("res.partner", {
    id: this.props.resId,
    onReload: async () => await this.model.load(),
});

Design Decision regarding bus_record_events_all:

We considered including the global broadcasting functionality directly within the core bus_record_events module, controlled by an ir.config_parameter (defaulting to False). However, this approach would require checking the system parameter during every single CRUD operation across the entire system, which raised concerns about potential performance overhead.

To ensure the core module remains lightweight and performant, we decided to isolate this functionality into a separate module (bus_record_events_all). This approach avoids unnecessary checks in the CRUD methods and gives administrators explicit control over enabling this resource-intensive feature simply by installing or uninstalling the module.

@zamberjo zamberjo force-pushed the 17.0-add-bus_record_events-module branch from c3fde21 to 664b015 Compare December 16, 2025 06:55
@zamberjo zamberjo force-pushed the 17.0-add-bus_record_events-module branch from 664b015 to ee9fe49 Compare December 16, 2025 07:07
@zamberjo zamberjo marked this pull request as ready for review December 16, 2025 07:11
@ivs-cetmix
Copy link
Member

Hey @zamberjo thank you for your contribution! Some notes:

@zamberjo
Copy link
Member Author

Hi @ivs-cetmix thanks for the comment!

Just to clarify an important point: PR #3396 is not equivalent to #3363, even though both deal with UI updates from backend changes.

#3363 (web_refresh_from_backend) focuses on forcing view reloads from the backend and requires manual integration in the backend code where a refresh is needed.

#3396 (bus_record_events) introduces an event-driven approach based on the bus, providing mixins, services, and OWL hooks so the UI can react to record changes. It enables automatic view refresh out of the box and allows building more fine-grained, near real-time reactive views beyond full reloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants