1 Commits

Author SHA1 Message Date
0a4d4e8553 [IMP] survey_record_generation : make field_id of SurveyRecordCreationFieldValues required
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m31s
2025-11-14 15:44:03 +01:00
4 changed files with 10 additions and 71 deletions

View File

@@ -22,7 +22,7 @@ class SurveyRecordCreation(models.Model):
)
field_to_retrieve_existing_records = fields.Many2one(
"ir.model.fields",
domain="[('id', 'in', allowed_field_ids)]",
domain="[('id', 'in', allowed_field_ids), ('readonly', '=', False)]",
ondelete="cascade",
help="Choose the field you want to use to retrieve the existing record. "
"WARNING: We update only the first record found.",

View File

@@ -33,8 +33,10 @@ class SurveyRecordCreationFieldValues(models.Model):
field_id = fields.Many2one(
'ir.model.fields',
domain="[('model_id','=',model_id),('ttype','in',['char','selection','text','html','integer','float','date','datetime','many2one','many2many', 'boolean'])]",
ondelete="cascade")
domain="[('model_id','=',model_id),('readonly','=',False),('ttype','in',['char','selection','text','html','integer','float','date','datetime','many2one','many2many', 'boolean'])]",
ondelete="cascade",
required=True
)
field_relation = fields.Char(related='field_id.relation')
field_type = fields.Selection(related="field_id.ttype")
field_help = fields.Html('Help', compute="_compute_field_help")
@@ -82,7 +84,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']:

View File

@@ -34,7 +34,9 @@ class SurveyUserInput(models.Model):
return action
def _mark_done(self):
def _mark_done(
self, ignore_when_res_partner_mandatory_fields_are_missing: bool = False
):
# generate records
for user_input in self:
created_records = {}
@@ -82,8 +84,6 @@ class SurveyUserInput(models.Model):
try:
with self.env.cr.savepoint():
record = self.env[model].create(vals)
if model == "res.partner" and not self.partner_id:
self.partner_id = record.id
except Exception:
# This a broad exception because it could be IntegrityError,
# EmptyNamesError in case partner_firstname is installed etc...

View File

@@ -375,7 +375,7 @@ class TestSurveyRecordCreation(SurveyCase):
self.second_contact_creation = self.env["survey.record.creation"].create(
{
"name": "Contact 2",
"name": "Second contact",
"survey_id": self.survey.id,
"model_id": self.res_partner_model.id,
}
@@ -828,66 +828,3 @@ class TestSurveyRecordCreation(SurveyCase):
# No partner has been created, and no IntegrityError has been raised
partner = self.env["res.partner"].search([("name", "=", "Jean")])
self.assertEqual(len(partner), 0)
def test_fill_up_partner_id_in_survey_input(self):
# In this test, we check that the field partner_id is filled up
# when we create a res.partner
self.answer = self._add_answer(
survey=self.survey, partner=False, email="jean@test.fr"
)
self._add_answer_line(
question=self.question_name, answer=self.answer, answer_value="Jean"
)
self.answer._mark_done()
partner = self.env["res.partner"].search([("name", "=", "Jean")])
self.assertEqual(self.answer.partner_id, partner)
def test_partner_id_in_survey_input_is_filled_up_by_first_contact_record_creation(self):
# In this test, we verify that when creating several contacts with the same survey,
# the 1st created contact is used to fill up survey_input.partner_id
self.second_question_name = self._add_question(
page=None,
name="Name of second person",
qtype="char_box",
survey_id=self.survey.id,
sequence=1,
)
self.second_contact_creation = self.env["survey.record.creation"].create(
{
"name": "Contact 2",
"survey_id": self.survey.id,
"model_id": self.res_partner_model.id,
}
)
self.env["survey.record.creation.field.values"].create(
{
"survey_record_creation_id": self.second_contact_creation.id,
"survey_id": self.survey.id,
"model_id": self.res_partner_model.id,
"field_id": self.name_field.id,
"value_origin": "question",
"question_id": self.second_question_name.id,
}
)
self.answer = self._add_answer(
survey=self.survey, partner=False, email="jean@test.fr"
)
self._add_answer_line(
question=self.question_name,
answer=self.answer,
answer_value="Jean",
)
self._add_answer_line(
question=self.second_question_name,
answer=self.answer,
answer_value="Jeanne",
)
self.answer._mark_done()
partner = self.env["res.partner"].search([("name", "=", "Jean")])
self.assertEqual(self.answer.partner_id, partner)