[ADD]urvey_record_generation: manage the case where the other record is a mandatory field
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": "16.0.1.0.0",
|
"version": "16.0.1.0.1",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "Elabore",
|
"author": "Elabore",
|
||||||
"website": "https://www.elabore.coop",
|
"website": "https://www.elabore.coop",
|
||||||
|
@@ -349,6 +349,17 @@ msgstr "Entrée utilisateur du sondage"
|
|||||||
msgid "Survey record creation"
|
msgid "Survey record creation"
|
||||||
msgstr "Génération d'enregistrement depuis la participation"
|
msgstr "Génération d'enregistrement depuis la participation"
|
||||||
|
|
||||||
|
#. module: survey_record_generation
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/survey_record_generation/models/survey_user_input.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid ""
|
||||||
|
"The field %s is mandatory. In Record Creation tab, drag "
|
||||||
|
"%s at the top of the table"
|
||||||
|
msgstr ""
|
||||||
|
"Le champ %s est obligatoire. Dans l'onglet Création d'un enregistrement, glissez "
|
||||||
|
"%s sur la première ligne du tableau"
|
||||||
|
|
||||||
#. module: survey_record_generation
|
#. module: survey_record_generation
|
||||||
#: model:ir.model.fields,field_description:survey_record_generation.field_survey_record_creation_field_values__unicity_check
|
#: model:ir.model.fields,field_description:survey_record_generation.field_survey_record_creation_field_values__unicity_check
|
||||||
msgid "Unicity constraint"
|
msgid "Unicity constraint"
|
||||||
@@ -397,6 +408,11 @@ msgstr "Vous devez au moins ajouter un enregistrement dans %s"
|
|||||||
msgid "possible values are %s"
|
msgid "possible values are %s"
|
||||||
msgstr "les valeurs possibles sont %s"
|
msgstr "les valeurs possibles sont %s"
|
||||||
|
|
||||||
|
#. module: survey_record_generation
|
||||||
|
#: model:ir.model.fields,field_description:survey_record_generation.field_survey_record_creation__sequence
|
||||||
|
msgid "sequence"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#. module: survey_record_generation
|
#. module: survey_record_generation
|
||||||
#: model:ir.model,name:survey_record_generation.model_survey_generated_record
|
#: model:ir.model,name:survey_record_generation.model_survey_generated_record
|
||||||
msgid "survey.generated.record"
|
msgid "survey.generated.record"
|
||||||
|
@@ -16,6 +16,7 @@ class SurveyRecordCreation(models.Model):
|
|||||||
model_id = fields.Many2one('ir.model', "Model", help="Model of generated record")
|
model_id = fields.Many2one('ir.model', "Model", help="Model of generated record")
|
||||||
field_values_ids = fields.One2many('survey.record.creation.field.values', 'survey_record_creation_id', string="Field values")
|
field_values_ids = fields.One2many('survey.record.creation.field.values', 'survey_record_creation_id', string="Field values")
|
||||||
warning_message = fields.Html('Warning message', compute="_compute_warning_message")
|
warning_message = fields.Html('Warning message', compute="_compute_warning_message")
|
||||||
|
sequence = fields.Integer("sequence")
|
||||||
|
|
||||||
@api.onchange('model_id')
|
@api.onchange('model_id')
|
||||||
def clear_field_values_ids(self):
|
def clear_field_values_ids(self):
|
||||||
|
@@ -113,7 +113,7 @@ class SurveyRecordCreationFieldValues(models.Model):
|
|||||||
|
|
||||||
@api.onchange('field_id')
|
@api.onchange('field_id')
|
||||||
def _onchange_field_id(self):
|
def _onchange_field_id(self):
|
||||||
# clean values
|
# clean values
|
||||||
self.clean_values()
|
self.clean_values()
|
||||||
# Set reference field model and select first record
|
# Set reference field model and select first record
|
||||||
if self.field_id and self.field_id.ttype == 'many2one' and self.field_id.relation:
|
if self.field_id and self.field_id.ttype == 'many2one' and self.field_id.relation:
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
from odoo import models, fields
|
from odoo import models, fields, _
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
|
||||||
|
|
||||||
class SurveyUserInput(models.Model):
|
class SurveyUserInput(models.Model):
|
||||||
@@ -37,9 +38,10 @@ class SurveyUserInput(models.Model):
|
|||||||
created_records = {}
|
created_records = {}
|
||||||
fields_to_update = []
|
fields_to_update = []
|
||||||
|
|
||||||
for record_creation in user_input.survey_id.survey_record_creation_ids:
|
for record_creation in user_input.survey_id.survey_record_creation_ids.sorted('sequence'):
|
||||||
model = record_creation.model_id.model
|
model = record_creation.model_id.model
|
||||||
vals = {}
|
vals = {}
|
||||||
|
ModelClass = self.env[model]
|
||||||
|
|
||||||
for field_value in record_creation.field_values_ids:
|
for field_value in record_creation.field_values_ids:
|
||||||
if field_value.value_origin == 'fixed':
|
if field_value.value_origin == 'fixed':
|
||||||
@@ -69,7 +71,17 @@ class SurveyUserInput(models.Model):
|
|||||||
vals[field_value.field_id.name] = None
|
vals[field_value.field_id.name] = None
|
||||||
elif field_value.value_origin == 'other_record':
|
elif field_value.value_origin == 'other_record':
|
||||||
fields_to_update.append(field_value)
|
fields_to_update.append(field_value)
|
||||||
|
# check if the field to update is mandatory
|
||||||
|
if ModelClass._fields[field_value.field_id.name].required:
|
||||||
|
# check if the other record is already created, if yes add it to vals
|
||||||
|
if len(created_records) > 0 and created_records[field_value.other_created_record_id.id]:
|
||||||
|
linked_record = created_records[field_value.other_created_record_id.id]
|
||||||
|
vals[field_value.field_id.name] = linked_record.id
|
||||||
|
else:
|
||||||
|
raise UserError(
|
||||||
|
_("The field %s is mandatory. In Record Creation tab, drag %s at the top of the table")
|
||||||
|
% (field_value.field_id.display_name, field_value.other_created_record_id.name)
|
||||||
|
)
|
||||||
# check duplicates
|
# check duplicates
|
||||||
uniq_fields = [field_value.field_id.name for field_value in record_creation.field_values_ids.filtered(lambda r:r.unicity_check)]
|
uniq_fields = [field_value.field_id.name for field_value in record_creation.field_values_ids.filtered(lambda r:r.unicity_check)]
|
||||||
duplicate = None
|
duplicate = None
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
<page name="record_creation" string="Record creation">
|
<page name="record_creation" string="Record creation">
|
||||||
<field name="survey_record_creation_ids">
|
<field name="survey_record_creation_ids">
|
||||||
<tree>
|
<tree>
|
||||||
|
<field name="sequence" widget="handle"/>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
<field name="model_id" />
|
<field name="model_id" />
|
||||||
</tree>
|
</tree>
|
||||||
|
Reference in New Issue
Block a user