[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:
@@ -11,7 +11,7 @@ Allow to create record of any model when sending the form :
|
|||||||
* Associate question with fields
|
* Associate question with fields
|
||||||
* For x2m fields : Associate values to questions
|
* For x2m fields : Associate values to questions
|
||||||
""",
|
""",
|
||||||
"version": "18.0.1.0.0",
|
"version": "18.0.1.0.1",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://www.elabore.coop",
|
"website": "https://www.elabore.coop",
|
||||||
|
|||||||
@@ -32,8 +32,9 @@ class SurveyQuestion(models.Model):
|
|||||||
|
|
||||||
def fill(self):
|
def fill(self):
|
||||||
for question in self:
|
for question in self:
|
||||||
if question.model_id:
|
if question.suggested_answer_ids:
|
||||||
new_suggested_answer_ids = [Command.clear()]
|
question.suggested_answer_ids = [Command.clear()]
|
||||||
|
elif question.model_id:
|
||||||
record_model = question.model_id.model
|
record_model = question.model_id.model
|
||||||
|
|
||||||
if question.fill_domain:
|
if question.fill_domain:
|
||||||
@@ -43,7 +44,11 @@ class SurveyQuestion(models.Model):
|
|||||||
|
|
||||||
records = self.env[record_model].search(domain)
|
records = self.env[record_model].search(domain)
|
||||||
|
|
||||||
new_suggested_answer_ids += [Command.create({'value':record.display_name, 'record_id':f"{record_model},{record.id}"
|
question.suggested_answer_ids = [
|
||||||
}) for record in records]
|
Command.create({
|
||||||
question.suggested_answer_ids = new_suggested_answer_ids
|
'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.exceptions import UserError
|
||||||
from odoo.tools.misc import format_date
|
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 ?
|
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"],
|
"char": ["char_box", "numerical_box", "date", "datetime", "simple_choice", "multiple_choice"],
|
||||||
"text": ["char_box", "date", "simple_choice"],
|
"text": ["char_box", "date", "simple_choice"],
|
||||||
@@ -78,20 +75,28 @@ class SurveyRecordCreationFieldValues(models.Model):
|
|||||||
record.field_help = field_help
|
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):
|
def _compute_allowed_question_ids(self):
|
||||||
for record_creation_field_values in self:
|
for record in self:
|
||||||
if not record_creation_field_values.survey_id or not record_creation_field_values.field_id:
|
survey = record.survey_id or record.survey_record_creation_id.survey_id
|
||||||
record_creation_field_values.allowed_question_ids = None
|
if not survey or not record.field_id:
|
||||||
|
record.allowed_question_ids = False
|
||||||
continue
|
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 = [('survey_id', '=', survey.id)]
|
||||||
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]))
|
|
||||||
|
|
||||||
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
|
@api.model
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<field name="inherit_id" ref="survey.survey_question_form" />
|
<field name="inherit_id" ref="survey.survey_question_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='suggested_answer_ids']" position="before">
|
<xpath expr="//field[@name='suggested_answer_ids']" position="before">
|
||||||
|
<group invisible="question_type not in ['simple_choice', 'multiple_choice', 'matrix']">
|
||||||
<field name="answer_values_type" />
|
<field name="answer_values_type" />
|
||||||
<field name="model_id" invisible="answer_values_type != 'record'" />
|
<field name="model_id" invisible="answer_values_type != 'record'" />
|
||||||
<field name="model_name" invisible="1" />
|
<field name="model_name" invisible="1" />
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
colspan="2"
|
colspan="2"
|
||||||
help="Empty the list and fill it with all items of selected model matching domain"
|
help="Empty the list and fill it with all items of selected model matching domain"
|
||||||
invisible="answer_values_type != 'record'" />
|
invisible="answer_values_type != 'record'" />
|
||||||
|
</group>
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//field[@name='suggested_answer_ids']" position="attributes">
|
<xpath expr="//field[@name='suggested_answer_ids']" position="attributes">
|
||||||
<attribute
|
<attribute
|
||||||
|
|||||||
Reference in New Issue
Block a user