[IMP] code comment in several modules

This commit is contained in:
clementthomas
2023-10-04 16:55:29 +02:00
parent 915e2bf583
commit e24614f571
17 changed files with 65 additions and 123 deletions

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Event form -->
<record model="ir.ui.view" id="view_event_form_event_speaker">
<field name="name">event.event.form.event.speaker</field>
<field name="model">event.event</field>

View File

@@ -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)])

View File

@@ -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')
visible_in_survey = fields.Boolean('Visible in surveys') #if checked, only events on this stage are visible in surveys

View File

@@ -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:

View File

@@ -5,7 +5,8 @@ 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(
@@ -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,26 +43,19 @@ 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')
@@ -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 ""

View File

@@ -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",
)

View File

@@ -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':
@@ -78,55 +80,22 @@ 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},

View File

@@ -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':

View File

@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<odoo>
<data>
<!-- Event stage view form -->
<!-- * Add field visible_in_survey -->
<record id="event_stage_view_form_survey_event_registration_generation" model="ir.ui.view">
<field name="name">event.stage.view.form.survey.event.registration.generation</field>
<field name="model">event.stage</field>
@@ -12,6 +14,8 @@
</field>
</record>
<!-- Event stage view tree -->
<!-- * Add field visible_in_survey -->
<record id="event_stage_view_tree_survey_event_registration_generation" model="ir.ui.view">
<field name="name">event.stage.view.tree.survey.event.registration.generation</field>
<field name="model">event.stage</field>

View File

@@ -1,37 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Survey question form -->
<record id="survey_question_form" model="ir.ui.view">
<field name="model">survey.question</field>
<field name="inherit_id" ref="survey.survey_question_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='comments_allowed']/.." position="after">
<group name="event_registration" string="Event registration">
<!-- related event product question, to filter events, in case of event question -->
<field name="event_product_question_id" options="{'no_open': True, 'no_create': True}"
attrs="{'invisible': [('question_type','!=','event')]}"
help="Select the question asking for event product, to filter proposed events." />
<!-- event registration field, filtered by event_registration_allowed_field_ids (invisible) -->
<field name="event_registration_field" widget="selection" />
<field name="event_registration_allowed_field_ids" invisible="1" />
</group>
</xpath>
<xpath expr="//field[@name='suggested_answer_ids']" position="attributes">
<attribute
name="context"
>{'default_question_id': active_id, 'default_event_registration_field': event_registration_field}</attribute>
</xpath>
<xpath
expr="//field[@name='suggested_answer_ids']//field[@name='value']"
position="after"
>
<field name="event_registration_field" invisible="1" />
<field
name="event_registration_field_resource_ref"
readonly="False"
options="{'hide_model': True, 'no_create': True, 'no_edit': True, 'no_open': True}"
attrs="{'column_invisible': [('parent.event_registration_field', '=', False)]}"
/>
</xpath>
</field>
</record>
</odoo>

View File

@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Survey form -->
<record id="survey_form" model="ir.ui.view">
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_survey_view_form" />
<field name="arch" type="xml">
<group name="options" position="inside">
<group name="event_registration_options" string="Events registrations">
<!-- Possibility to generate event registration -->
<field name="generate_registration" />
</group>
</group>

View File

@@ -13,6 +13,7 @@
</xpath>
</template>
<!-- Event product selector -->
<template id="question_event_product" name="Question: event product">
<div class="o_survey_comment_container p-0">
<select class="o_survey_form_choice_item"
@@ -30,6 +31,7 @@
</div>
</template>
<!-- Event selector -->
<template id="question_event" name="Question: event">
<div class="o_survey_comment_container p-0">
<select class="o_survey_form_choice_item"

View File

@@ -1,5 +1,5 @@
<odoo>
<!-- Inherit Form View -->
<!-- User Input Form View -->
<record id="survey_event_registration_generation_inherit_survey_user_input_line_form"
model="ir.ui.view">
<field name="name">user.input.value.event.product</field>
@@ -7,6 +7,7 @@
<field name="inherit_id" ref="survey.survey_user_input_line_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='answer_type']" position="after">
<!-- add selected event and event_product -->
<field name="value_event"/>
<field name="value_event_product" />
</xpath>

View File

@@ -8,4 +8,4 @@ class SurveySurvey(models.Model):
generate_speaker = fields.Boolean(
help="Generate speaker for selected event",
)
) #Field to check if user wants to generate a speaker on survey submit

View File

@@ -15,9 +15,10 @@ _logger = logging.getLogger(__name__)
class SurveyUserInput(models.Model):
_inherit = 'survey.user_input'
speaker_id = fields.Many2one('res.partner', 'Event speaker')
speaker_id = fields.Many2one('res.partner', 'Event speaker') #created partner when submit survey
def _get_event(self):
"""Find event selected, in all answers"""
for line in self.user_input_line_ids:
if line.question_id.question_type == 'event' and not line.skipped \
and line.answer_type != "suggestion" \
@@ -26,6 +27,7 @@ class SurveyUserInput(models.Model):
def _create_speaker_post_process(self, speaker):
"""Add message to chatter to note speaker creation and association with event"""
speaker.message_post_with_view(
"survey_event_speaker_generation.message_event_speaker_assigned",
values={"speaker": speaker, "user_input": self, "event":self._get_event()},

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Message notification in res.partner chatter -->
<template id="message_event_speaker_assigned">
<div style="margin: 0px; padding: 0px; font-size: 13px;">
<a href="#" t-att-data-oe-model="speaker._name" t-att-data-oe-id="speaker.id">

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- Survey form -->
<record id="survey_form" model="ir.ui.view">
<field name="model">survey.survey</field>
<field name="inherit_id" ref="survey.survey_survey_view_form" />