[IMP] survey_event_registration_generation: answer filter on survey question "event"
This commit is contained in:
@@ -18,16 +18,35 @@ class Survey(main.Survey):
|
||||
return [{'id':event.id,'name':event.name} for event in events]
|
||||
|
||||
|
||||
def _prepare_survey_data(self, survey_sudo, answer_sudo, **post):
|
||||
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
|
||||
|
@@ -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
|
||||
|
@@ -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>
|
||||
|
@@ -22,13 +22,11 @@
|
||||
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)">
|
||||
<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 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>
|
||||
</select>
|
||||
</div>
|
||||
@@ -42,19 +40,19 @@
|
||||
<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)">
|
||||
<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"
|
||||
t-att-name="question.id" t-att-data-question-type="question.question_type" />
|
||||
<span class="ms-2 text-break" t-field='event_product.name'/>
|
||||
<t t-foreach="event_products[question.id]" t-as="event_product">
|
||||
|
||||
<i class="fa fa-check-circle float-end mt-1 position-relative"></i>
|
||||
<i class="fa fa-circle-thin float-end mt-1 position-relative"></i>
|
||||
|
||||
</label>
|
||||
</t>
|
||||
<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"
|
||||
t-att-name="question.id" t-att-data-question-type="question.question_type" />
|
||||
<span class="ms-2 text-break" t-field='event_product.name'/>
|
||||
|
||||
<i class="fa fa-check-circle float-end mt-1 position-relative"></i>
|
||||
<i class="fa fa-circle-thin float-end mt-1 position-relative"></i>
|
||||
|
||||
</label>
|
||||
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
@@ -67,19 +65,17 @@
|
||||
<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)">
|
||||
<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 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>
|
||||
</select>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user