From b2a64d2574fbadcd5ce452854ddd650073ec87ed Mon Sep 17 00:00:00 2001 From: clementthomas Date: Mon, 18 Sep 2023 17:41:26 +0200 Subject: [PATCH] [IMP] survey_event_generation: manage case when old registration already exists --- .../models/survey_user_input.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/survey_event_registration_generation/models/survey_user_input.py b/survey_event_registration_generation/models/survey_user_input.py index e89dfed..fa35262 100644 --- a/survey_event_registration_generation/models/survey_user_input.py +++ b/survey_event_registration_generation/models/survey_user_input.py @@ -121,9 +121,28 @@ class SurveyUserInput(models.Model): lambda r: r.survey_id.generate_registration and not self.registration_id ): vals = user_input._prepare_registration() - - registration = self.env["event.registration"].create(vals) - self._create_registration_post_process(registration) + + # check doublon : if old draft registration already exists : update it + email = vals.get('email') + event_id = vals.get('event_id') + old_registration = False + if email and event_id: + old_registration = self.env["event.registration"].search([('email','=',email),('event_id','=',event_id)]) + if old_registration: + old_registration = old_registration[0] + if old_registration.state == 'draft': + registration = old_registration + registration.write(vals) + registration.message_post_with_view( + "mail.message_origin_link", + values={"edit":True, "self": registration, "origin": self.survey_id}, + subtype_id=self.env.ref("mail.mt_note").id, + ) + + if not old_registration: + registration = self.env["event.registration"].create(vals) + self._create_registration_post_process(registration) + self.update({"registration_id": registration.id}) res = super()._mark_done()