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."))