Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions web_refresh_from_backend/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
========================
Web Refresh From Backend
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3fa12acb12fc8ba91141e344bd5dde385fc00e19cd307fd40c253be39dd8111f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/17.0/web_refresh_from_backend
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_refresh_from_backend
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Backend UI Reload Module
========================

This is a **technical module** that allows triggering a **UI reload**
from the backend. It enables triggering the reload action for selected
users and record IDs.

**NB:** this module refreshes views using direct actions instead of
calling ``action_reload``. This is done to avoid possible glitches and
is aligned with the same approach used in the
`web_refreshed <https://github.com/OCA/web/tree/16.0/web_refresher>`__
module.

--------------

🔧 Helper Function: ``reload_views``
------------------------------------

A special helper function ``reload_views`` is added to the ``res.users``
model.

**Arguments**
~~~~~~~~~~~~~

+----------------+-------------------------+-------------------------+
| Argument | Type | Description |
+================+=========================+=========================+
| **model** | ``Char`` | Model name, e.g. |
| | | ``'res.partner'`` |
+----------------+-------------------------+-------------------------+
| **view_types** | ``List of Char`` | View types to reload, |
| | *(optional)* | e.g. |
| | | ``["form", "kanban"]``. |
| | | Leave blank to reload |
| | | all views. |
+----------------+-------------------------+-------------------------+
| **rec_ids** | ``List of Integer`` | The view will be |
| | *(optional)* | reloaded only if a |
| | | record with an ID from |
| | | this list is present in |
| | | the view. |
+----------------+-------------------------+-------------------------+

--------------

⚠️ Important Notes
------------------

Use this function **wisely**.

When reloading **form views**, be aware that if a user is currently
editing a record, **their unsaved updates may be lost**.

**Table of contents**

.. contents::
:local:

Usage
=====

🧩 Example Usage
----------------

Below is a code snippet showing how to use the ``reload_views`` helper
function.

.. code:: python

# Reload the kanban and form views for all salespeople when an opportunity is won
# Will reload views only if the current opportunity is being displayed

group_id = self.env.ref("sales_team.group_sale_salesman").id
users_to_reload = self.env["res.users"].search([("groups_id", "in", [group_id])])
users_to_reload.reload_views(
model="crm.lead",
view_types=["kanban", "form"],
rec_ids=[self.id],
)

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_refresh_from_backend%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Cetmix

Contributors
------------

- Cetmix

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/web <https://github.com/OCA/web/tree/17.0/web_refresh_from_backend>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions web_refresh_from_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2025 Cetmix OÜ
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models
22 changes: 22 additions & 0 deletions web_refresh_from_backend/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2025 Cetmix OÜ
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Web Refresh From Backend",
"summary": "Refresh views from backend",
"version": "17.0.1.0.0",
"category": "Web",
"license": "LGPL-3",
"author": "Cetmix, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"depends": ["mail"],
"assets": {
"web.assets_backend": [
"web_refresh_from_backend/static/src/views/list/list_controller_patch.esm.js",
"web_refresh_from_backend/static/src/views/kanban/kanban_controller_patch.esm.js",
"web_refresh_from_backend/static/src/views/form/form_controller_patch.esm.js",
],
},
"installable": True,
"auto_install": False,
}
97 changes: 97 additions & 0 deletions web_refresh_from_backend/i18n/web_refresh_from_backend.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_refresh_from_backend
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/form/form_controller_patch.esm.js:0
#, python-format
msgid "All unsaved changes will be lost! Continue?"
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/form/form_controller_patch.esm.js:0
#: code:addons/web_refresh_from_backend/static/src/views/list/list_controller_patch.esm.js:0
#, python-format
msgid "Cancel"
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/form/form_controller_patch.esm.js:0
#, python-format
msgid "Continue"
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/form/form_controller_patch.esm.js:0
#, python-format
msgid "Could not reload form. "
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/kanban/kanban_controller_patch.esm.js:0
#, python-format
msgid "Could not reload kanban. "
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/list/list_controller_patch.esm.js:0
#, python-format
msgid "Could not reload list. "
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/list/list_controller_patch.esm.js:0
#, python-format
msgid "Could not save record. "
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/form/form_controller_patch.esm.js:0
#, python-format
msgid "Form is being refreshed from backend"
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/list/list_controller_patch.esm.js:0
#, python-format
msgid "List is being refreshed from backend"
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/list/list_controller_patch.esm.js:0
#, python-format
msgid "Save & Refresh"
msgstr ""

#. module: web_refresh_from_backend
#: model:ir.model,name:web_refresh_from_backend.model_res_users
msgid "User"
msgstr ""

#. module: web_refresh_from_backend
#. odoo-javascript
#: code:addons/web_refresh_from_backend/static/src/views/list/list_controller_patch.esm.js:0
#, python-format
msgid "You have unsaved edits. Save them before refreshing?"
msgstr ""
4 changes: 4 additions & 0 deletions web_refresh_from_backend/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2025 Cetmix OÜ
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import res_users
50 changes: 50 additions & 0 deletions web_refresh_from_backend/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright 2025 Cetmix OÜ
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import models


class ResUsers(models.Model):
_inherit = "res.users"

def reload_views(self, model, view_types=None, rec_ids=None):
"""
Trigger UI reload for selected users and record IDs.

This method allows to reload specific views from the backend.
Be aware that when reloading form views, if a user is currently
doing some updates, those updates may be lost.

:param model: str, Model name (e.g., 'res.partner')
:param view_types: list of str, optional, View types to reload
(e.g., ['form', 'kanban']). Leave blank to reload all views.
:param rec_ids: list of int, optional, View will be reloaded only if a record
with id from the list is present in the view.

Example usage:
# Reload the kanban and form views for all salespeople when an opportunity
# is won.
# Will reload views only if the current opportunity is being displayed
group_id = self.env.ref("sales_team.group_sale_salesman").id
users_to_reload = self.env["res.users"].search(
[("groups_id", "in", [group_id])]
)
users_to_reload.reload_views(
model="crm.lead",
view_types=["kanban", "form"],
rec_ids=[self.id]
)
"""

# Prepare the message payload
bus_message = {
"model": model,
"view_types": view_types or [],
"rec_ids": rec_ids or [],
}

# Send notification to each user's partner
notifications = [
[user.partner_id, "web.refresh_view", bus_message] for user in self
]
self.env["bus.bus"]._sendmany(notifications)
3 changes: 3 additions & 0 deletions web_refresh_from_backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions web_refresh_from_backend/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Cetmix

31 changes: 31 additions & 0 deletions web_refresh_from_backend/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

# Backend UI Reload Module

This is a **technical module** that allows triggering a **UI reload** from the backend.
It enables triggering the reload action for selected users and record IDs.

**NB:** this module refreshes views using direct actions instead of calling `action_reload`.
This is done to avoid possible glitches and is aligned with the same approach used in the [web_refreshed](https://github.com/OCA/web/tree/16.0/web_refresher) module.

---

## 🔧 Helper Function: `reload_views`

A special helper function `reload_views` is added to the `res.users` model.

### **Arguments**

| Argument | Type | Description |
|-----------|------|-------------|
| **model** | `Char` | Model name, e.g. `'res.partner'` |
| **view_types** | `List of Char` *(optional)* | View types to reload, e.g. `["form", "kanban"]`. Leave blank to reload all views. |
| **rec_ids** | `List of Integer` *(optional)* | The view will be reloaded only if a record with an ID from this list is present in the view. |

---

## ⚠️ Important Notes

Use this function **wisely**.

When reloading **form views**, be aware that if a user is currently editing a record,
**their unsaved updates may be lost**.
15 changes: 15 additions & 0 deletions web_refresh_from_backend/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## 🧩 Example Usage

Below is a code snippet showing how to use the `reload_views` helper function.

```python
# Reload the kanban and form views for all salespeople when an opportunity is won
# Will reload views only if the current opportunity is being displayed

group_id = self.env.ref("sales_team.group_sale_salesman").id
users_to_reload = self.env["res.users"].search([("groups_id", "in", [group_id])])
users_to_reload.reload_views(
model="crm.lead",
view_types=["kanban", "form"],
rec_ids=[self.id],
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading