Skip to content

Commit 7d07454

Browse files
committed
[IMP] sign_oca: use mail.template instead of static mails.
There is a need to make a well designed email template, in order to encourage partners to sign if the see a professional email.
1 parent 28f6ab5 commit 7d07454

File tree

6 files changed

+130
-97
lines changed

6 files changed

+130
-97
lines changed

sign_oca/README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
========
62
Sign Oca
73
========
@@ -17,7 +13,7 @@ Sign Oca
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsign-lightgray.png?logo=github

sign_oca/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"views/sign_oca_role.xml",
2929
"views/sign_oca_template.xml",
3030
"templates/assets.xml",
31+
"templates/mail_template.xml",
3132
"reports/signature_certificate.xml",
3233
"reports/signature_certificate_report.xml",
3334
],

sign_oca/models/sign_oca_request.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,10 @@ def action_send(self, sign_now=False, message=""):
258258
signer._portal_ensure_token()
259259
if sign_now and signer.partner_id == self.env.user.partner_id:
260260
continue
261-
render_result = self.env["ir.qweb"]._render(
262-
"sign_oca.sign_oca_template_mail",
263-
{"record": signer, "body": message, "link": signer.access_url},
264-
engine="ir.qweb",
265-
minimal_qcontext=True,
266-
)
267-
self.env["mail.thread"].message_notify(
268-
body=render_result,
269-
partner_ids=signer.partner_id.ids,
270-
subject=_("New document to sign"),
271-
subtype_id=self.env.ref("mail.mt_comment").id,
272-
mail_auto_delete=False,
273-
email_layout_xmlid="mail.mail_notification_light",
261+
template = self.env.ref("sign_oca.email_template_sign_document")
262+
template.with_context(body=message, link=signer.access_url).send_mail(
263+
signer.id,
264+
force_send=True,
274265
)
275266

276267
def action_send_signed_request(self):
@@ -292,19 +283,14 @@ def action_send_signed_request(self):
292283
]
293284
)
294285
)
295-
# The message will not be linked to the record because we do not want
296-
# it happen.
297-
self.env["mail.thread"].message_notify(
298-
body=_(
299-
"%(name)s (%(email)s) has sent the signed document.",
300-
name=self.create_uid.name,
301-
email=self.create_uid.email,
302-
),
303-
partner_ids=signer.partner_id.ids,
304-
subject=_("Signed document"),
305-
subtype_id=self.env.ref("mail.mt_comment").id,
306-
mail_auto_delete=False,
307-
attachment_ids=attachments.ids,
286+
template = self.env.ref("sign_oca.email_template_signed_document")
287+
email_values = {
288+
"attachment_ids": [(6, 0, attachments.ids)],
289+
}
290+
template.send_mail(
291+
signer.id,
292+
force_send=True,
293+
email_values=email_values,
308294
)
309295

310296
def _check_signed(self):

sign_oca/static/description/index.html

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>Sign Oca</title>
77
<style type="text/css">
88

99
/*
@@ -360,21 +360,16 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="sign-oca">
364+
<h1 class="title">Sign Oca</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="sign-oca">
370-
<h1>Sign Oca</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:4074fa3685a918a90dd5b7bbdde33764b9db4a112ca219352c6265a81b7876cf
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sign/tree/16.0/sign_oca"><img alt="OCA/sign" src="https://img.shields.io/badge/github-OCA%2Fsign-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sign-16-0/sign-16-0-sign_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sign&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sign/tree/16.0/sign_oca"><img alt="OCA/sign" src="https://img.shields.io/badge/github-OCA%2Fsign-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sign-16-0/sign-16-0-sign_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sign&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378373
<p>This module allows to create documents for signature inside Odoo using
379374
OWL.</p>
380375
<p><strong>Table of contents</strong></p>
@@ -404,17 +399,17 @@ <h1>Sign Oca</h1>
404399
</ul>
405400
</div>
406401
<div class="section" id="configuration">
407-
<h2><a class="toc-backref" href="#toc-entry-1">Configuration</a></h2>
402+
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
408403
<p>There is a wizard (sign.oca.template.generate.multi) that can be used
409404
for any model needed. If there is a template without a linked model or
410405
linked to a model (res.partner for example) an action will be
411406
automatically displayed in the tree and form view (only for users with
412407
Sign permissions).</p>
413408
</div>
414409
<div class="section" id="usage">
415-
<h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
410+
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
416411
<div class="section" id="creation-of-templates">
417-
<h3><a class="toc-backref" href="#toc-entry-3">Creation of templates</a></h3>
412+
<h2><a class="toc-backref" href="#toc-entry-3">Creation of templates</a></h2>
418413
<ul class="simple">
419414
<li>Access Sign / Templates</li>
420415
<li>Create a new template</li>
@@ -426,7 +421,7 @@ <h3><a class="toc-backref" href="#toc-entry-3">Creation of templates</a></h3>
426421
</ul>
427422
</div>
428423
<div class="section" id="sign-role">
429-
<h3><a class="toc-backref" href="#toc-entry-4">Sign role</a></h3>
424+
<h2><a class="toc-backref" href="#toc-entry-4">Sign role</a></h2>
430425
<ul class="simple">
431426
<li>Access Sign / Settings / Roles</li>
432427
<li>Create a new role (Equipment employee for example)</li>
@@ -437,7 +432,7 @@ <h3><a class="toc-backref" href="#toc-entry-4">Sign role</a></h3>
437432
</ul>
438433
</div>
439434
<div class="section" id="sign-a-document-from-template">
440-
<h3><a class="toc-backref" href="#toc-entry-5">Sign a document from template</a></h3>
435+
<h2><a class="toc-backref" href="#toc-entry-5">Sign a document from template</a></h2>
441436
<ul class="simple">
442437
<li>Access Sign / Templates</li>
443438
<li>Press the Sign button from a template</li>
@@ -452,7 +447,7 @@ <h3><a class="toc-backref" href="#toc-entry-5">Sign a document from template</a>
452447
</ul>
453448
</div>
454449
<div class="section" id="sign-a-pending-document">
455-
<h3><a class="toc-backref" href="#toc-entry-6">Sign a pending document</a></h3>
450+
<h2><a class="toc-backref" href="#toc-entry-6">Sign a pending document</a></h2>
456451
<ul class="simple">
457452
<li>Go to the pencil icon in the upper right corner (systray) of the sign
458453
request to access the pending signatures.</li>
@@ -465,7 +460,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Sign a pending document</a></h3>
465460
</ul>
466461
</div>
467462
<div class="section" id="sign-from-template">
468-
<h3><a class="toc-backref" href="#toc-entry-7">Sign from template</a></h3>
463+
<h2><a class="toc-backref" href="#toc-entry-7">Sign from template</a></h2>
469464
<ul class="simple">
470465
<li>Go to any list view or form view (except sign.oca models), e.g.:
471466
Contacts</li>
@@ -482,17 +477,17 @@ <h3><a class="toc-backref" href="#toc-entry-7">Sign from template</a></h3>
482477
</ul>
483478
</div>
484479
<div class="section" id="sign-from-portal">
485-
<h3><a class="toc-backref" href="#toc-entry-8">Sign from portal</a></h3>
480+
<h2><a class="toc-backref" href="#toc-entry-8">Sign from portal</a></h2>
486481
<ul class="simple">
487482
<li>customers who are using portal can sign their documents from portal
488483
directly in addition to being able to sign them from emails.</li>
489484
</ul>
490485
</div>
491486
</div>
492487
<div class="section" id="known-issues-roadmap">
493-
<h2><a class="toc-backref" href="#toc-entry-9">Known issues / Roadmap</a></h2>
488+
<h1><a class="toc-backref" href="#toc-entry-9">Known issues / Roadmap</a></h1>
494489
<div class="section" id="tasks">
495-
<h3><a class="toc-backref" href="#toc-entry-10">Tasks</a></h3>
490+
<h2><a class="toc-backref" href="#toc-entry-10">Tasks</a></h2>
496491
<ul class="simple">
497492
<li>Ensure that the signature is inalterable. Maybe we might need to use
498493
some tools like endevise or pyHanko with a certificate. Signer can be
@@ -501,23 +496,23 @@ <h3><a class="toc-backref" href="#toc-entry-10">Tasks</a></h3>
501496
</div>
502497
</div>
503498
<div class="section" id="bug-tracker">
504-
<h2><a class="toc-backref" href="#toc-entry-11">Bug Tracker</a></h2>
499+
<h1><a class="toc-backref" href="#toc-entry-11">Bug Tracker</a></h1>
505500
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sign/issues">GitHub Issues</a>.
506501
In case of trouble, please check there if your issue has already been reported.
507502
If you spotted it first, help us to smash it by providing a detailed and welcomed
508503
<a class="reference external" href="https://github.com/OCA/sign/issues/new?body=module:%20sign_oca%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
509504
<p>Do not contact contributors directly about support or help with technical issues.</p>
510505
</div>
511506
<div class="section" id="credits">
512-
<h2><a class="toc-backref" href="#toc-entry-12">Credits</a></h2>
507+
<h1><a class="toc-backref" href="#toc-entry-12">Credits</a></h1>
513508
<div class="section" id="authors">
514-
<h3><a class="toc-backref" href="#toc-entry-13">Authors</a></h3>
509+
<h2><a class="toc-backref" href="#toc-entry-13">Authors</a></h2>
515510
<ul class="simple">
516511
<li>Dixmit</li>
517512
</ul>
518513
</div>
519514
<div class="section" id="contributors">
520-
<h3><a class="toc-backref" href="#toc-entry-14">Contributors</a></h3>
515+
<h2><a class="toc-backref" href="#toc-entry-14">Contributors</a></h2>
521516
<ul class="simple">
522517
<li>Enric Tobella (<a class="reference external" href="http://www.dixmit.com">www.dixmit.com</a>)</li>
523518
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
@@ -531,7 +526,7 @@ <h3><a class="toc-backref" href="#toc-entry-14">Contributors</a></h3>
531526
</ul>
532527
</div>
533528
<div class="section" id="maintainers">
534-
<h3><a class="toc-backref" href="#toc-entry-15">Maintainers</a></h3>
529+
<h2><a class="toc-backref" href="#toc-entry-15">Maintainers</a></h2>
535530
<p>This module is maintained by the OCA.</p>
536531
<a class="reference external image-reference" href="https://odoo-community.org">
537532
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -546,6 +541,5 @@ <h3><a class="toc-backref" href="#toc-entry-15">Maintainers</a></h3>
546541
</div>
547542
</div>
548543
</div>
549-
</div>
550544
</body>
551545
</html>

sign_oca/templates/assets.xml

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,45 +60,4 @@
6060
</div>
6161
</t>
6262
</template>
63-
<template t-name="sign_oca_template_mail">
64-
<div>
65-
<span>
66-
<t t-out="record.create_uid.name" />
67-
(<a
68-
t-att-href="'mailto:%s?subject=%s' % (record.create_uid.email, 'Re: %s' % subject)"
69-
style="color:#428BCA; text-decoration:none;"
70-
target="_blank"
71-
><t t-out="record.create_uid.email" /></a>)
72-
has requested your signature on a document.
73-
</span>
74-
<span t-if="body">
75-
<div
76-
style="margin: 16px 0px 16px 0px; padding: 8px 16px 8px 16px; background-color: #F1F1F1;"
77-
>
78-
<span>
79-
<t t-out="body" />
80-
</span>
81-
</div>
82-
</span>
83-
<span>
84-
<div style="margin:16px auto; text-align:center;">
85-
<a
86-
t-att-href="link"
87-
style="padding: 8px 16px 8px 16px; border-radius: 3px; background-color:#875A7B; text-align:center; text-decoration:none; color: #FFFFFF;"
88-
>
89-
Sign document
90-
</a>
91-
</div>
92-
</span>
93-
<span>
94-
<div style="opacity: 0.7;">
95-
<strong
96-
>Warning</strong> do not forward this email to other people!<br />
97-
They will be able to access this document and sign it as yourself.<br
98-
/>
99-
</div>
100-
</span>
101-
</div>
102-
</template>
103-
10463
</odoo>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" ?>
2+
<odoo noupdate="1">
3+
<!-- A mail template for signing a document -->
4+
<record id="email_template_sign_document" model="mail.template">
5+
<field name="name">New document to sign</field>
6+
<field name="model_id" ref="sign_oca.model_sign_oca_request_signer" />
7+
<field name="email_from">{{ object.request_id.create_uid.email or '' }}</field>
8+
<field name="partner_to">{{ object.partner_id.id }}</field>
9+
<field name="subject">New document to sign</field>
10+
<field name="description">A notification to sign a document</field>
11+
<field name="body_html" type="html">
12+
<t t-set="sender" t-value="object.request_id.create_uid" />
13+
<t t-if="sender.name in ['OdooBot', 'Public User']">
14+
<t t-set="sender" t-value="False" />
15+
</t>
16+
<t t-set="link" t-value="object.env.context.get('link')" />
17+
<t t-set="body" t-value="object.env.context.get('body')" />
18+
<div>
19+
<span>
20+
<t t-if="sender">
21+
<t t-out="sender.name" />
22+
(<a
23+
t-att-href="'mailto:%s?subject=%s' % (sender.email, 'Re: %s' % subject)"
24+
style="color:#428BCA; text-decoration:none;"
25+
target="_blank"
26+
><t t-out="sender.email" /></a>)
27+
has requested your signature on a document.
28+
</t>
29+
<t t-else="">
30+
A document has been requested for your signature.
31+
</t>
32+
</span>
33+
<span t-if="body">
34+
<div
35+
style="margin: 16px 0px 16px 0px; padding: 8px 16px 8px 16px; background-color: #F1F1F1;"
36+
>
37+
<span>
38+
<t t-out="body" />
39+
</span>
40+
</div>
41+
</span>
42+
<span t-if="link">
43+
<div style="margin:16px auto; text-align:center;">
44+
<a
45+
t-att-href="link"
46+
style="padding: 8px 16px 8px 16px; border-radius: 3px; background-color:#875A7B; text-align:center; text-decoration:none; color: #FFFFFF;"
47+
>
48+
Sign document
49+
</a>
50+
</div>
51+
</span>
52+
<span>
53+
<div style="opacity: 0.7;">
54+
<strong>Warning</strong> do not forward this email to other people!<br />
55+
They will be able to access this document and sign it as yourself.<br />
56+
</div>
57+
</span>
58+
</div>
59+
</field>
60+
<field name="lang">{{ object.request_id.user_id.partner_id.lang }}</field>
61+
<field name="auto_delete" eval="False" />
62+
</record>
63+
64+
<!-- A mail template for signed document -->
65+
<record id="email_template_signed_document" model="mail.template">
66+
<field name="name">New Document has been signed</field>
67+
<field name="model_id" ref="sign_oca.model_sign_oca_request_signer" />
68+
<field name="email_from">{{ object.request_id.create_uid.email or '' }}</field>
69+
<field name="partner_to">{{ object.partner_id.id }}</field>
70+
<field name="subject">New Document has been signed</field>
71+
<field name="description">Notification for signed document</field>
72+
<field name="body_html" type="html">
73+
<t t-set="sender" t-value="object.request_id.create_uid" />
74+
<t t-if="sender.name in ['OdooBot', 'Public User']">
75+
<t t-set="sender" t-value="False" />
76+
</t>
77+
<div>
78+
<span>
79+
<t t-if="sender">
80+
<t t-out="sender.name" />
81+
(<a
82+
t-att-href="'mailto:%s?subject=%s' % (sender.email, 'Re: %s' % subject)"
83+
style="color:#428BCA; text-decoration:none;"
84+
target="_blank"
85+
><t t-out="sender.email" /></a>)
86+
has sent the signed document.
87+
</t>
88+
<t t-else="">
89+
A fully signed document has been sent to you.
90+
</t>
91+
</span>
92+
</div>
93+
</field>
94+
<field name="lang">{{ object.request_id.user_id.partner_id.lang }}</field>
95+
<field name="auto_delete" eval="False" />
96+
</record>
97+
</odoo>

0 commit comments

Comments
 (0)