[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

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