[ADD] survey_contact_generation, survey_event_registration_generation

This commit is contained in:
clementthomas
2023-09-12 20:35:16 +02:00
parent 1897ac5a6e
commit 4baaad2054
32 changed files with 1477 additions and 0 deletions

View File

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

View File

@@ -0,0 +1,23 @@
# 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 registration generation",
"version": "16.0.0.0.0",
"license": "AGPL-3",
"author": "Elabore",
"website": "https://www.elabore.coop",
"category": "",
"depends": ["survey"],
"data": [
'views/survey_question_views.xml',
'views/survey_templates.xml'
],
'assets': {
'survey.survey_assets': [
'/survey_event_registration_generation/static/src/js/survey_form.js',
],
},
"installable": True,
}

View File

@@ -0,0 +1,4 @@
# -*- encoding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import main

View File

@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.survey.controllers import main
from odoo.http import request
class Survey(main.Survey):
def _prepare_survey_data(self, survey_sudo, answer_sudo, **post):
result = super(Survey, self)._prepare_survey_data(survey_sudo, answer_sudo, **post)
result['event_products'] = request.env['product.product'].search([('detailed_type','=','event')])
next_event_question = self._get_next_event_question(answer_sudo)
if next_event_question:
event_product = None
if next_event_question.event_product_question_id:
event_product = self._get_answer_event_product(next_event_question.event_product_question_id, answer_sudo)
if event_product:
event_tickets = request.env['event.event.ticket'].search([('product_id','=',event_product.id)])
result['events'] = event_tickets.event_id
else:
result['events'] = request.env['event.event'].search([])
return result
def _get_answer_event_product(self, question, answer_sudo):
for user_input_line in answer_sudo.user_input_line_ids:
if user_input_line.question_id == question:
return user_input_line.value_event_product
def _get_next_event_question(self, answer_sudo):
future_question = False
for question in answer_sudo.predefined_question_ids:
if question == answer_sudo.last_displayed_page_id:
future_question = True
continue
if not future_question:
continue
if question.question_type == 'event':
return question

View File

@@ -0,0 +1,3 @@
from . import survey_question
from . import survey_user_input
from . import survey_user_input_line

View File

@@ -0,0 +1,28 @@
from odoo import models, fields, api
class SurveyQuestion(models.Model):
_inherit = 'survey.question'
question_type = fields.Selection(
selection_add=[('event_product', 'Event product'),('event', 'Event')])
event_product_question_id = fields.Many2one(
'survey.question', string="Event ticket question", copy=False, compute="_compute_event_product_question_id",
store=True, readonly=False, help="If you specify question of event product, only events of selected product will be proposed.",
domain="[('survey_id', '=', survey_id), \
'&', ('question_type', '=', 'event_product'), \
'|', \
('sequence', '<', sequence), \
'&', ('sequence', '=', sequence), ('id', '<', id)]")
@api.depends('question_type')
def _compute_event_product_question_id(self):
""" Used as an 'onchange' : Reset the event ticket question if user change question type
Avoid CacheMiss : set the value to False if the value is not set yet."""
for question in self:
if not question.question_type == 'event' or question.triggering_question_id is None:
question.triggering_question_id = False

View File

@@ -0,0 +1,47 @@
import logging
import textwrap
import uuid
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
from odoo.tools import float_is_zero
_logger = logging.getLogger(__name__)
class SurveyUserInput(models.Model):
_inherit = 'survey.user_input'
def save_lines(self, question, answer, comment=None):
old_answers = self.env['survey.user_input.line'].search([
('user_input_id', '=', self.id),
('question_id', '=', question.id)
])
if question.question_type == 'event_product':
self._save_event_product(question, old_answers, answer)
elif question.question_type == 'event':
self._save_event(question, old_answers, answer)
else:
return super().save_lines(question, answer, comment)
def _save_event_product(self, question, old_answers, answer):
vals = self._get_line_answer_values(question, answer, question.question_type)
vals['value_event_product'] = int(vals['value_event_product'])
if old_answers:
old_answers.write(vals)
return old_answers
else:
return self.env['survey.user_input.line'].create(vals)
def _save_event(self, question, old_answers, answer):
vals = self._get_line_answer_values(question, answer, question.question_type)
vals['value_event'] = int(vals['value_event'])
if old_answers:
old_answers.write(vals)
return old_answers
else:
return self.env['survey.user_input.line'].create(vals)

View File

@@ -0,0 +1,28 @@
import logging
import textwrap
import uuid
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
from odoo.tools import float_is_zero
class SurveyUserInputLine(models.Model):
_inherit = 'survey.user_input.line'
answer_type = fields.Selection(
selection_add=[('event_product', 'Event product'),('event', 'Event')])
value_event = fields.Many2one('event.event', string="Event")
value_event_product = fields.Many2one('product.product', string="Event product")
def _compute_display_name(self):
super()._compute_display_name()
for line in self:
if line.answer_type == 'event_product':
line.display_name = line.value_event_product.name
elif line.answer_type == 'event':
line.display_name = line.value_event.name

View File

@@ -0,0 +1,24 @@
odoo.define('survey_event_registration_generation.survey.form', function (require) {
'use strict';
var SurveyFormWidget = require('survey.form');
SurveyFormWidget.include({
_prepareSubmitValues: function (formData, params) {
var self = this;
var result = this._super.apply(this, arguments);
this.$('[data-question-type]').each(function () {
if (['event','event_product'].includes($(this).data('questionType'))) {
params[this.name] = this.value;
}
});
return result;
},
})
});

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="survey_question_form" model="ir.ui.view">
<field name="model">survey.question</field>
<field name="inherit_id" ref="survey.survey_question_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='comments_allowed']/.." position="after">
<group name="event_registration" string="Event registration">
<field name="event_product_question_id" options="{'no_open': True, 'no_create': True}"
attrs="{'invisible': [('question_type','!=','event')]}" />
<!-- <field name="allowed_field_ids" invisible="1" /> -->
</group>
</xpath>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,43 @@
<odoo>
<template id="question_container" name="survey_event_registration_generation question container" inherit_id="survey.question_container">
<xpath expr="//div[@role='alert']" position="before">
<t t-if="question.question_type == 'event_product'"><t t-call="survey_event_registration_generation.question_event_product" /></t>
<t t-if="question.question_type == 'event'"><t t-call="survey_event_registration_generation.question_event" /></t>
</xpath>
</template>
<template id="survey_page_print" name="survey_event_registration_generation print page" inherit_id="survey.survey_page_print">
<xpath expr="//div[@role='alert']" position="before">
<t t-if="question.question_type == 'event_product'"><t t-call="survey_event_registration_generation.question_event_product"/></t>
<t t-if="question.question_type == 'event'"><t t-call="survey_event_registration_generation.question_event" /></t>
</xpath>
</template>
<template id="question_event_product" name="Question: event product">
<div class="o_survey_comment_container p-0">
<select t-att-name="question.id" t-att-placeholder="question.question_placeholder" t-att-data-question-type="question.question_type">
<t t-foreach="event_products" t-as="event_product">
<option
t-att-value="event_product.id"
t-att-selected="answer_lines and (answer_lines[0].value_event_product.id == event_product.id)">
<t t-esc="event_product.name"/></option>
</t>
</select>
</div>
</template>
<template id="question_event" name="Question: event">
<div class="o_survey_comment_container p-0">
<select t-att-name="question.id" t-att-placeholder="question.question_placeholder" t-att-data-question-type="question.question_type">
<t t-foreach="events" t-as="event">
<option
t-att-value="event.id"
t-att-selected="answer_lines and (answer_lines[0].value_event.id == event.id)">
<t t-esc="event.name"/></option>
</t>
</select>
</div>
</template>
</odoo>

View File

@@ -0,0 +1,17 @@
<odoo>
<!-- Inherit Form View -->
<record id="survey_event_registration_generation_inherit_survey_user_input_line_form"
model="ir.ui.view">
<field name="name">user.input.value.event.product</field>
<field name="model">survey.user_input.line</field>
<field name="inherit_id" ref="survey.survey_user_input_line_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='answer_type']" position="after">
<field name="value_event"/>
<field name="value_event_product" />
</xpath>
</field>
</record>
</odoo>