[IMP] survey_event_registration_generation:

New type of question : multiple event products
This commit is contained in:
clementthomas
2023-10-24 10:57:55 +02:00
parent d5a834f3c9
commit 2690d69696
6 changed files with 85 additions and 30 deletions

View File

@@ -5,7 +5,7 @@ class SurveyQuestion(models.Model):
_inherit = 'survey.question'
question_type = fields.Selection(
selection_add=[('event_product', 'Event product'),('event', 'Event')]) #event_product : List product used in tickets of visible events
selection_add=[('event_product', 'Event product'),('event', 'Event'),('multiple_event_products', 'Multiple event products')]) #event_product : List product used in tickets of visible events
#event : List events visible in surveys
@@ -13,7 +13,7 @@ class SurveyQuestion(models.Model):
'survey.question', string="Event product 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'), \
'&', ('question_type', 'in', ['event_product','multiple_event_products']), \
'|', \
('sequence', '<', sequence), \
'&', ('sequence', '=', sequence), ('id', '<', id)]") #event product question, used by event question, to filter list of events

View File

@@ -53,6 +53,8 @@ class SurveyUserInput(models.Model):
])
if question.question_type == 'event_product':
self._save_event_product(question, old_answers, answer)
elif question.question_type == 'multiple_event_products':
self._save_multiple_event_products(question, old_answers, answer)
elif question.question_type == 'event':
self._save_event(question, old_answers, answer)
else:
@@ -74,6 +76,25 @@ class SurveyUserInput(models.Model):
else:
return self.env['survey.user_input.line'].create(vals)
def _save_multiple_event_products(self, question, old_answers, answer):
"""
Save multiple event products to user_input.line
"""
vals = self._get_line_answer_values(question, answer, question.question_type)
if 'value_multiple_event_products' in vals:
if isinstance(vals['value_multiple_event_products'], str) and vals['value_multiple_event_products'].isnumeric():
vals['value_multiple_event_products'] = [int(vals['value_multiple_event_products'])]
elif type(vals['value_multiple_event_products']) == list:
vals['value_multiple_event_products'] = [int(product_id) for product_id in vals['value_multiple_event_products']]
else:
vals['value_multiple_event_products'] = None
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):
"""
Save event to user_input.line

View File

@@ -13,10 +13,11 @@ class SurveyUserInputLine(models.Model):
_inherit = 'survey.user_input.line'
answer_type = fields.Selection(
selection_add=[('event_product', 'Event product'),('event', 'Event')]) #event_product if answer is a ticket Product, event if answer is an event
selection_add=[('multiple_event_products', 'Multiple event products'), ('event_product', 'Event product'),('event', 'Event')]) #event_product if answer is a ticket Product, event if answer is an event
value_event = fields.Many2one('event.event', string="Event") #selected event
value_event_product = fields.Many2one('product.product', string="Event product") #selected product
value_multiple_event_products = fields.Many2many('product.product', string="Multiple event products") #selected products
def _compute_display_name(self):
"""display event product name, or event name, depending on answer type
@@ -25,6 +26,8 @@ class SurveyUserInputLine(models.Model):
for line in self:
if line.answer_type == 'event_product':
line.display_name = line.value_event_product.name
elif line.answer_type == 'multiple_event_products':
line.display_name = ','.join([product.name for product in line.value_multiple_event_products])
elif line.answer_type == 'event':
line.display_name = line.value_event.name