diff --git a/survey_record_generation/__manifest__.py b/survey_record_generation/__manifest__.py
index 22845c1..1fa0e2a 100644
--- a/survey_record_generation/__manifest__.py
+++ b/survey_record_generation/__manifest__.py
@@ -11,7 +11,7 @@ Allow to create record of any model when sending the form :
* Associate question with fields
* For x2m fields : Associate values to questions
""",
- "version": "18.0.1.0.0",
+ "version": "18.0.1.0.1",
"license": "AGPL-3",
"author": "Elabore",
"website": "https://www.elabore.coop",
diff --git a/survey_record_generation/models/survey_question.py b/survey_record_generation/models/survey_question.py
index 4bb0478..426ec10 100644
--- a/survey_record_generation/models/survey_question.py
+++ b/survey_record_generation/models/survey_question.py
@@ -32,8 +32,9 @@ class SurveyQuestion(models.Model):
def fill(self):
for question in self:
- if question.model_id:
- new_suggested_answer_ids = [Command.clear()]
+ if question.suggested_answer_ids:
+ question.suggested_answer_ids = [Command.clear()]
+ elif question.model_id:
record_model = question.model_id.model
if question.fill_domain:
@@ -43,7 +44,11 @@ class SurveyQuestion(models.Model):
records = self.env[record_model].search(domain)
- new_suggested_answer_ids += [Command.create({'value':record.display_name, 'record_id':f"{record_model},{record.id}"
-}) for record in records]
- question.suggested_answer_ids = new_suggested_answer_ids
+ question.suggested_answer_ids = [
+ Command.create({
+ 'value': record.display_name,
+ 'record_id': f"{record_model},{record.id}",
+ })
+ for record in records
+ ]
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 b9de430..3e79913 100644
--- a/survey_record_generation/models/survey_record_creation_field_values.py
+++ b/survey_record_generation/models/survey_record_creation_field_values.py
@@ -5,9 +5,6 @@ from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools.misc import format_date
-_logger = logging.getLogger(__name__)
-
-
type_mapping = { #field types on the left, question types on the right. TODO : what about booleans ?
"char": ["char_box", "numerical_box", "date", "datetime", "simple_choice", "multiple_choice"],
"text": ["char_box", "date", "simple_choice"],
@@ -78,20 +75,28 @@ class SurveyRecordCreationFieldValues(models.Model):
record.field_help = field_help
- @api.depends('field_id')
+ @api.depends('field_id', 'survey_record_creation_id.survey_id')
def _compute_allowed_question_ids(self):
- 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
+ for record in self:
+ survey = record.survey_id or record.survey_record_creation_id.survey_id
+ if not survey or not record.field_id:
+ record.allowed_question_ids = False
continue
- question_domain = [('survey_id','=',record_creation_field_values.survey_id.id)]
- if record_creation_field_values.field_id.ttype in ['many2one','many2many']:
- question_domain.extend(['|','&',('answer_values_type','=','record'),('model_id','=',record_creation_field_values.field_id.relation),('answer_values_type','=','value')])
- if record_creation_field_values.field_id.ttype in type_mapping:
- question_domain.append(('question_type','in',type_mapping[record_creation_field_values.field_id.ttype]))
+ question_domain = [('survey_id', '=', survey.id)]
- record_creation_field_values.allowed_question_ids = self.env['survey.question'].search(question_domain)
+ if record.field_id.ttype in ['many2one', 'many2many']:
+ question_domain.extend([
+ '|', '&',
+ ('answer_values_type', '=', 'record'),
+ ('model_id', '=', record.field_id.relation),
+ ('answer_values_type', '=', 'value'),
+ ])
+ if record.field_id.ttype in type_mapping:
+ question_domain.append(('question_type', 'in', type_mapping[record.field_id.ttype]))
+
+ questions = self.env['survey.question'].search(question_domain)
+ record.allowed_question_ids = questions
@api.model
diff --git a/survey_record_generation/views/survey_question_views.xml b/survey_record_generation/views/survey_question_views.xml
index 4795066..ffc0ce5 100644
--- a/survey_record_generation/views/survey_question_views.xml
+++ b/survey_record_generation/views/survey_question_views.xml
@@ -6,15 +6,17 @@
-
-
-
-
-
+
+
+
+
+
+
+