From a47ac870c18f758edc362c89698da1d30595373e Mon Sep 17 00:00:00 2001 From: clementthomas Date: Tue, 21 Nov 2023 13:49:58 +0100 Subject: [PATCH] [IMP] survey_event_speaker_generation: * take events from new filed in survey_base --- .../__manifest__.py | 2 +- .../models/survey_user_input.py | 28 ++++++++----------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/survey_event_speaker_generation/__manifest__.py b/survey_event_speaker_generation/__manifest__.py index ae11061..361fab1 100644 --- a/survey_event_speaker_generation/__manifest__.py +++ b/survey_event_speaker_generation/__manifest__.py @@ -9,7 +9,7 @@ "author": "Elabore", "website": "https://www.elabore.coop", "category": "", - "depends": ["survey", "event_speaker"], + "depends": ["survey", "survey_event_base", "event_speaker"], "data": [ 'views/mail_templates_chatter.xml', 'views/survey_survey_views.xml', diff --git a/survey_event_speaker_generation/models/survey_user_input.py b/survey_event_speaker_generation/models/survey_user_input.py index 356f0d7..aa41c97 100644 --- a/survey_event_speaker_generation/models/survey_user_input.py +++ b/survey_event_speaker_generation/models/survey_user_input.py @@ -17,30 +17,24 @@ class SurveyUserInput(models.Model): speaker_id = fields.Many2one('res.partner', 'Event speaker') #created partner when submit survey - def _get_event(self): - """Find event selected, in all answers""" - for line in self.user_input_line_ids: - if line.question_id.question_type == 'event' and not line.skipped \ - and line.answer_type != "suggestion" \ - and line.question_id.event_registration_field.name != "comment": - return line.value_event - def _create_speaker_post_process(self, speaker): - """Add message to chatter to note speaker creation and association with event""" - speaker.message_post_with_view( - "survey_event_speaker_generation.message_event_speaker_assigned", - values={"speaker": speaker, "user_input": self, "event":self._get_event()}, - subtype_id=self.env.ref("mail.mt_note").id, - ) + for event in self.events_ids: + """Add message to chatter to note speaker creation and association with event""" + speaker.message_post_with_view( + "survey_event_speaker_generation.message_event_speaker_assigned", + values={"speaker": speaker, "user_input": self, "event":event}, + subtype_id=self.env.ref("mail.mt_note").id, + ) def _mark_done(self): """Attach partner as speaker of event""" - res = super()._mark_done() - for user_input in self.filtered(lambda r: r.survey_id.generate_speaker and not r.speaker_id and r.partner_id): + for user_input in self.filtered(lambda r: r.survey_id.generate_speaker and not r.speaker_id and r.partner_id): user_input.update({"speaker_id": user_input.partner_id.id}) - user_input._get_event().speakers = [Command.link(user_input.speaker_id.id)] + for event in user_input.events_ids: + event.speakers = [Command.link(user_input.speaker_id.id)] user_input._create_speaker_post_process(user_input.speaker_id) + return res