From ab2afb0e9d032fbbdfd1a7071ef1d90f08f0a865 Mon Sep 17 00:00:00 2001 From: Mitul Shah Date: Thu, 29 Jul 2021 11:50:44 +0000 Subject: [PATCH] [FIX] survey: fix the warning message while sharing the survey Currently, while trying to share the survey with 'one page per section' layout, if the survey has only questions and no sections, a warning is raised that says 'You cannot send an invitation for a survey that has no questions'. It is misleading because in this case, what you do not have is atleast one section with question(s). This commit fixes the warning message for 'one page per section' type of survey and gives clear idea to the user about what is missing. TaskID-2611996 closes odoo/odoo#74694 X-original-commit: 381d18888d81f6797004c718fee5dbd9706b3122 Signed-off-by: awa-odoo Signed-off-by: Thibault Delavallee (tde) --- addons/survey/i18n/survey.pot | 12 ++++++++++++ addons/survey/models/survey_survey.py | 15 +++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/addons/survey/i18n/survey.pot b/addons/survey/i18n/survey.pot index 7c7fd6449d5..2de962b4a44 100644 --- a/addons/survey/i18n/survey.pot +++ b/addons/survey/i18n/survey.pot @@ -3084,6 +3084,18 @@ msgstr "" msgid "You cannot send an invitation for a survey that has no questions." msgstr "" +#. module: survey +#: code:addons/survey/models/survey_survey.py:0 +#, python-format +msgid "You cannot send an invitation for a \"One page per section\" survey if the survey has no sections." +msgstr "" + +#. module: survey +#: code:addons/survey/models/survey_survey.py:0 +#, python-format +msgid "You cannot send an invitation for a \"One page per section\" survey if the survey only contains empty sections." +msgstr "" + #. module: survey #: code:addons/survey/models/survey_survey.py:0 #, python-format diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index 58c5a93accc..f7ab94ce86a 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -7,7 +7,7 @@ import uuid import werkzeug from odoo import api, exceptions, fields, models, _ -from odoo.exceptions import AccessError +from odoo.exceptions import AccessError, UserError from odoo.osv import expression from odoo.tools import is_html_empty @@ -803,9 +803,16 @@ class Survey(models.Model): def action_send_survey(self): """ Open a window to compose an email, pre-filled with the survey message """ - # Ensure that this survey has at least one page with at least one question. - if (not self.page_ids and self.questions_layout == 'page_per_section') or not self.question_ids: - raise exceptions.UserError(_('You cannot send an invitation for a survey that has no questions.')) + # Ensure that this survey has at least one question. + if not self.question_ids: + raise UserError(_('You cannot send an invitation for a survey that has no questions.')) + + # Ensure that this survey has at least one section with question(s), if question layout is 'One page per section'. + if self.questions_layout == 'page_per_section': + if not self.page_ids: + raise UserError(_('You cannot send an invitation for a "One page per section" survey if the survey has no sections.')) + if not self.page_ids.mapped('question_ids'): + raise UserError(_('You cannot send an invitation for a "One page per section" survey if the survey only contains empty sections.')) if not self.active: raise exceptions.UserError(_("You cannot send invitations for closed surveys."))