[FIX]survey_record_generation
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m34s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m34s
This commit is contained in:
@@ -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
|
||||
]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user