The previous commit introduced an optimization to reduce the number of queries and fields fetched when we call `name_search`. But it works much better when the dependencies of `display_name` contain field names used in the calculation (on the same record/model). Then, to improve the performance and the cache coherency, add `depends` and `depends_context` depending on the custom `_compute_display_name`. Add only the first level of dependencies (never traverse relational field) because only these have a positive impact on the previous optimization and the cost is very low (see `modified`). About `depends_context`, we don't include `lang` because (when `_` is used by example) it is unlikely to get the same display_name in the same request with two different lang. closes odoo/odoo#122085 Related: odoo/documentation#4639 Related: odoo/enterprise#42599 Related: odoo/upgrade#4780 Signed-off-by: Raphael Collet <rco@odoo.com>
32 lines
1.5 KiB
Python
32 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class EventRegistrationAnswer(models.Model):
|
|
""" Represents the user input answer for a single event.question """
|
|
_name = 'event.registration.answer'
|
|
_description = 'Event Registration Answer'
|
|
_rec_names_search = ['value_answer_id', 'value_text_box']
|
|
|
|
question_id = fields.Many2one(
|
|
'event.question', ondelete='restrict', required=True,
|
|
domain="[('event_id', '=', event_id)]")
|
|
registration_id = fields.Many2one('event.registration', required=True, ondelete='cascade')
|
|
partner_id = fields.Many2one('res.partner', related='registration_id.partner_id')
|
|
event_id = fields.Many2one('event.event', related='registration_id.event_id')
|
|
question_type = fields.Selection(related='question_id.question_type')
|
|
value_answer_id = fields.Many2one('event.question.answer', string="Suggested answer")
|
|
value_text_box = fields.Text('Text answer')
|
|
|
|
_sql_constraints = [
|
|
('value_check', "CHECK(value_answer_id IS NOT NULL OR COALESCE(value_text_box, '') <> '')", "There must be a suggested value or a text value.")
|
|
]
|
|
|
|
# for displaying selected answers by attendees in attendees list view
|
|
@api.depends('value_answer_id', 'question_type', 'value_text_box')
|
|
def _compute_display_name(self):
|
|
for reg in self:
|
|
reg.display_name = reg.value_answer_id.name if reg.question_type == "simple_choice" else reg.value_text_box
|