From 87b42837ec271e69c7ac22a4739702e4255a1e95 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 16 Nov 2026 16:54:43 +0100 Subject: [PATCH] [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). --- .../survey_record_creation_field_values.py | 2 +- .../tests/test_survey_record_creation.py | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/survey_record_generation/models/survey_record_creation_field_values.py b/survey_record_generation/models/survey_record_creation_field_values.py index 81bedd1..b9de430 100644 --- a/survey_record_generation/models/survey_record_creation_field_values.py +++ b/survey_record_generation/models/survey_record_creation_field_values.py @@ -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']: diff --git a/survey_record_generation/tests/test_survey_record_creation.py b/survey_record_generation/tests/test_survey_record_creation.py index bcb304e..9382f61 100644 --- a/survey_record_generation/tests/test_survey_record_creation.py +++ b/survey_record_generation/tests/test_survey_record_creation.py @@ -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]) -- 2.49.1