From 69f9f824f39d86c1d579904508f068c2ab79cad4 Mon Sep 17 00:00:00 2001 From: pilarvargas-tecnativa Date: Tue, 11 Feb 2025 23:38:57 +0100 Subject: [PATCH] [ADD] survey_certification_sending: New module TT54988 --- .../odoo/addons/survey_certification_sending | 1 + setup/survey_certification_sending/setup.py | 6 + survey_certification_sending/README.rst | 104 ++++ survey_certification_sending/__init__.py | 1 + survey_certification_sending/__manifest__.py | 19 + survey_certification_sending/i18n/es.po | 74 +++ .../i18n/survey_certification_sending.pot | 70 +++ .../models/__init__.py | 3 + .../models/mail_template.py | 21 + .../models/survey_survey.py | 12 + .../models/survey_user_input.py | 56 +++ .../readme/CONTRIBUTORS.rst | 4 + .../readme/DESCRIPTION.rst | 2 + survey_certification_sending/readme/USAGE.rst | 12 + .../static/description/index.html | 447 ++++++++++++++++++ .../tests/__init__.py | 1 + .../test_survey_certification_sending.py | 185 ++++++++ .../views/survey_survey_views.xml | 15 + .../views/survey_user_views.xml | 40 ++ 19 files changed, 1073 insertions(+) create mode 120000 setup/survey_certification_sending/odoo/addons/survey_certification_sending create mode 100644 setup/survey_certification_sending/setup.py create mode 100644 survey_certification_sending/README.rst create mode 100644 survey_certification_sending/__init__.py create mode 100644 survey_certification_sending/__manifest__.py create mode 100644 survey_certification_sending/i18n/es.po create mode 100644 survey_certification_sending/i18n/survey_certification_sending.pot create mode 100644 survey_certification_sending/models/__init__.py create mode 100644 survey_certification_sending/models/mail_template.py create mode 100644 survey_certification_sending/models/survey_survey.py create mode 100644 survey_certification_sending/models/survey_user_input.py create mode 100644 survey_certification_sending/readme/CONTRIBUTORS.rst create mode 100644 survey_certification_sending/readme/DESCRIPTION.rst create mode 100644 survey_certification_sending/readme/USAGE.rst create mode 100644 survey_certification_sending/static/description/index.html create mode 100644 survey_certification_sending/tests/__init__.py create mode 100644 survey_certification_sending/tests/test_survey_certification_sending.py create mode 100644 survey_certification_sending/views/survey_survey_views.xml create mode 100644 survey_certification_sending/views/survey_user_views.xml diff --git a/setup/survey_certification_sending/odoo/addons/survey_certification_sending b/setup/survey_certification_sending/odoo/addons/survey_certification_sending new file mode 120000 index 00000000..278e6643 --- /dev/null +++ b/setup/survey_certification_sending/odoo/addons/survey_certification_sending @@ -0,0 +1 @@ +../../../../survey_certification_sending \ No newline at end of file diff --git a/setup/survey_certification_sending/setup.py b/setup/survey_certification_sending/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/survey_certification_sending/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/survey_certification_sending/README.rst b/survey_certification_sending/README.rst new file mode 100644 index 00000000..de139ed7 --- /dev/null +++ b/survey_certification_sending/README.rst @@ -0,0 +1,104 @@ +============================ +Survey Certification Sending +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f803666c59351fa990677b0084dd6507d3b6297d5939d2beb5e834a095447262 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsurvey-lightgray.png?logo=github + :target: https://github.com/OCA/survey/tree/15.0/survey_certification_sending + :alt: OCA/survey +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/survey-15-0/survey-15-0-survey_certification_sending + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/survey&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the Odoo Survey application to allow automatic and manual sending +of certifications when a participant successfully completes a survey. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Go to Survey > Surveys. +#. Create or edit a certification survey. +#. Configure whether you want to send certifications manually by checking the + "Skip Auto Email" option. +#. Participants who pass the survey will receive their certification automatically if + manual submission is not enabled. +#. If the automatic sending is disabled, passed certifications can be submitted manually + from the "Send certification email" action. +#. Certifications that have already been sent will be marked as "Certification sent". +#. Passed certifications can be sent as many times as necessary. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_ + + * David Vidal + * Pilar Vargas + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-pilarvargas-tecnativa| image:: https://github.com/pilarvargas-tecnativa.png?size=40px + :target: https://github.com/pilarvargas-tecnativa + :alt: pilarvargas-tecnativa + +Current `maintainer `__: + +|maintainer-pilarvargas-tecnativa| + +This module is part of the `OCA/survey `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/survey_certification_sending/__init__.py b/survey_certification_sending/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/survey_certification_sending/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/survey_certification_sending/__manifest__.py b/survey_certification_sending/__manifest__.py new file mode 100644 index 00000000..69875bd8 --- /dev/null +++ b/survey_certification_sending/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Survey Certification Sending", + "summary": "Controls the automatic sending of certifications in surveys.", + "version": "15.0.1.0.0", + "author": "Tecnativa, Odoo Community Association (OCA)", + "development_status": "Beta", + "category": "Marketing/Survey", + "website": "https://github.com/OCA/survey", + "maintainers": ["pilarvargas-tecnativa"], + "license": "AGPL-3", + "depends": ["survey"], + "data": [ + "views/survey_survey_views.xml", + "views/survey_user_views.xml", + ], + "installable": True, +} diff --git a/survey_certification_sending/i18n/es.po b/survey_certification_sending/i18n/es.po new file mode 100644 index 00000000..ca1c2604 --- /dev/null +++ b/survey_certification_sending/i18n/es.po @@ -0,0 +1,74 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_certification_sending +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-02-12 14:06+0000\n" +"PO-Revision-Date: 2025-02-12 15:11+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.4.2\n" + +#. module: survey_certification_sending +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "%s certification(s) successfully sent." +msgstr "%s certificación(es) enviada(s) con éxito." + +#. module: survey_certification_sending +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_user_input__certification_sent +msgid "Certification Sent" +msgstr "Certificación enviada" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_mail_template +msgid "Email Templates" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model.fields,help:survey_certification_sending.field_survey_user_input__certification_sent +msgid "It indicates if the certification has been sent." +msgstr "Indica si la certificación ha sido enviada." + +#. module: survey_certification_sending +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "No certifications sent. The survey does not meet the conditions." +msgstr "No se han enviado certificaciones. La encuesta no cumple las condiciones." + +#. module: survey_certification_sending +#: model:ir.actions.server,name:survey_certification_sending.ir_actions_server_send_certification +msgid "Send Certification Email" +msgstr "Enviar certificación por correo electrónico" + +#. module: survey_certification_sending +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_survey__skip_auto_email +msgid "Skip Auto Email" +msgstr "Omitir correo automático" + +#. module: survey_certification_sending +#: model:ir.model.fields,help:survey_certification_sending.field_survey_survey__skip_auto_email +msgid "" +"Skip sending the certification automatically after successful completion of " +"the survey." +msgstr "" +"Omitir el envío automático de la certificación una vez completada con éxito la " +"la encuesta." + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_survey_survey +msgid "Survey" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_survey_user_input +msgid "Survey User Input" +msgstr "" diff --git a/survey_certification_sending/i18n/survey_certification_sending.pot b/survey_certification_sending/i18n/survey_certification_sending.pot new file mode 100644 index 00000000..43591e03 --- /dev/null +++ b/survey_certification_sending/i18n/survey_certification_sending.pot @@ -0,0 +1,70 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_certification_sending +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-02-12 14:06+0000\n" +"PO-Revision-Date: 2025-02-12 14:06+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: survey_certification_sending +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "%s certification(s) successfully sent." +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_user_input__certification_sent +msgid "Certification Sent" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_mail_template +msgid "Email Templates" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model.fields,help:survey_certification_sending.field_survey_user_input__certification_sent +msgid "It indicates if the certification has been sent." +msgstr "" + +#. module: survey_certification_sending +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "No certifications sent. The survey does not meet the conditions." +msgstr "" + +#. module: survey_certification_sending +#: model:ir.actions.server,name:survey_certification_sending.ir_actions_server_send_certification +msgid "Send Certification Email" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_survey__skip_auto_email +msgid "Skip Auto Email" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model.fields,help:survey_certification_sending.field_survey_survey__skip_auto_email +msgid "" +"Skip sending the certification automatically after successful completion of " +"the survey." +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_survey_survey +msgid "Survey" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_survey_user_input +msgid "Survey User Input" +msgstr "" diff --git a/survey_certification_sending/models/__init__.py b/survey_certification_sending/models/__init__.py new file mode 100644 index 00000000..2cff3554 --- /dev/null +++ b/survey_certification_sending/models/__init__.py @@ -0,0 +1,3 @@ +from . import mail_template +from . import survey_survey +from . import survey_user_input diff --git a/survey_certification_sending/models/mail_template.py b/survey_certification_sending/models/mail_template.py new file mode 100644 index 00000000..69f6f5a5 --- /dev/null +++ b/survey_certification_sending/models/mail_template.py @@ -0,0 +1,21 @@ +# Copyright 2025 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class MailTemplate(models.Model): + _inherit = "mail.template" + + def send_mail( + self, + res_id, + force_send=False, + raise_exception=False, + email_values=None, + notif_layout=False, + ): + if self.env.context.get("skip_auto_email"): + return False + return super().send_mail( + res_id, force_send, raise_exception, email_values, notif_layout + ) diff --git a/survey_certification_sending/models/survey_survey.py b/survey_certification_sending/models/survey_survey.py new file mode 100644 index 00000000..554c3589 --- /dev/null +++ b/survey_certification_sending/models/survey_survey.py @@ -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 = "survey.survey" + + skip_auto_email = fields.Boolean( + help="Skip sending the certification automatically after successful completion " + "of the survey." + ) diff --git a/survey_certification_sending/models/survey_user_input.py b/survey_certification_sending/models/survey_user_input.py new file mode 100644 index 00000000..bbcf3472 --- /dev/null +++ b/survey_certification_sending/models/survey_user_input.py @@ -0,0 +1,56 @@ +# Copyright 2025 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import _, fields, models + + +class SurveyUserInput(models.Model): + _inherit = "survey.user_input" + + certification_sent = fields.Boolean( + default=False, help="It indicates if the certification has been sent." + ) + + def _mark_done(self): + for user_input in self: + if ( + not user_input.survey_id.skip_auto_email + and user_input.survey_id.certification + and user_input.scoring_success + ): + if ( + user_input.survey_id.certification_mail_template_id + and not user_input.test_entry + ): + user_input.certification_sent = True + + # Mark as completed and send email only if not deactivated. + return super( + SurveyUserInput, + self.with_context( + skip_auto_email=self.mapped("survey_id").filtered( + lambda s: s.skip_auto_email + ) + ), + )._mark_done() + + def action_manual_send_certification(self): + # Send certifications manually only to those who passed the survey. + sent_count = 0 + for user_input in self: + if ( + user_input.survey_id.certification + and user_input.scoring_success + and not user_input.test_entry + ): + template = user_input.survey_id.certification_mail_template_id + if template: + template.send_mail( + user_input.id, notif_layout="mail.mail_notification_light" + ) + user_input.certification_sent = True + sent_count += 1 + + if sent_count: + return _("%s certification(s) successfully sent.", sent_count) + else: + return _("No certifications sent. The survey does not meet the conditions.") diff --git a/survey_certification_sending/readme/CONTRIBUTORS.rst b/survey_certification_sending/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..a926d758 --- /dev/null +++ b/survey_certification_sending/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_ + + * David Vidal + * Pilar Vargas diff --git a/survey_certification_sending/readme/DESCRIPTION.rst b/survey_certification_sending/readme/DESCRIPTION.rst new file mode 100644 index 00000000..9758a292 --- /dev/null +++ b/survey_certification_sending/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the Odoo Survey application to allow automatic and manual sending +of certifications when a participant successfully completes a survey. diff --git a/survey_certification_sending/readme/USAGE.rst b/survey_certification_sending/readme/USAGE.rst new file mode 100644 index 00000000..4df4dd76 --- /dev/null +++ b/survey_certification_sending/readme/USAGE.rst @@ -0,0 +1,12 @@ +To use this module, you need to: + +#. Go to Survey > Surveys. +#. Create or edit a certification survey. +#. Configure whether you want to send certifications manually by checking the + "Skip Auto Email" option. +#. Participants who pass the survey will receive their certification automatically if + manual submission is not enabled. +#. If the automatic sending is disabled, passed certifications can be submitted manually + from the "Send certification email" action. +#. Certifications that have already been sent will be marked as "Certification sent". +#. Passed certifications can be sent as many times as necessary. diff --git a/survey_certification_sending/static/description/index.html b/survey_certification_sending/static/description/index.html new file mode 100644 index 00000000..30577679 --- /dev/null +++ b/survey_certification_sending/static/description/index.html @@ -0,0 +1,447 @@ + + + + + +Survey Certification Sending + + + +
+

Survey Certification Sending

+ + +

Beta License: AGPL-3 OCA/survey Translate me on Weblate Try me on Runboat

+

This module extends the Odoo Survey application to allow automatic and manual sending +of certifications when a participant successfully completes a survey.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Survey > Surveys.
  2. +
  3. Create or edit a certification survey.
  4. +
  5. Configure whether you want to send certifications manually by checking the +“Skip Auto Email” option.
  6. +
  7. Participants who pass the survey will receive their certification automatically if +manual submission is not enabled.
  8. +
  9. If the automatic sending is disabled, passed certifications can be submitted manually +from the “Send certification email” action.
  10. +
  11. Certifications that have already been sent will be marked as “Certification sent”.
  12. +
  13. Passed certifications can be sent as many times as necessary.
  14. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

pilarvargas-tecnativa

+

This module is part of the OCA/survey project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/survey_certification_sending/tests/__init__.py b/survey_certification_sending/tests/__init__.py new file mode 100644 index 00000000..e2466bc3 --- /dev/null +++ b/survey_certification_sending/tests/__init__.py @@ -0,0 +1 @@ +from . import test_survey_certification_sending diff --git a/survey_certification_sending/tests/test_survey_certification_sending.py b/survey_certification_sending/tests/test_survey_certification_sending.py new file mode 100644 index 00000000..7e449698 --- /dev/null +++ b/survey_certification_sending/tests/test_survey_certification_sending.py @@ -0,0 +1,185 @@ +from odoo.tests import tagged + +from odoo.addons.survey.tests.common import TestSurveyCommon + + +@tagged("-at_install", "post_install", "functional") +class TestCertificationsending(TestSurveyCommon): + def test_certification_auto_sending(self): + test_certification = self.env["survey.survey"].create( + { + "title": "Test Certification 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) + answer.with_user(self.env.user).write({"state": "done"}) + answer._mark_done() + # Verify that the certification has been sent automatically. + self.assertTrue(answer.scoring_success) + self.assertTrue(answer.certification_sent) + + def test_certification_skip_auto_sending(self): + test_certification = self.env["survey.survey"].create( + { + "title": "Test Certification 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, + "skip_auto_email": 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) + 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) + + def test_no_passed_certification_skip_auto_sending(self): + test_certification = self.env["survey.survey"].create( + { + "title": "Test No Passed Certification 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, + "skip_auto_email": 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[0].id) + self._add_answer_line(q_02, answer, q_02.suggested_answer_ids[3].id) + answer.with_user(self.env.user).write({"state": "done"}) + answer._mark_done() + # Verify that the certification has not been sent automatically + self.assertFalse(answer.scoring_success) + self.assertFalse(answer.certification_sent) + # Verify that the certification has not been sent manually + answer.action_manual_send_certification() + self.assertFalse(answer.certification_sent) diff --git a/survey_certification_sending/views/survey_survey_views.xml b/survey_certification_sending/views/survey_survey_views.xml new file mode 100644 index 00000000..d950146d --- /dev/null +++ b/survey_certification_sending/views/survey_survey_views.xml @@ -0,0 +1,15 @@ + + + + survey.survey + + + + + + + + diff --git a/survey_certification_sending/views/survey_user_views.xml b/survey_certification_sending/views/survey_user_views.xml new file mode 100644 index 00000000..c3904e93 --- /dev/null +++ b/survey_certification_sending/views/survey_user_views.xml @@ -0,0 +1,40 @@ + + + + survey.user_input + + + + + + + + + + + Send Certification Email + ir.actions.server + + code + + if records: + result = records.action_manual_send_certification() + action = { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "title": "Certification Sent", + "message": result, + "type": "success", + "sticky": False, + }, + } + + + list,form + +