[IMP] survey_event_registration_generation: manage multiple training products fields in survey

This commit is contained in:
clementthomas
2023-10-31 12:10:12 +01:00
parent 7bc095e265
commit 0c4b367112
9 changed files with 172 additions and 68 deletions

View File

@@ -4,18 +4,27 @@ from odoo import models, fields, api
class EventEvent(models.Model):
_inherit = 'event.event'
def get_events_visible_in_survey(self, product_id=None):
"""Search events in stage visible in survey.
Optionnaly filtered by product present in ticket.
visible_in_survey = fields.Boolean('Visible in survey', related='stage_id.visible_in_survey', readonly=True,
help="""Events in step configured as 'visible in survey'.""")
def get_events_from_event_products(self, product_ids=None, only_visible_in_survey=False):
"""Search events in stage filtered by product present in ticket..
Args:
product_id (product.product, optional): to filter only events with tickets using this product. Defaults to None.
product_ids (list[product.product ids], optional): to filter only events with tickets using product in this list. Defaults to None.
Returns:
event.event: Events
"""
if product_id:
event_tickets = self.env['event.event.ticket'].search([('product_id','=',product_id)])
return self.env['event.event'].search([('stage_id.visible_in_survey','=',True),('event_ticket_ids','in',event_tickets.id)])
return self.env['event.event'].search([('stage_id.visible_in_survey','=',True)])
event_search = []
if product_ids:
event_tickets = self.env['event.event.ticket'].search([('product_id','in',product_ids)])
event_search.append(('event_ticket_ids','in',event_tickets.ids))
if only_visible_in_survey:
event_search.append(('visible_in_survey','=',True))
return self.env['event.event'].search(event_search)

View File

@@ -4,15 +4,20 @@ from odoo import models, fields, api
class ProductProduct(models.Model):
_inherit = 'product.product'
def get_event_products_visible_in_survey(self):
"""Search products used in tickets of events visibles in surveys
visible_in_survey = fields.Boolean('Visible in survey', compute='_compute_visible_in_survey', readonly=True,
help="""Events in step configured as 'visible in survey'.""")
Returns:
product.product: products
"""
events = self.env['event.event'].get_events_visible_in_survey()
products = set()
def _compute_visible_in_survey(self):
#get all events in step 'visible in survey'
product_ids = set()
events = self.env['event.event'].search([('visible_in_survey','=',True)])
for event in events:
for ticket in event.event_ticket_ids:
products.add(ticket.product_id)
return list(products)
product_ids.add(ticket.product_id.id)
for event_product in self:
if event_product.id in product_ids:
event_product.visible_in_survey = True
else:
event_product.visible_in_survey = False

View File

@@ -1,3 +1,4 @@
from email.policy import default
from odoo import models, fields, api
@@ -7,6 +8,12 @@ class SurveyQuestion(models.Model):
question_type = fields.Selection(
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
show_events_and_event_products_only_visible_in_survey = fields.Boolean('Show events or event products in step visible in survey',
help="""In event step configuration, you can check 'Visible in surveys'.
If this option is checked,
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_product_question_id = fields.Many2one(

View File

@@ -19,7 +19,7 @@ class SurveyUserInput(models.Model):
event_id = fields.Many2one('event.event', 'Event', compute='compute_event_id', store=True) #related event - answer of "event" question
event_product_id = fields.Many2one('product.product', 'Event product', compute='compute_event_product_id', store=True) #related event product - answer of "event product" question
event_products_ids = fields.Many2many('product.product', string='Event products', compute='compute_event_products_ids', store=True) #related event products - answer of "event product" or "multiple event product" question
@api.depends('user_input_line_ids')
def compute_event_id(self):
@@ -32,13 +32,16 @@ class SurveyUserInput(models.Model):
break
@api.depends('user_input_line_ids')
def compute_event_product_id(self):
"""set event_product_id as answer of "event product" question
def compute_event_products_ids(self):
"""set event_products_ids as answer of "event product" or "multiple event products" question
"""
for user_input in self:
for user_input_line in user_input.user_input_line_ids:
if user_input_line.answer_type == 'event_product':
user_input.event_product_id = user_input_line.value_event_product
user_input.event_products_ids = [user_input_line.value_event_product.id]
break
if user_input_line.answer_type == 'multiple_event_products':
user_input.event_products_ids = user_input_line.value_multiple_event_products
break
def save_lines(self, question, answer, comment=None):