diff --git a/survey_certification_sending/README.rst b/survey_certification_sending/README.rst new file mode 100644 index 00000000..15530516 --- /dev/null +++ b/survey_certification_sending/README.rst @@ -0,0 +1,106 @@ +============================ +Survey Certification Sending +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f65da06bc4263b39b955284f983d99eece46675b15b14d82fa35db2528e31372 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/18.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-18-0/survey-18-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=18.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: + +1. Go to Survey > Surveys. +2. Create or edit a certification survey. +3. Configure whether you want to send certifications manually by + checking the "Skip Auto Email" option. +4. Participants who pass the survey will receive their certification + automatically if manual submission is not enabled. +5. If the automatic sending is disabled, passed certifications can be + submitted manually from the "Send certification email" action. +6. Certifications that have already been sent will be marked as + "Certification sent". +7. 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..f4850d61 --- /dev/null +++ b/survey_certification_sending/__manifest__.py @@ -0,0 +1,21 @@ +# 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": "18.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/res_partner_views.xml", + "views/survey_survey_views.xml", + "views/survey_templates.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..5daab8ac --- /dev/null +++ b/survey_certification_sending/i18n/es.po @@ -0,0 +1,95 @@ +# 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-21 06:59+0000\n" +"PO-Revision-Date: 2025-02-21 08:01+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 +#. odoo-python +#: 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 +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_user_input__certification_sent +#, python-format +msgid "Certification Sent" +msgstr "Certificación enviada" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_res_partner +msgid "Contact" +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 "Indica si la certificación ha sido enviada." + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "No Certifications Sent" +msgstr "Certificaciones no enviadas" + +#. 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_res_partner__skip_certification_email +#: model:ir.model.fields,field_description:survey_certification_sending.field_res_users__skip_certification_email +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_survey__skip_certification_email +msgid "Skip Certification Email" +msgstr "Omitir correo de certificación" + +#. module: survey_certification_sending +#: model:ir.model.fields,help:survey_certification_sending.field_res_partner__skip_certification_email +#: model:ir.model.fields,help:survey_certification_sending.field_res_users__skip_certification_email +#: model:ir.model.fields,help:survey_certification_sending.field_survey_survey__skip_certification_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 "" + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "The survey does not meet the conditions." +msgstr "La encuesta no cumple las condiciones." diff --git a/survey_certification_sending/i18n/it.po b/survey_certification_sending/i18n/it.po new file mode 100644 index 00000000..b0dce44e --- /dev/null +++ b/survey_certification_sending/i18n/it.po @@ -0,0 +1,94 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_certification_sending +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-05-29 10:26+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.4\n" + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "%s certification(s) successfully sent." +msgstr "%s certificazioni spedite correttamente." + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_user_input__certification_sent +#, python-format +msgid "Certification Sent" +msgstr "Certificazione spedita" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_mail_template +msgid "Email Templates" +msgstr "Modelli e-mail" + +#. 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 se la certificazione è stata spedita." + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "No Certifications Sent" +msgstr "Nessuna certificazione spedita" + +#. module: survey_certification_sending +#: model:ir.actions.server,name:survey_certification_sending.ir_actions_server_send_certification +msgid "Send Certification Email" +msgstr "Invia e-mail certificazione" + +#. module: survey_certification_sending +#: model:ir.model.fields,field_description:survey_certification_sending.field_res_partner__skip_certification_email +#: model:ir.model.fields,field_description:survey_certification_sending.field_res_users__skip_certification_email +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_survey__skip_certification_email +msgid "Skip Certification Email" +msgstr "Salta e-mail certificazione" + +#. module: survey_certification_sending +#: model:ir.model.fields,help:survey_certification_sending.field_res_partner__skip_certification_email +#: model:ir.model.fields,help:survey_certification_sending.field_res_users__skip_certification_email +#: model:ir.model.fields,help:survey_certification_sending.field_survey_survey__skip_certification_email +msgid "" +"Skip sending the certification automatically after successful completion of " +"the survey." +msgstr "" +"Evita di inviare automaticamente la certificazione al completamento corretto " +"del sondaggio." + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_survey_survey +msgid "Survey" +msgstr "Sondaggio" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_survey_user_input +msgid "Survey User Input" +msgstr "Risposta utente al sondaggio" + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "The survey does not meet the conditions." +msgstr "Il sondaggio non soddisfa le condizioni." 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..abbb8e68 --- /dev/null +++ b/survey_certification_sending/i18n/survey_certification_sending.pot @@ -0,0 +1,89 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * survey_certification_sending +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \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 +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "%s certification(s) successfully sent." +msgstr "" + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_user_input__certification_sent +#, python-format +msgid "Certification Sent" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model,name:survey_certification_sending.model_res_partner +msgid "Contact" +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 +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "No Certifications Sent" +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_res_partner__skip_certification_email +#: model:ir.model.fields,field_description:survey_certification_sending.field_res_users__skip_certification_email +#: model:ir.model.fields,field_description:survey_certification_sending.field_survey_survey__skip_certification_email +msgid "Skip Certification Email" +msgstr "" + +#. module: survey_certification_sending +#: model:ir.model.fields,help:survey_certification_sending.field_res_partner__skip_certification_email +#: model:ir.model.fields,help:survey_certification_sending.field_res_users__skip_certification_email +#: model:ir.model.fields,help:survey_certification_sending.field_survey_survey__skip_certification_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 "" + +#. module: survey_certification_sending +#. odoo-python +#: code:addons/survey_certification_sending/models/survey_user_input.py:0 +#, python-format +msgid "The survey does not meet the conditions." +msgstr "" diff --git a/survey_certification_sending/models/__init__.py b/survey_certification_sending/models/__init__.py new file mode 100644 index 00000000..53cdf28a --- /dev/null +++ b/survey_certification_sending/models/__init__.py @@ -0,0 +1,4 @@ +from . import mail_template +from . import res_partner +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..5b943488 --- /dev/null +++ b/survey_certification_sending/models/mail_template.py @@ -0,0 +1,26 @@ +# 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, + email_layout_xmlid=False, + ): + if self.model == "survey.user_input": + 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 + ) diff --git a/survey_certification_sending/models/res_partner.py b/survey_certification_sending/models/res_partner.py new file mode 100644 index 00000000..17f1358a --- /dev/null +++ b/survey_certification_sending/models/res_partner.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 = "res.partner" + + skip_certification_email = fields.Boolean( + help="Skip sending the certification automatically after successful completion " + "of the survey." + ) diff --git a/survey_certification_sending/models/survey_survey.py b/survey_certification_sending/models/survey_survey.py new file mode 100644 index 00000000..87f0973e --- /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_certification_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..058f19a2 --- /dev/null +++ b/survey_certification_sending/models/survey_user_input.py @@ -0,0 +1,61 @@ +# 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: + # The response is marked as sent in anticipation that it will be sent + # safely. + if ( + 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 + return super()._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, email_layout_xmlid="mail.mail_notification_light" + ) + user_input.certification_sent = True + sent_count += 1 + if sent_count: + title = _("Certification Sent") + message = _("%s certification(s) successfully sent.") % sent_count + notif_type = "success" + else: + title = _("No Certifications Sent") + message = _("The survey does not meet the conditions.") + notif_type = "warning" + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "title": title, + "message": message, + "type": notif_type, + "sticky": False, + }, + } diff --git a/survey_certification_sending/pyproject.toml b/survey_certification_sending/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/survey_certification_sending/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/survey_certification_sending/readme/CONTRIBUTORS.md b/survey_certification_sending/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..68e9227d --- /dev/null +++ b/survey_certification_sending/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Tecnativa](https://www.tecnativa.com) + - David Vidal + - Pilar Vargas diff --git a/survey_certification_sending/readme/DESCRIPTION.md b/survey_certification_sending/readme/DESCRIPTION.md new file mode 100644 index 00000000..b377912b --- /dev/null +++ b/survey_certification_sending/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +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.md b/survey_certification_sending/readme/USAGE.md new file mode 100644 index 00000000..a5744530 --- /dev/null +++ b/survey_certification_sending/readme/USAGE.md @@ -0,0 +1,13 @@ +To use this module, you need to: + +1. Go to Survey \> Surveys. +2. Create or edit a certification survey. +3. Configure whether you want to send certifications manually by + checking the "Skip Auto Email" option. +4. Participants who pass the survey will receive their certification + automatically if manual submission is not enabled. +5. If the automatic sending is disabled, passed certifications can be + submitted manually from the "Send certification email" action. +6. Certifications that have already been sent will be marked as + "Certification sent". +7. Passed certifications can be sent as many times as necessary. diff --git a/survey_certification_sending/static/description/icon.png b/survey_certification_sending/static/description/icon.png new file mode 100644 index 00000000..1dcc49c2 Binary files /dev/null and b/survey_certification_sending/static/description/icon.png differ diff --git a/survey_certification_sending/static/description/index.html b/survey_certification_sending/static/description/index.html new file mode 100644 index 00000000..5c298cbd --- /dev/null +++ b/survey_certification_sending/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +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..883ace94 --- /dev/null +++ b/survey_certification_sending/tests/test_survey_certification_sending.py @@ -0,0 +1,402 @@ +# Copyright 2022 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from unittest.mock import patch + +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_certification_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_certification_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) + + 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) + + # --- shared helper --- + + def _make_passing_certification(self, title, extra_vals=None): + vals = { + "title": title, + "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, + } + if extra_vals: + vals.update(extra_vals) + survey = self.env["survey.survey"].create(vals) + q = self._add_question( + None, + "1+1", + "simple_choice", + sequence=1, + constr_mandatory=True, + constr_error_msg="Please select an answer", + survey_id=survey.id, + labels=[ + {"value": "1"}, + {"value": "2", "is_correct": True, "answer_score": 100.0}, + ], + ) + return survey, q + + # --- survey_user_input.py coverage --- + + def test_mark_done_test_entry_skips_certification(self): + survey, q = self._make_passing_certification("Test Entry No Cert") + answer = self._add_answer(survey, self.env.user) + self._add_answer_line(q, answer, q.suggested_answer_ids[1].id) + answer.write({"test_entry": True, "state": "done"}) + answer._mark_done() + self.assertTrue(answer.scoring_success) + self.assertFalse(answer.certification_sent) + + def test_mark_done_no_template_skips_certification(self): + survey, q = self._make_passing_certification( + "No Template No Cert", + extra_vals={"certification_mail_template_id": False}, + ) + answer = self._add_answer(survey, self.env.user) + self._add_answer_line(q, answer, q.suggested_answer_ids[1].id) + answer.write({"state": "done"}) + answer._mark_done() + self.assertTrue(answer.scoring_success) + self.assertFalse(answer.certification_sent) + + def test_manual_send_success_notification(self): + survey, q = self._make_passing_certification( + "Manual Send Success", extra_vals={"skip_certification_email": True} + ) + answer = self._add_answer(survey, self.env.user) + self._add_answer_line(q, answer, q.suggested_answer_ids[1].id) + answer.write({"state": "done"}) + answer._mark_done() + result = answer.action_manual_send_certification() + self.assertEqual(result["type"], "ir.actions.client") + self.assertEqual(result["params"]["type"], "success") + self.assertTrue(answer.certification_sent) + + def test_manual_send_warning_when_not_passed(self): + survey, q = self._make_passing_certification("Manual Send Warning") + answer = self._add_answer(survey, self.env.user) + self._add_answer_line(q, answer, q.suggested_answer_ids[0].id) + answer.write({"state": "done"}) + answer._mark_done() + result = answer.action_manual_send_certification() + self.assertEqual(result["type"], "ir.actions.client") + self.assertEqual(result["params"]["type"], "warning") + self.assertFalse(answer.certification_sent) + + def test_manual_send_no_template_returns_warning(self): + # covers: if template: False branch — answer passed but no template set + survey, q = self._make_passing_certification( + "Manual Send No Template", + extra_vals={"certification_mail_template_id": False}, + ) + answer = self._add_answer(survey, self.env.user) + self._add_answer_line(q, answer, q.suggested_answer_ids[1].id) + answer.write({"state": "done"}) + answer._mark_done() + result = answer.action_manual_send_certification() + self.assertEqual(result["type"], "ir.actions.client") + self.assertEqual(result["params"]["type"], "warning") + self.assertFalse(answer.certification_sent) + + # --- mail_template.py coverage --- + + def test_send_mail_non_survey_model_calls_super(self): + # This module overrides send_mail on ALL mail.template records. + # The guard "if self.model == 'survey.user_input'" ensures the skip + # logic never interferes with templates for other models. + # This test covers the False branch of that guard. + model_id = ( + self.env["ir.model"].search([("model", "=", "res.partner")], limit=1).id + ) + partner_template = self.env["mail.template"].create( + { + "name": "Test Non Survey Template", + "model_id": model_id, + "subject": "Test", + "body_html": "

Test

", + } + ) + with patch( + "odoo.addons.mail.models.mail_template.MailTemplate.send_mail", + return_value=True, + ) as mock_send: + result = partner_template.send_mail(self.env.user.partner_id.id) + mock_send.assert_called_once() + self.assertTrue(result) + + def test_send_mail_returns_false_when_survey_skip(self): + survey, _q = self._make_passing_certification( + "Send Mail Survey Skip", + extra_vals={"skip_certification_email": True}, + ) + answer = self._add_answer(survey, self.env.user) + template = self.env.ref("survey.mail_template_certification") + self.assertFalse(template.send_mail(answer.id)) + + def test_send_mail_returns_false_when_partner_skip(self): + survey, _q = self._make_passing_certification("Send Mail Partner Skip") + answer = self._add_answer(survey, self.env.user) + answer.partner_id.write({"skip_certification_email": True}) + template = self.env.ref("survey.mail_template_certification") + self.assertFalse(template.send_mail(answer.id)) + + def test_send_mail_proceeds_when_no_skip(self): + survey, _q = self._make_passing_certification("Send Mail Proceeds") + answer = self._add_answer(survey, self.env.user) + template = self.env.ref("survey.mail_template_certification") + with patch( + "odoo.addons.mail.models.mail_template.MailTemplate.send_mail", + return_value=True, + ) as mock_send: + result = template.send_mail(answer.id) + mock_send.assert_called_once() + self.assertTrue(result) diff --git a/survey_certification_sending/views/res_partner_views.xml b/survey_certification_sending/views/res_partner_views.xml new file mode 100644 index 00000000..1d339f1a --- /dev/null +++ b/survey_certification_sending/views/res_partner_views.xml @@ -0,0 +1,16 @@ + + + + res.partner.form.view + res.partner + + + + + + + + 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..4e408612 --- /dev/null +++ b/survey_certification_sending/views/survey_survey_views.xml @@ -0,0 +1,12 @@ + + + + survey.survey + + + + + + + + diff --git a/survey_certification_sending/views/survey_templates.xml b/survey_certification_sending/views/survey_templates.xml new file mode 100644 index 00000000..602b16a1 --- /dev/null +++ b/survey_certification_sending/views/survey_templates.xml @@ -0,0 +1,15 @@ + + + + + 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..70fd9555 --- /dev/null +++ b/survey_certification_sending/views/survey_user_views.xml @@ -0,0 +1,29 @@ + + + + survey.user_input + + + + + + + + + + + Send Certification Email + ir.actions.server + + code + + action = records.action_manual_send_certification() + + + list,form + +