diff --git a/event_speaker/views/event_event_views.xml b/event_speaker/views/event_event_views.xml index 6fa5958..85f3af4 100644 --- a/event_speaker/views/event_event_views.xml +++ b/event_speaker/views/event_event_views.xml @@ -1,5 +1,6 @@ + event.event.form.event.speaker event.event diff --git a/survey_event_registration_generation/models/event_event.py b/survey_event_registration_generation/models/event_event.py index a17c27d..56c53e8 100644 --- a/survey_event_registration_generation/models/event_event.py +++ b/survey_event_registration_generation/models/event_event.py @@ -4,7 +4,16 @@ from odoo import models, fields, api class EventEvent(models.Model): _inherit = 'event.event' - def get_events_visible_in_survey(self, product_id=False): + def get_events_visible_in_survey(self, product_id=None): + """Search events in stage visible in survey. + Optionnaly filtered by product present in ticket. + + Args: + product_id (product.product, optional): to filter only events with tickets using this product. 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)]) diff --git a/survey_event_registration_generation/models/event_stage.py b/survey_event_registration_generation/models/event_stage.py index b5dae9a..68f5c9c 100644 --- a/survey_event_registration_generation/models/event_stage.py +++ b/survey_event_registration_generation/models/event_stage.py @@ -4,4 +4,4 @@ from odoo import models, fields, api class EventStage(models.Model): _inherit = 'event.stage' - visible_in_survey = fields.Boolean('Visible in surveys') \ No newline at end of file + visible_in_survey = fields.Boolean('Visible in surveys') #if checked, only events on this stage are visible in surveys \ No newline at end of file diff --git a/survey_event_registration_generation/models/product_product.py b/survey_event_registration_generation/models/product_product.py index 0d6510d..56e709c 100644 --- a/survey_event_registration_generation/models/product_product.py +++ b/survey_event_registration_generation/models/product_product.py @@ -5,6 +5,11 @@ 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 + + Returns: + product.product: products + """ events = self.env['event.event'].get_events_visible_in_survey() products = set() for event in events: diff --git a/survey_event_registration_generation/models/survey_question.py b/survey_event_registration_generation/models/survey_question.py index 8e90af2..03cad8a 100644 --- a/survey_event_registration_generation/models/survey_question.py +++ b/survey_event_registration_generation/models/survey_question.py @@ -5,8 +5,9 @@ class SurveyQuestion(models.Model): _inherit = 'survey.question' question_type = fields.Selection( - selection_add=[('event_product', 'Event product'),('event', 'Event')]) - + selection_add=[('event_product', 'Event product'),('event', 'Event')]) #event_product : List product used in tickets of visible events + #event : List events visible in surveys + event_product_question_id = fields.Many2one( 'survey.question', string="Event product question", copy=False, compute="_compute_event_product_question_id", @@ -15,20 +16,22 @@ class SurveyQuestion(models.Model): '&', ('question_type', '=', 'event_product'), \ '|', \ ('sequence', '<', sequence), \ - '&', ('sequence', '=', sequence), ('id', '<', id)]") + '&', ('sequence', '=', sequence), ('id', '<', id)]") #event product question, used by event question, to filter list of events event_registration_allowed_field_ids = fields.Many2many( comodel_name="ir.model.fields", compute="_compute_event_registration_allowed_field_ids", - ) + ) #fields of event registration, proposed in question, to associate answer to good event registration field, during event registration creation event_registration_field = fields.Many2one( string="Event registration field", comodel_name="ir.model.fields", domain="[('id', 'in', event_registration_allowed_field_ids)]", - ) + ) #field of event registration selected, used in event registration creation @api.depends("question_type") def _compute_event_registration_allowed_field_ids(self): + """propose all event registration fields corresponding to selected question type + """ type_mapping = { "char_box": ["char", "text"], "text_box": ["html"], @@ -40,28 +43,21 @@ class SurveyQuestion(models.Model): } for record in self: if record.question_type == "event": - record.event_registration_allowed_field_ids = ( - self.env["ir.model.fields"] - .search( + record.event_registration_allowed_field_ids = self.env["ir.model.fields"].search( [ ("model", "=", "event.registration"), ("name", "=", "event_id"), ] - ) - .ids - ) - record.event_registration_allowed_field_ids = ( - self.env["ir.model.fields"] - .search( + ).ids + + record.event_registration_allowed_field_ids = self.env["ir.model.fields"].search( [ ("model", "=", "event.registration"), ("ttype", "in", type_mapping.get(record.question_type, [])), ] - ) - .ids - ) + ).ids + - @api.depends('question_type') def _compute_event_product_question_id(self): """ Used as an 'onchange' : Reset the event product question if user change question type @@ -70,42 +66,3 @@ class SurveyQuestion(models.Model): if not question.question_type == 'event' or question.event_product_question_id is None: question.event_product_question_id = False - -class SurveyQuestionAnswer(models.Model): - _inherit = "survey.question.answer" - - @api.model - def default_get(self, fields): - result = super().default_get(fields) - if ( - not result.get("event_registration_field") - or "event_registration_field_resource_ref" not in fields - ): - return result - registration_field = self.env["ir.model.fields"].browse(result["event_registration_field"]) - # Otherwise we'll just use the value (char, text) - if registration_field.ttype not in {"many2one", "many2many"}: - return result - res = self.env[registration_field.relation].search([], limit=1) - if res: - result["event_registration_field_resource_ref"] = "%s,%s" % ( - registration_field.relation, - res.id, - ) - return result - - @api.model - def _selection_event_registration_field_resource_ref(self): - return [(model.model, model.name) for model in self.env["ir.model"].search([])] - - event_registration_field = fields.Many2one(related="question_id.event_registration_field") - event_registration_field_resource_ref = fields.Reference( - string="Event registration field value", - selection="_selection_event_registration_field_resource_ref", - ) - - @api.onchange("event_registration_field_resource_ref") - def _onchange_event_registration_field_resource_ref(self): - """Set the default value as the display_name, although we can change it""" - if self.event_registration_field_resource_ref: - self.value = self.event_registration_field_resource_ref.display_name or "" diff --git a/survey_event_registration_generation/models/survey_survey.py b/survey_event_registration_generation/models/survey_survey.py index ed8b87c..4a12256 100644 --- a/survey_event_registration_generation/models/survey_survey.py +++ b/survey_event_registration_generation/models/survey_survey.py @@ -7,7 +7,7 @@ class SurveySurvey(models.Model): _inherit = "survey.survey" generate_registration = fields.Boolean( - help="Generate registration for selected event", + help="Generate event registration for selected event", ) \ No newline at end of file diff --git a/survey_event_registration_generation/models/survey_user_input.py b/survey_event_registration_generation/models/survey_user_input.py index c00e257..0d86467 100644 --- a/survey_event_registration_generation/models/survey_user_input.py +++ b/survey_event_registration_generation/models/survey_user_input.py @@ -15,12 +15,14 @@ _logger = logging.getLogger(__name__) class SurveyUserInput(models.Model): _inherit = 'survey.user_input' - registration_id = fields.Many2one('event.registration', 'Event registration') + registration_id = fields.Many2one('event.registration', 'Event registration') #registration created automaticaly on survey post - event_id = fields.Many2one('event.event', 'Événement', compute='compute_event_id', store=True) + event_id = fields.Many2one('event.event', 'Événement', compute='compute_event_id', store=True) #related event - answer of "event" question @api.depends('user_input_line_ids') def compute_event_id(self): + """set event_id as answer of "event" question + """ for user_input in self: for user_input_line in user_input.user_input_line_ids: if user_input_line.answer_type == 'event': @@ -77,56 +79,23 @@ class SurveyUserInput(models.Model): def _prepare_registration(self): """Extract registration values from the answers""" - - """TODO: simplifier le code""" elegible_inputs = self.user_input_line_ids.filtered( lambda x: x.question_id.event_registration_field and not x.skipped ) - basic_inputs = elegible_inputs.filtered( - lambda x: x.answer_type not in {"suggestion"} - and x.question_id.event_registration_field.name != "comment" - ) vals = {} - for line in basic_inputs: + for line in elegible_inputs: if line.question_id.event_registration_field.ttype == 'many2one': vals[line.question_id.event_registration_field.name] = line[f"value_{line.answer_type}"].id else: vals[line.question_id.event_registration_field.name] = line[f"value_{line.answer_type}"] - for line in elegible_inputs - basic_inputs: - field_name = line.question_id.event_registration_field.name - if line.question_id.event_registration_field.ttype == "many2one": - vals[ - field_name - ] = line.suggested_answer_id.event_registration_field_resource_ref.id - elif line.question_id.event_registration_field.ttype == "many2many": - vals.setdefault(field_name, []) - vals[field_name] += [ - (4, line.suggested_answer_id.event_registration_field_resource_ref.id) - ] - # We'll use the comment field to add any other infos - elif field_name == "comment": - vals.setdefault("comment", "") - value = ( - line.suggested_answer_id.value - if line.answer_type == "suggestion" - else line[f"value_{line.answer_type}"] - ) - vals["comment"] += f"\n{line.question_id.title}: {value}" - else: - if line.question_id.question_type == "multiple_choice": - if not vals.get(field_name): - vals[field_name] = line.suggested_answer_id.value - else: - vals[field_name] += line.suggested_answer_id.value - else: - vals[field_name] = line.suggested_answer_id.value + return vals def _create_registration_post_process(self, registration): - """After creating the lead send an internal message with the input link""" + """After creating the event registration send an internal message with the input link""" registration.message_post_with_view( "mail.message_origin_link", values={"self": registration, "origin": self}, diff --git a/survey_event_registration_generation/models/survey_user_input_line.py b/survey_event_registration_generation/models/survey_user_input_line.py index bd7db94..2ef016e 100644 --- a/survey_event_registration_generation/models/survey_user_input_line.py +++ b/survey_event_registration_generation/models/survey_user_input_line.py @@ -13,12 +13,14 @@ class SurveyUserInputLine(models.Model): _inherit = 'survey.user_input.line' answer_type = fields.Selection( - selection_add=[('event_product', 'Event product'),('event', 'Event')]) + selection_add=[('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") - value_event_product = fields.Many2one('product.product', string="Event product") + value_event = fields.Many2one('event.event', string="Event") #selected event + value_event_product = fields.Many2one('product.product', string="Event product") #selected product def _compute_display_name(self): + """display event product name, or event name, depending on answer type + """ super()._compute_display_name() for line in self: if line.answer_type == 'event_product': diff --git a/survey_event_registration_generation/views/event_stage_views.xml b/survey_event_registration_generation/views/event_stage_views.xml index f416b57..22937b4 100644 --- a/survey_event_registration_generation/views/event_stage_views.xml +++ b/survey_event_registration_generation/views/event_stage_views.xml @@ -1,6 +1,8 @@ + + event.stage.view.form.survey.event.registration.generation event.stage @@ -12,6 +14,8 @@ + + event.stage.view.tree.survey.event.registration.generation event.stage diff --git a/survey_event_registration_generation/views/survey_question_views.xml b/survey_event_registration_generation/views/survey_question_views.xml index cbb90b4..b7b421d 100644 --- a/survey_event_registration_generation/views/survey_question_views.xml +++ b/survey_event_registration_generation/views/survey_question_views.xml @@ -1,37 +1,24 @@ + + survey.question + + + - - - {'default_question_id': active_id, 'default_event_registration_field': event_registration_field} - - - - - diff --git a/survey_event_registration_generation/views/survey_survey_views.xml b/survey_event_registration_generation/views/survey_survey_views.xml index 5801a7b..c4edeef 100644 --- a/survey_event_registration_generation/views/survey_survey_views.xml +++ b/survey_event_registration_generation/views/survey_survey_views.xml @@ -1,11 +1,13 @@ + survey.survey + diff --git a/survey_event_registration_generation/views/survey_templates.xml b/survey_event_registration_generation/views/survey_templates.xml index 3d95181..641f85e 100644 --- a/survey_event_registration_generation/views/survey_templates.xml +++ b/survey_event_registration_generation/views/survey_templates.xml @@ -13,6 +13,7 @@ + +