[ADD] survey_event_speaker_generation

This commit is contained in:
clementthomas
2023-09-19 15:28:26 +02:00
parent d8b820902a
commit affaf785ee
7 changed files with 112 additions and 0 deletions

View File

@@ -0,0 +1 @@
from . import models

View File

@@ -0,0 +1,18 @@
# Copyright 2016-2020 Akretion France (<https://www.akretion.com>)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Survey event speaker generation",
"version": "16.0.0.0.0",
"license": "AGPL-3",
"author": "Elabore",
"website": "https://www.elabore.coop",
"category": "",
"depends": ["survey", "event_speaker"],
"data": [
'views/mail_templates_chatter.xml',
'views/survey_survey_views.xml',
],
"installable": True,
}

View File

@@ -0,0 +1,2 @@
from . import survey_user_input
from . import survey_survey

View File

@@ -0,0 +1,11 @@
# Copyright 2023 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class SurveySurvey(models.Model):
_inherit = "survey.survey"
generate_speaker = fields.Boolean(
help="Generate speaker for selected event",
)

View File

@@ -0,0 +1,44 @@
import logging
import textwrap
import uuid
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _, Command
from odoo.exceptions import ValidationError
from odoo.tools import float_is_zero
_logger = logging.getLogger(__name__)
class SurveyUserInput(models.Model):
_inherit = 'survey.user_input'
speaker_id = fields.Many2one('res.partner', 'Event speaker')
def _get_event(self):
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):
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,
)
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):
user_input.update({"speaker_id": user_input.partner_id.id})
user_input._get_event().speakers = [Command.link(user_input.speaker_id.id)]
user_input._create_speaker_post_process(user_input.speaker_id)
return res

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="message_event_speaker_assigned">
<div style="margin: 0px; padding: 0px; font-size: 13px;">
<a href="#" t-att-data-oe-model="speaker._name" t-att-data-oe-id="speaker.id">
<t t-esc="speaker.name" />
</a>
has been assigned as speaker to
<a href="#" t-att-data-oe-model="event._name" t-att-data-oe-id="event.id">
<t t-esc="event.display_name" />
</a>
from survey answers
<a href="#" t-att-data-oe-model="user_input._name" t-att-data-oe-id="user_input.id">
<t t-esc="user_input.display_name" />
</a>
</div>
</template>
</data>
</odoo>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="survey_form" model="ir.ui.view">
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_survey_view_form" />
<field name="arch" type="xml">
<group name="options" position="inside">
<group name="event_options" string="Event">
<field name="generate_speaker" />
</group>
</group>
</field>
</record>
</odoo>