Moaz  Mabrok
Moaz Mabrok

Reputation: 740

odoo notification if the record data is out of date

when odoo 15 was released I have seen this record is not up to date (not sure of the actual words)

The issue is that I have a approval for a record but if the user that summered the record for approval is still on the page he don't see the updates to the record after the approval. I do send the notification but the user wants the page to refresh or show that the record view is not up to date like (what odoo was doing in the first week of the released)

sorry is there is no code but am not sure how go about doing this. Not expecting a solution just ideas on what you thing and maybe in you have time why your idea may fail (drawbacks).

        /**
         * Displays one notification on user's screen when assets have changed
         */
        function displayBundleChangedNotification() {
            if (!isNotificationDisplayed) {
                // Wrap the notification inside a delay.
                // The server may be overwhelmed with recomputing assets
                // We wait until things settle down
                browser.clearTimeout(bundleNotifTimerID);
                bundleNotifTimerID = browser.setTimeout(() => {
                    notification.add(
                        env._t("The page appears to be out of date."),
                        {
                            title: env._t("Refresh"),
                            type: "warning",
                            sticky: true,
                            buttons: [
                                {
                                    name: env._t("Refresh"),
                                    primary: true,
                                    onClick: () => {
                                        browser.location.reload();
                                    },
                                },
                            ],
                            onClose: () => {
                                isNotificationDisplayed = false;
                            },
                        }
                    );
                    isNotificationDisplayed = true;
                }, getBundleNotificationDelay());
            }
        }

addons/bus/static/src/js/services/assets_watchdog_service.js

this maybe semlar to what I need but assets

The main question here Is how to know if a user is on the modified record and run a function

Upvotes: 2

Views: 470

Answers (1)

Andrew Williams
Andrew Williams

Reputation: 11

  1. setup a web socket that listens for update events identified by ID’s and prompt notifications if the documentId of the notification matches the ID of document on page at that point in time.
  2. Poll every x seconds for the record corresponding to document on page and compare some unique value that would have changed like lastUpdated. If changed prompt notification and refresh.
  3. Keep a metadata list of open pages. Can use heartbeat interval and onLoad onUnload events to keep list valid. Whenever two or more documents are open at the same time make it known on page that “document is being edited and cannot be currently edited will update accordingly” or something like that.
  4. Use service workers and the push api to send updates to the main running app

Upvotes: 1

Related Questions