Skip to content
Merged
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
6 changes: 3 additions & 3 deletions survey_certification_sending/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Authors
Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__
- `Tecnativa <https://www.tecnativa.com>`__

- David Vidal
- Pilar Vargas
- David Vidal
- Pilar Vargas

Maintainers
-----------
Expand Down
1 change: 1 addition & 0 deletions survey_certification_sending/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"license": "AGPL-3",
"depends": ["survey"],
"data": [
"views/res_partner_views.xml",
"views/survey_survey_views.xml",
"views/survey_templates.xml",
"views/survey_user_views.xml",
Expand Down
1 change: 1 addition & 0 deletions survey_certification_sending/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import mail_template
from . import res_partner
from . import survey_survey
from . import survey_user_input
8 changes: 5 additions & 3 deletions survey_certification_sending/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def send_mail(
email_layout_xmlid=False,
):
if self.model == "survey.user_input":
skip_ids = self.env.context.get("skip_certification_email_ids", [])
survey = self.env["survey.user_input"].browse(res_id).survey_id
if survey.id in skip_ids:
survey_input = self.env["survey.user_input"].browse(res_id)
if (
survey_input.survey_id.skip_certification_email
or survey_input.partner_id.skip_certification_email
):
return False
return super().send_mail(
res_id, force_send, raise_exception, email_values, email_layout_xmlid
Expand Down
12 changes: 12 additions & 0 deletions survey_certification_sending/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2025 Tecnativa - Pilar Vargas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class Survey(models.Model):
_inherit = "res.partner"

skip_certification_email = fields.Boolean(
help="Skip sending the certification automatically after successful completion "
"of the survey."
)
11 changes: 2 additions & 9 deletions survey_certification_sending/models/survey_user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@ def _mark_done(self):
user_input.survey_id.certification
and user_input.scoring_success
and not user_input.survey_id.skip_certification_email
and not user_input.partner_id.skip_certification_email
and user_input.survey_id.certification_mail_template_id
and not user_input.test_entry
):
user_input.certification_sent = True
# Add ids of surveys that have to skip automatic sending to the context
return super(
SurveyUserInput,
self.with_context(
skip_certification_email_ids=self.mapped("survey_id")
.filtered(lambda s: s.skip_certification_email)
.ids
),
)._mark_done()
return super()._mark_done()

def action_manual_send_certification(self):
# Send certifications manually only to those who passed the survey.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,66 @@ def test_no_passed_certification_skip_auto_sending(self):
# Verify that the certification has not been sent manually
answer.action_manual_send_certification()
self.assertFalse(answer.certification_sent)

def test_certification_partner_skip_auto_sending(self):
test_certification = self.env["survey.survey"].create(
{
"title": "Test Partner Skip Auto Sending",
"access_mode": "public",
"users_login_required": True,
"questions_layout": "page_per_question",
"users_can_go_back": True,
"scoring_type": "scoring_with_answers",
"scoring_success_min": 85.0,
"certification": True,
"certification_mail_template_id": self.env.ref(
"survey.mail_template_certification"
).id,
"is_time_limited": True,
"time_limit": 10,
}
)
q_01 = self._add_question(
None,
"2+2",
"simple_choice",
sequence=1,
constr_mandatory=True,
constr_error_msg="Please select an answer",
survey_id=test_certification.id,
labels=[
{"value": "2"},
{"value": "3"},
{"value": "4", "is_correct": True, "answer_score": 50.0},
{"value": "5"},
],
)
q_02 = self._add_question(
None,
"2x2",
"simple_choice",
sequence=2,
constr_mandatory=True,
constr_error_msg="Please select an answer",
survey_id=test_certification.id,
labels=[
{"value": "2"},
{"value": "3"},
{"value": "4", "is_correct": True, "answer_score": 50.0},
{"value": "5"},
],
)
answer = self._add_answer(test_certification, self.env.user)
self._add_answer_line(q_01, answer, q_01.suggested_answer_ids[2].id)
self._add_answer_line(q_02, answer, q_02.suggested_answer_ids[2].id)
# Set on answer.partner_id to ensure it applies to the actual partner
# used in the test
answer.partner_id.write({"skip_certification_email": True})
answer.with_user(self.env.user).write({"state": "done"})
answer._mark_done()
# Verify that the certification has not been sent automatically
self.assertTrue(answer.scoring_success)
self.assertFalse(answer.certification_sent)
# Verify that the certification has been sent manually
answer.action_manual_send_certification()
self.assertTrue(answer.certification_sent)
16 changes: 16 additions & 0 deletions survey_certification_sending/views/res_partner_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.form.view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="website" position="before">
<field
name="skip_certification_email"
groups="survey.group_survey_user"
/>
</field>
</field>
</record>
</odoo>
2 changes: 1 addition & 1 deletion survey_certification_sending/views/survey_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>
<attribute
name="t-if"
>survey.certification and not survey.skip_certification_email</attribute>
>survey.certification and (not survey.skip_certification_email and not answer.partner_id.skip_certification_email)</attribute>
</xpath>
</template>
</odoo>