diff --git a/addons/website_event_questions/models/event_question.py b/addons/website_event_questions/models/event_question.py index 4d058569d4c..195413c5929 100644 --- a/addons/website_event_questions/models/event_question.py +++ b/addons/website_event_questions/models/event_question.py @@ -40,6 +40,11 @@ class EventQuestion(models.Model): raise UserError(_("You cannot change the question type of a question that already has answers!")) return super(EventQuestion, self).write(vals) + @api.ondelete(at_uninstall=False) + def _unlink_except_answered_question(self): + if self.env['event.registration.answer'].search_count([('question_id', 'in', self.ids)]): + raise UserError(_('You cannot delete a question that has already been answered by attendees.')) + def action_view_question_answers(self): """ Allow analyzing the attendees answers to event questions in a convenient way: - A graph view showing counts of each suggestions for simple_choice questions @@ -63,3 +68,8 @@ class EventQuestionAnswer(models.Model): name = fields.Char('Answer', required=True, translate=True) question_id = fields.Many2one('event.question', required=True, ondelete='cascade') sequence = fields.Integer(default=10) + + @api.ondelete(at_uninstall=False) + def _unlink_except_selected_answer(self): + if self.env['event.registration.answer'].search_count([('value_answer_id', 'in', self.ids)]): + raise UserError(_('You cannot delete an answer that has already been selected by attendees.'))