[MIG] survey_extra_fields, survey_base : modifications to make them work in v18
This commit is contained in:
@@ -8,7 +8,7 @@ import os
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from odoo.addons.survey_extra_fields.models.survey_question import SurveyQuestion
|
||||
@@ -17,12 +17,20 @@ if TYPE_CHECKING:
|
||||
class SurveyUserInput(models.Model):
|
||||
_inherit = "survey.user_input"
|
||||
|
||||
def save_lines(self, question: SurveyQuestion, answer: str | None, comment: str | None = None) -> None:
|
||||
def _save_lines(
|
||||
self,
|
||||
question: SurveyQuestion,
|
||||
answer: str | None,
|
||||
comment: str | None = None,
|
||||
overwrite_existing: bool = True,
|
||||
) -> None:
|
||||
if question.question_type == "file":
|
||||
old_answers = self.env["survey.user_input.line"].search([
|
||||
("user_input_id", "=", self.id),
|
||||
("question_id", "=", question.id),
|
||||
])
|
||||
if old_answers and not overwrite_existing:
|
||||
raise UserError(_("This answer cannot be overwritten."))
|
||||
vals = {
|
||||
"user_input_id": self.id,
|
||||
"question_id": question.id,
|
||||
@@ -43,7 +51,9 @@ class SurveyUserInput(models.Model):
|
||||
else:
|
||||
self.env["survey.user_input.line"].create(vals)
|
||||
else:
|
||||
return super().save_lines(question, answer, comment=comment)
|
||||
return super()._save_lines(
|
||||
question, answer, comment=comment, overwrite_existing=overwrite_existing
|
||||
)
|
||||
|
||||
def _check_file_constraints(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user