Skip to content

Commit

Permalink
[18.0][IMP] sign_oca: adding events for bus synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
kobros-tech committed Jan 13, 2025
1 parent d1f88d7 commit c4d315d
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 24 deletions.
2 changes: 1 addition & 1 deletion sign_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Contributors

- `Kencove <https://www.kencove.com>`__:

- Mohamed Alkobrosli
- Mohamed Alkobrosli <malkobrosly@kencove.com>

Maintainers
-----------
Expand Down
3 changes: 2 additions & 1 deletion sign_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "AGPL-3",
"author": "Dixmit,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sign",
"depends": ["web_editor", "portal", "base_sparse_field"],
"depends": ["web_editor", "portal", "base_sparse_field", "bus"],
"data": [
"security/security.xml",
"views/menu.xml",
Expand Down Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions sign_oca/models/sign_oca_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,24 @@ 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
partner_list_ids = partner_recs.mapped("id")
for partner_id in partner_list_ids:
self.env["bus.bus"]._sendone(
"broadcast",
f"sign_oca_request_updates_{partner_id}",
{"message": "Sign OCA Requests Model updated"},
)

@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


Expand Down
2 changes: 1 addition & 1 deletion sign_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
- Víctor Martínez

- [Kencove](https://www.kencove.com):
- Mohamed Alkobrosli
- Mohamed Alkobrosli \<<malkobrosly@kencove.com>\>
2 changes: 1 addition & 1 deletion sign_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ <h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
</ul>
</li>
<li><a class="reference external" href="https://www.kencove.com">Kencove</a>:<ul>
<li>Mohamed Alkobrosli</li>
<li>Mohamed Alkobrosli &lt;<a class="reference external" href="mailto:malkobrosly&#64;kencove.com">malkobrosly&#64;kencove.com</a>&gt;</li>
</ul>
</li>
</ul>
Expand Down
58 changes: 58 additions & 0 deletions sign_oca/static/src/js/sign_requests_service.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @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";
import {user} from "@web/core/user";

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_${user.partnerId}`,
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);
18 changes: 3 additions & 15 deletions sign_oca/static/src/js/systray_service.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
9 changes: 4 additions & 5 deletions sign_oca/static/src/xml/systray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
<t t-name="sign_oca.SignerMenu">
<Dropdown
position="'bottom-end'"
beforeOpen.bind="onBeforeOpen"
manual="false"
menuClass="discussSystray.menuClass"
>
<t t-set-slot="default">
<div class="o-mail-DiscussSystray-class cursor-pointer">
<i class="fa fa-pencil" role="img" aria-label="Sign Requests" />
<span
t-if="state.signerCounter > 0"
t-if="state.sign_requests.signerCounter > 0"
class="o-mail-ActivityMenu-counter badge rounded-pill"
t-out="state.signerCounter"
t-out="state.sign_requests.signerCounter"
/>
</div>
</t>
<t t-set-slot="content">
<div t-att-class="`${discussSystray.contentClass} o-mail-ActivityMenu`">
<div
t-if="state.signerCounter === 0"
t-if="state.sign_requests.signerCounter === 0"
class="o-mail-ActivityMenu-empty align-items-center text-muted p-2 opacity-50 d-flex justify-content-center"
>
<span>No requests to sign.</span>
Expand All @@ -30,7 +29,7 @@
name="activityGroups"
>
<t
t-foreach="state.signerGroups"
t-foreach="state.sign_requests.signerGroups"
t-as="group"
t-key="group_index"
name="activityGroupLoop"
Expand Down

0 comments on commit c4d315d

Please sign in to comment.