[FIX] survey: prevent question deletion when session in progress
If we create a survey and start a new session. When the session state is in progress and If the survey creater deletes a question and participant tries to answer the deleted question and submits it then participant will face the issue of 'False is not in list'. This commit will raise an usererror if the survey creater tries to delete the question when the survey session is in progress. sentry-4113791861 closes odoo/odoo#124769 X-original-commit: f636025fce4edda8a5f89b7161c4e9481460f03f Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Saurabh Mishra (sami) <sami@odoo.com>
This commit is contained in:
@@ -5158,6 +5158,14 @@ msgstr ""
|
||||
|
||||
#. module: survey
|
||||
#. odoo-python
|
||||
#: code:addons/survey/models/survey_question.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot delete questions from surveys \"%(survey_names)s\" while live "
|
||||
"sessions are in progress."
|
||||
msgstr ""
|
||||
|
||||
#. module: survey
|
||||
#: code:addons/survey/models/survey_survey.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
|
||||
@@ -8,7 +8,7 @@ import itertools
|
||||
import operator
|
||||
|
||||
from odoo import api, fields, models, tools, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class SurveyQuestion(models.Model):
|
||||
@@ -407,6 +407,19 @@ class SurveyQuestion(models.Model):
|
||||
})
|
||||
return super().unlink()
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# CRUD
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_live_sessions_in_progress(self):
|
||||
running_surveys = self.survey_id.filtered(lambda survey: survey.session_state == 'in_progress')
|
||||
if running_surveys:
|
||||
raise UserError(_(
|
||||
'You cannot delete questions from surveys "%(survey_names)s" while live sessions are in progress.',
|
||||
survey_names=', '.join(running_surveys.mapped('title')),
|
||||
))
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# VALIDATION
|
||||
# ------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user