[FIX] survey_record_generation: unblock survey edition after a line without field
When a record creation has a field value line whose field is not chosen yet,
``_compute_allowed_question_ids`` returned instead of moving on to the next
line. The lines computed after it were left without a value, and Odoo raised
``Compute method failed to assign ... allowed_question_ids`` on every onchange
of the survey form, so no field of the survey could be edited or deleted any
more.
Skip to the next line instead, as already done on 18.0 (94d3bd7).
This commit is contained in:
@@ -83,7 +83,7 @@ class SurveyRecordCreationFieldValues(models.Model):
|
||||
for record_creation_field_values in self:
|
||||
if not record_creation_field_values.survey_id or not record_creation_field_values.field_id:
|
||||
record_creation_field_values.allowed_question_ids = None
|
||||
return
|
||||
continue
|
||||
question_domain = [('survey_id','=',record_creation_field_values.survey_id.id)]
|
||||
|
||||
if record_creation_field_values.field_id.ttype in ['many2one','many2many']:
|
||||
|
||||
@@ -1096,3 +1096,31 @@ class TestSurveyRecordCreation(SurveyCase):
|
||||
self.assertEqual(self.answer.partner_id, jean)
|
||||
self.assertNotEqual(self.answer.partner_id, jeanne)
|
||||
self.assertEqual(self.answer.email, jean.email)
|
||||
|
||||
def test_allowed_questions_are_computed_after_a_line_without_field(self):
|
||||
# The administrator has added a line without choosing its field yet,
|
||||
# followed by a complete line
|
||||
FieldValues = self.env["survey.record.creation.field.values"]
|
||||
line_without_field = FieldValues.create(
|
||||
{
|
||||
"survey_record_creation_id": self.survey_record_creation.id,
|
||||
"value_origin": "fixed",
|
||||
}
|
||||
)
|
||||
line_with_field = FieldValues.create(
|
||||
{
|
||||
"survey_record_creation_id": self.survey_record_creation.id,
|
||||
"field_id": self.name_field.id,
|
||||
"value_origin": "question",
|
||||
"question_id": self.question_name.id,
|
||||
}
|
||||
)
|
||||
lines = line_without_field | line_with_field
|
||||
lines.invalidate_recordset(["allowed_question_ids"])
|
||||
|
||||
# Reading the lines together, as the survey form does, computes
|
||||
# the allowed questions of every line
|
||||
allowed = {line: line.allowed_question_ids for line in lines}
|
||||
|
||||
self.assertFalse(allowed[line_without_field])
|
||||
self.assertIn(self.question_name, allowed[line_with_field])
|
||||
|
||||
Reference in New Issue
Block a user