Skip to content
Closed
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
1 change: 1 addition & 0 deletions sign_oca/__manifest__.py
Original file line number Diff line number Diff line change
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
10 changes: 10 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,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)
Comment on lines +344 to +345

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
partner_recs = record.signer_ids.mapped("partner_id")
self.notify_changes(partner_recs)
partner_recs = records.signer_ids.mapped("partner_id")
self.notify_changes(partner_recs)

Copy link
Contributor Author

@kobros-tech kobros-tech Mar 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ nilshamerlinck
thanks, but there will be no change in code functionality or syntax.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you create 2 sign.oca.request that involve same signers, isn't it better to send only one notification to each signer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating two requests does not make sense.
only one is needed to be fully signed but better if some partner is not there we send him an email again.

we made a PR on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it is possible to create multiple requests at the same time, for example, through maintenance_sign_oca (although it can be done without this module).

test

return records


Expand Down
54 changes: 54 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,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);
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