[IMP] survey_event_registration_generation: answer filter on survey question "event"

This commit is contained in:
clementthomas
2023-11-06 17:11:32 +01:00
parent 0c4b367112
commit dea7a84bd3
4 changed files with 67 additions and 48 deletions

View File

@@ -20,14 +20,33 @@ 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'].sudo().search([('detailed_type','=','event')])
next_event_question = self._get_next_event_question(answer_sudo)
if next_event_question:
event_products_ids = None
if next_event_question.event_product_question_id:
event_products_ids = self._get_answer_event_product(next_event_question.event_product_question_id, answer_sudo).id
result['events'] = request.env['event.event'].sudo().get_events_from_event_products(event_products_ids)
result['event_products'] = {}
result['events'] = {}
for question in answer_sudo.predefined_question_ids:
if question.question_type == 'event_product':
# set event products answers (by question)
if question.show_events_and_event_products_only_visible_in_survey:
result['event_products'][question.id] = request.env['product.product'].sudo().search([('detailed_type','=','event'),('visible_in_survey','=',True)])
else:
result['event_products'][question.id] = request.env['product.product'].sudo().search([('detailed_type','=','event')])
if question.question_type == 'event':
# set events answers (by question)
if question.event_answer_filter == 'all':
if question.show_events_and_event_products_only_visible_in_survey:
result['events'][question.id] = request.env['event.event'].sudo().search([('visible_in_survey','=',True)])
else:
result['events'][question.id] = request.env['event.event'].sudo().search([])
else:
if question.event_answer_filter == 'event_product':
event_products_ids = [question.event_filter_event_product_id.id]
elif question.event_answer_filter == 'event_product_question':
event_products_ids = self._get_answer_event_product(question.event_product_question_id, answer_sudo).id
result['events'][question.id] = request.env['event.event'].sudo().get_events_from_event_products(event_products_ids,
only_visible_in_survey=question.show_events_and_event_products_only_visible_in_survey)
return result
@@ -50,14 +69,3 @@ class Survey(main.Survey):
if question.question_type == 'multiple_event_products':
return user_input_line.value_multiple_event_products
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

@@ -15,6 +15,11 @@ class SurveyQuestion(models.Model):
If question display events, they are filtered with only events in step 'Visible in survey'.
If question display event products, they are filtered with only products of events in step 'Visible in survey'.""")
event_answer_filter = fields.Selection(
[('all','All events'), ('event_product_question','By event product question'), ('event_product', 'By fixed event product')],
string="Filter event answer by.. ", default='all')
event_filter_event_product_id = fields.Many2one('product.product', string="Event product", domain="[('detailed_type','=','event')]")
event_product_question_id = fields.Many2one(
'survey.question', string="Event product question", copy=False, compute="_compute_event_product_question_id",
@@ -73,3 +78,10 @@ class SurveyQuestion(models.Model):
if not question.question_type == 'event' or question.event_product_question_id is None:
question.event_product_question_id = False
@api.onchange('event_answer_filter')
def onchange_event_answer_filter(self):
if self.event_answer_filter in ('all', 'event_product_question'):
self.event_filter_event_product_id = False
if self.event_answer_filter in ('all', 'event_product'):
self.event_product_question_id = False

View File

@@ -18,9 +18,12 @@
attrs="{'invisible': [('question_type', 'not in', ['event_product', 'event', 'multiple_event_products'])]}"
/>
<!-- related event product question, to filter events, in case of event question -->
<field name="event_answer_filter" attrs="{'invisible': [('question_type','!=','event')],'required': [('question_type','=','event')]}" />
<field name="event_product_question_id" options="{'no_open': True, 'no_create': True}"
attrs="{'invisible': [('question_type','!=','event')],'required': [('question_type','=','event')]}"
attrs="{'invisible': ['|', ('event_answer_filter','!=','event_product_question'), ('question_type','!=','event')],'required': [('event_answer_filter','=','event_product_question'), ('question_type','=','event')]}"
help="Select the question asking for event product, to filter proposed events." />
<field name="event_filter_event_product_id"
attrs="{'invisible': ['|', ('event_answer_filter','!=','event_product'), ('question_type','!=','event')],'required': [('event_answer_filter','=','event_product'), ('question_type','=','event')]}" />
</xpath>
</field>

View File

@@ -22,14 +22,12 @@
t-att-placeholder="question.question_placeholder"
t-att-data-question-type="question.question_type">
<option>Please select...</option>
<t t-foreach="event_products" t-as="event_product">
<t t-if="not question.show_events_and_event_products_only_visible_in_survey or (question.show_events_and_event_products_only_visible_in_survey and event_product.visible_in_survey)">
<t t-foreach="event_products[question.id]" 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>
</t>
</select>
</div>
</template>
@@ -42,8 +40,8 @@
<t t-set="item_idx" t-value="0"/>
<div class="d-flex flex-wrap col-lg-12">
<t t-set="has_correct_answer" t-value="scoring_display_correction and any(label.is_correct for label in question.suggested_answer_ids)"/>
<t t-foreach="event_products" t-as="event_product">
<t t-if="not question.show_events_and_event_products_only_visible_in_survey or (question.show_events_and_event_products_only_visible_in_survey and event_product.visible_in_survey)">
<t t-foreach="event_products[question.id]" t-as="event_product">
<label t-att-class="'o_survey_choice_btn form-label me-2 py-1 px-3 rounded %s' % ('o_survey_selected' if answer_line else '')">
<input type="checkbox" t-att-value='event_product.id' class="o_survey_form_choice_item invisible position-absolute"
@@ -54,7 +52,7 @@
<i class="fa fa-circle-thin float-end mt-1 position-relative"></i>
</label>
</t>
</t>
</div>
</div>
@@ -67,20 +65,18 @@
<div class="o_survey_comment_container p-0">
<select class="o_survey_form_choice_item"
t-att-name="question.id"
t-att-data-event-product-question-id="question.event_product_question_id.id"
t-att-data-event-product-question-type="question.event_product_question_id.question_type"
t-att-data-event-product-question-id="question.event_answer_filter == 'event_product_question' and question.event_product_question_id.id or 0"
t-att-data-event-product-question-type="question.event_answer_filter == 'event_product_question' and question.event_product_question_id.question_type or 0"
t-att-placeholder="question.question_placeholder"
t-att-data-question-type="question.question_type"
t-att-data-only-visible-in-survey="question.show_events_and_event_products_only_visible_in_survey">
<option>Please select...</option>
<t t-foreach="events" t-as="event">
<t t-if="not question.show_events_and_event_products_only_visible_in_survey or (question.show_events_and_event_products_only_visible_in_survey and event.visible_in_survey)">
<t t-foreach="events[question.id]" 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>
</t>
</select>
</div>
</template>