diff --git a/sign_oca/__manifest__.py b/sign_oca/__manifest__.py
index 21eb9a11..ae8d6470 100644
--- a/sign_oca/__manifest__.py
+++ b/sign_oca/__manifest__.py
@@ -48,6 +48,7 @@
"sign_oca/static/src/elements/signature.esm.js",
"sign_oca/static/src/elements/check.esm.js",
"sign_oca/static/src/components/sign_oca_pdf/sign_oca_pdf.esm.js",
+ "sign_oca/static/src/js/sign_requests_service.esm.js",
"sign_oca/static/src/js/sign_oca.esm.js",
"sign_oca/static/src/js/systray_service.esm.js",
"sign_oca/static/src/xml/*.xml",
diff --git a/sign_oca/models/sign_oca_request.py b/sign_oca/models/sign_oca_request.py
index 079628d8..14cfd31d 100644
--- a/sign_oca/models/sign_oca_request.py
+++ b/sign_oca/models/sign_oca_request.py
@@ -328,11 +328,21 @@ def _set_action_log(self, action, **kwargs):
.create(self._set_action_log_vals(action, **kwargs))
)
+ @api.model
+ def notify_changes(self, partner_recs):
+ # send notification to the list of subscribers
+ channel = "sign_oca_request_updates"
+ message = {"message": "Sign OCA Requests Model updated"}
+ for partner_id in partner_recs:
+ partner_id._bus_send(channel, message)
+
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
for record in records:
record._set_action_log("create")
+ partner_recs = record.signer_ids.mapped("partner_id")
+ self.notify_changes(partner_recs)
return records
diff --git a/sign_oca/static/src/js/sign_requests_service.esm.js b/sign_oca/static/src/js/sign_requests_service.esm.js
new file mode 100644
index 00000000..1cdeba5a
--- /dev/null
+++ b/sign_oca/static/src/js/sign_requests_service.esm.js
@@ -0,0 +1,54 @@
+/** @odoo-module **/
+/* global */
+/* Copyright 2025 Kencove - Mohamed Alkobrosli
+ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
+
+import {Reactive} from "@web/core/utils/reactive";
+import {reactive} from "@odoo/owl";
+import {registry} from "@web/core/registry";
+
+export class WatchSignRequestsService extends Reactive {
+ static modelToLoad = [];
+ static serviceDependencies = ["bus_service", "orm", "notification"];
+
+ constructor() {
+ super();
+ this.ready = this.setup(...arguments).then(() => this);
+ }
+
+ async setup(env, {bus_service, orm, notification}) {
+ this.env = env;
+ this.bus_service = bus_service;
+ this.orm = orm;
+ this.notification = notification;
+ this.sign_requests = reactive({signerCounter: 0, signerGroups: []});
+
+ this.bus_service.subscribe("sign_oca_request_updates", async ({message}) => {
+ if (message) {
+ await this.fetchSystraySigner();
+ }
+ });
+ }
+ async fetchSystraySigner() {
+ const groups = await this.orm.call("res.users", "sign_oca_request_user_count");
+ let total = 0;
+ for (const group of groups) {
+ total += group.total_records || 0;
+ }
+ this.sign_requests.signerGroups = groups;
+ this.sign_requests.signerCounter = total;
+ return {groups, total};
+ }
+ getTotalSignRequests() {
+ return this.sign_requests.signerCounter;
+ }
+}
+
+export const watchSignRequestsService = {
+ dependencies: WatchSignRequestsService.serviceDependencies,
+ async start(env, services) {
+ return new WatchSignRequestsService(env, services).ready;
+ },
+};
+
+registry.category("services").add("watchSignRequests", watchSignRequestsService);
diff --git a/sign_oca/static/src/js/systray_service.esm.js b/sign_oca/static/src/js/systray_service.esm.js
index d7e6fa33..9b5ab721 100644
--- a/sign_oca/static/src/js/systray_service.esm.js
+++ b/sign_oca/static/src/js/systray_service.esm.js
@@ -15,26 +15,14 @@ export class SignerMenuView extends Component {
this.discussSystray = useDiscussSystray();
this.orm = useService("orm");
this.action = useService("action");
+ this.watchSignRequests = useService("watchSignRequests");
this.state = useState({
- signerGroups: [],
- signerCounter: 0,
+ sign_requests: this.watchSignRequests.sign_requests,
});
onMounted(async () => {
- await this.fetchSystraySigner();
+ await this.watchSignRequests.fetchSystraySigner();
});
}
- async fetchSystraySigner() {
- const groups = await this.orm.call("res.users", "sign_oca_request_user_count");
- let total = 0;
- for (const group of groups) {
- total += group.total_records || 0;
- }
- this.state.signerCounter = total;
- this.state.signerGroups = groups;
- }
- async onBeforeOpen() {
- await this.fetchSystraySigner();
- }
availableViews() {
return [
[false, "kanban"],
diff --git a/sign_oca/static/src/xml/systray.xml b/sign_oca/static/src/xml/systray.xml
index 797db60d..0f5c2c97 100644
--- a/sign_oca/static/src/xml/systray.xml
+++ b/sign_oca/static/src/xml/systray.xml
@@ -3,7 +3,6 @@
@@ -11,16 +10,16 @@