Skip to content

Commit 8c7d389

Browse files
committed
[16.0][IMP] sign_oca: connect sign requests with survey answers
1 parent 6a4a040 commit 8c7d389

File tree

9 files changed

+106
-22
lines changed

9 files changed

+106
-22
lines changed

sign_oca/README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ Sign from template
111111
- Some extra modules (e.g. maintenance_sign_oca) will automatically set
112112
the signers for each request.
113113

114+
Sign answered survey questions
115+
------------------------------
116+
117+
- Create a survey and ask the partner to answer it.
118+
- Create a sign template and select Survey model for model field.
119+
- Select the specific answered survey for survey field.
120+
- Open configuration form and create field elements and choose Survey
121+
ones.
122+
- Make placeholder for each survey field the same answered questions of
123+
the survey itself.
124+
- When the partners open the sign request they find default values are
125+
the answered survey questions.
126+
114127
Known issues / Roadmap
115128
======================
116129

sign_oca/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "AGPL-3",
1010
"author": "Dixmit,Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/sign",
12-
"depends": ["web_editor", "portal", "base_sparse_field"],
12+
"depends": ["web_editor", "portal", "base_sparse_field", "survey"],
1313
"data": [
1414
"security/security.xml",
1515
"views/menu.xml",

sign_oca/data/data.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<field name="name">Check</field>
2828
<field name="field_type">check</field>
2929
</record>
30+
<record id="sign_field_survey" model="sign.oca.field">
31+
<field name="name">Survey</field>
32+
<field name="field_type">text</field>
33+
<field name="default_value">survey</field>
34+
</record>
3035
<record id="sign_role_customer" model="sign.oca.role">
3136
<field name="name">Customer</field>
3237
<field name="domain">[]</field>

sign_oca/models/sign_oca_request.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,25 @@ def get_info(self, access_token=False):
443443
)
444444
}
445445
)
446+
# for survey related sign requests
447+
survey_id = self.request_id.template_id.survey_id
448+
model_id = self.request_id.template_id.model_id
449+
if survey_id and model_id and model_id.model == "survey.survey":
450+
survey_participation = self.env["survey.user_input"].search(
451+
[
452+
("survey_id", "=", survey_id.id),
453+
("partner_id", "=", self.partner_id.id),
454+
]
455+
)[:1]
456+
survey = {}
457+
for line in survey_participation.user_input_line_ids:
458+
if line.question_id.question_type == "matrix":
459+
survey.update(
460+
{line.matrix_row_id.value: line.suggested_answer_id.value}
461+
)
462+
else:
463+
survey.update({line.question_id.display_name: line.display_name})
464+
partner_fields_dict.update({"survey": survey})
446465
return {
447466
"role_id": self.role_id.id if not self.signed_on else False,
448467
"name": self.request_id.template_id.name,

sign_oca/models/sign_oca_template.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class SignOcaTemplate(models.Model):
2222
domain=[("transient", "=", False), ("model", "not like", "sign.oca")],
2323
)
2424
model = fields.Char(compute="_compute_model", compute_sudo=True, store=True)
25+
survey_id = fields.Many2one(
26+
"survey.survey",
27+
)
2528
active = fields.Boolean(default=True)
2629
request_ids = fields.One2many("sign.oca.request", inverse_name="template_id")
2730

sign_oca/readme/USAGE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@
5555
no signer will be set.
5656
- Some extra modules (e.g. maintenance_sign_oca) will automatically set
5757
the signers for each request.
58+
59+
## Sign answered survey questions
60+
61+
- Create a survey and ask the partner to answer it.
62+
- Create a sign template and select Survey model for model field.
63+
- Select the specific answered survey for survey field.
64+
- Open configuration form and create field elements and choose Survey ones.
65+
- Make placeholder for each survey field the same answered questions of the survey itself.
66+
- When the partners open the sign request they find default values are the answered survey questions.

sign_oca/static/description/index.html

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,18 @@ <h1 class="title">Sign Oca</h1>
382382
<li><a class="reference internal" href="#sign-a-document-from-template" id="toc-entry-5">Sign a document from template</a></li>
383383
<li><a class="reference internal" href="#sign-a-pending-document" id="toc-entry-6">Sign a pending document</a></li>
384384
<li><a class="reference internal" href="#sign-from-template" id="toc-entry-7">Sign from template</a></li>
385+
<li><a class="reference internal" href="#sign-answered-survey-questions" id="toc-entry-8">Sign answered survey questions</a></li>
385386
</ul>
386387
</li>
387-
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-8">Known issues / Roadmap</a><ul>
388-
<li><a class="reference internal" href="#tasks" id="toc-entry-9">Tasks</a></li>
388+
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-9">Known issues / Roadmap</a><ul>
389+
<li><a class="reference internal" href="#tasks" id="toc-entry-10">Tasks</a></li>
389390
</ul>
390391
</li>
391-
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-10">Bug Tracker</a></li>
392-
<li><a class="reference internal" href="#credits" id="toc-entry-11">Credits</a><ul>
393-
<li><a class="reference internal" href="#authors" id="toc-entry-12">Authors</a></li>
394-
<li><a class="reference internal" href="#contributors" id="toc-entry-13">Contributors</a></li>
395-
<li><a class="reference internal" href="#maintainers" id="toc-entry-14">Maintainers</a></li>
392+
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-11">Bug Tracker</a></li>
393+
<li><a class="reference internal" href="#credits" id="toc-entry-12">Credits</a><ul>
394+
<li><a class="reference internal" href="#authors" id="toc-entry-13">Authors</a></li>
395+
<li><a class="reference internal" href="#contributors" id="toc-entry-14">Contributors</a></li>
396+
<li><a class="reference internal" href="#maintainers" id="toc-entry-15">Maintainers</a></li>
396397
</ul>
397398
</li>
398399
</ul>
@@ -475,11 +476,25 @@ <h2><a class="toc-backref" href="#toc-entry-7">Sign from template</a></h2>
475476
the signers for each request.</li>
476477
</ul>
477478
</div>
479+
<div class="section" id="sign-answered-survey-questions">
480+
<h2><a class="toc-backref" href="#toc-entry-8">Sign answered survey questions</a></h2>
481+
<ul class="simple">
482+
<li>Create a survey and ask the partner to answer it.</li>
483+
<li>Create a sign template and select Survey model for model field.</li>
484+
<li>Select the specific answered survey for survey field.</li>
485+
<li>Open configuration form and create field elements and choose Survey
486+
ones.</li>
487+
<li>Make placeholder for each survey field the same answered questions of
488+
the survey itself.</li>
489+
<li>When the partners open the sign request they find default values are
490+
the answered survey questions.</li>
491+
</ul>
492+
</div>
478493
</div>
479494
<div class="section" id="known-issues-roadmap">
480-
<h1><a class="toc-backref" href="#toc-entry-8">Known issues / Roadmap</a></h1>
495+
<h1><a class="toc-backref" href="#toc-entry-9">Known issues / Roadmap</a></h1>
481496
<div class="section" id="tasks">
482-
<h2><a class="toc-backref" href="#toc-entry-9">Tasks</a></h2>
497+
<h2><a class="toc-backref" href="#toc-entry-10">Tasks</a></h2>
483498
<ul class="simple">
484499
<li>Ensure that the signature is inalterable. Maybe we might need to use
485500
some tools like endevise or pyHanko with a certificate. Signer can be
@@ -488,23 +503,23 @@ <h2><a class="toc-backref" href="#toc-entry-9">Tasks</a></h2>
488503
</div>
489504
</div>
490505
<div class="section" id="bug-tracker">
491-
<h1><a class="toc-backref" href="#toc-entry-10">Bug Tracker</a></h1>
506+
<h1><a class="toc-backref" href="#toc-entry-11">Bug Tracker</a></h1>
492507
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sign/issues">GitHub Issues</a>.
493508
In case of trouble, please check there if your issue has already been reported.
494509
If you spotted it first, help us to smash it by providing a detailed and welcomed
495510
<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>
496511
<p>Do not contact contributors directly about support or help with technical issues.</p>
497512
</div>
498513
<div class="section" id="credits">
499-
<h1><a class="toc-backref" href="#toc-entry-11">Credits</a></h1>
514+
<h1><a class="toc-backref" href="#toc-entry-12">Credits</a></h1>
500515
<div class="section" id="authors">
501-
<h2><a class="toc-backref" href="#toc-entry-12">Authors</a></h2>
516+
<h2><a class="toc-backref" href="#toc-entry-13">Authors</a></h2>
502517
<ul class="simple">
503518
<li>Dixmit</li>
504519
</ul>
505520
</div>
506521
<div class="section" id="contributors">
507-
<h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
522+
<h2><a class="toc-backref" href="#toc-entry-14">Contributors</a></h2>
508523
<ul class="simple">
509524
<li>Enric Tobella (<a class="reference external" href="http://www.dixmit.com">www.dixmit.com</a>)</li>
510525
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
@@ -514,7 +529,7 @@ <h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
514529
</ul>
515530
</div>
516531
<div class="section" id="maintainers">
517-
<h2><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h2>
532+
<h2><a class="toc-backref" href="#toc-entry-15">Maintainers</a></h2>
518533
<p>This module is maintained by the OCA.</p>
519534
<a class="reference external image-reference" href="https://odoo-community.org">
520535
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />

sign_oca/static/src/elements/text.esm.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,28 @@ const textSignOca = {
2323
!item.value &&
2424
parent.info.partner[item.default_value]
2525
) {
26-
this.change(
27-
parent.info.partner[item.default_value],
28-
parent,
29-
item,
30-
signatureItem
31-
);
32-
ev.target.value = parent.info.partner[item.default_value];
26+
// Add survey values if present
27+
if (
28+
parent.info.partner.survey &&
29+
item.default_value === "survey" &&
30+
parent.info.partner.survey[item.placeholder]
31+
) {
32+
this.change(
33+
parent.info.partner.survey[item.placeholder],
34+
parent,
35+
item,
36+
signatureItem
37+
);
38+
ev.target.value = parent.info.partner.survey[item.placeholder];
39+
} else {
40+
this.change(
41+
parent.info.partner[item.default_value],
42+
parent,
43+
item,
44+
signatureItem
45+
);
46+
ev.target.value = parent.info.partner[item.default_value];
47+
}
3348
}
3449
});
3550
input.addEventListener("change", (ev) => {

sign_oca/views/sign_oca_template.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
<field name="data" filename="filename" />
4444
<field name="filename" invisible="1" />
4545
<field name="model_id" groups="sign_oca.sign_oca_group_admin" />
46+
<field name="model" invisible="1" />
47+
<field
48+
name="survey_id"
49+
attrs="{'invisible': [('model', '!=', 'survey.survey')]}"
50+
/>
4651
<field name="ask_location" />
4752
</group>
4853
<notebook>

0 commit comments

Comments
 (0)