summaryrefslogtreecommitdiff
path: root/addons/website_event_questions
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-02-19 14:40:37 +0000
committerThibault Delavallée <tde@odoo.com>2020-03-10 11:15:09 +0000
commit5e4efef3ca3f2e9f02ec40c746c0d43aa3e97b79 (patch)
tree0694549107cb5db9f0af721f642fb0542a8ee5ee /addons/website_event_questions
parent22351763477969b415c7403fca260a43a68baac9 (diff)
[REF] event : move from onchange / default to stored editable computed fields
PURPOSE Try to move from onchange / default_get to stored editable computed fields. Behavior should be the same (computed or set by user), with support of create / write / onchange field update without additional code. SPECIFICATIONS: GLOBAL RULES Update classic fields updated in some cases by onchange and/or default methods by fields with store=True, readonly=False. It means their value comes either from manual user input, either from trigger based computation. Remove onchange and default_get when possible, leading to an unique computation method and clearing fields definition. Also clean some fields definition inconsistencies, notably required fields that should instead be correctly computed or default that have no real meaning. SPECIFICATIONS: REQUIRED FIELDS As computed fields are computed after create required attribute cannot be respected without computing them beforehand. That is why we have some custom code to compute required fields if not given at create and update the creation values accordingly. SPECIFICATIONS: MAIL SCHEDULING Mail scheduling on event type is modified in this commit. Previously checking the use_mail_schedule radio button had no effect on event_type_mail_ids field. It is now reset if unchecked. It is therefore coherent with use_ticket and event_type_ticket_ids field behavior. LINKS Task ID 2089156 Community PR odoo/odoo#42911 Co-Authored-By: Thibault Delavallée <tde@odoo.com> Co-Authored-By: Michaël Mattiello <mcm@odoo.com>
Diffstat (limited to 'addons/website_event_questions')
-rw-r--r--addons/website_event_questions/models/event_event.py29
-rw-r--r--addons/website_event_questions/tests/test_event_internals.py2
2 files changed, 17 insertions, 14 deletions
diff --git a/addons/website_event_questions/models/event_event.py b/addons/website_event_questions/models/event_event.py
index 53e1cfc0533..3a7984a30a0 100644
--- a/addons/website_event_questions/models/event_event.py
+++ b/addons/website_event_questions/models/event_event.py
@@ -17,21 +17,24 @@ class EventEvent(models.Model):
""" Override Event model to add optional questions when buying tickets. """
_inherit = 'event.event'
- question_ids = fields.One2many('event.question', 'event_id', 'Questions', copy=True)
+ question_ids = fields.One2many(
+ 'event.question', 'event_id', 'Questions', copy=True,
+ compute='_compute_from_event_type', readonly=False, store=True)
general_question_ids = fields.One2many('event.question', 'event_id', 'General Questions',
domain=[('once_per_order', '=', True)])
specific_question_ids = fields.One2many('event.question', 'event_id', 'Specific Questions',
domain=[('once_per_order', '=', False)])
- @api.onchange('event_type_id')
- def _onchange_type(self):
- super(EventEvent, self)._onchange_type()
- if self.event_type_id.use_questions and self.event_type_id.question_ids:
- self.question_ids = [(5, 0, 0)] + [
- (0, 0, {
- 'title': question.title,
- 'sequence': question.sequence,
- 'once_per_order': question.once_per_order,
- })
- for question in self.event_type_id.question_ids
- ]
+ @api.depends('event_type_id')
+ def _compute_from_event_type(self):
+ super(EventEvent, self)._compute_from_event_type()
+ for event in self:
+ if event.event_type_id.use_questions and event.event_type_id.question_ids:
+ event.question_ids = [(5, 0, 0)] + [
+ (0, 0, {
+ 'title': question.title,
+ 'sequence': question.sequence,
+ 'once_per_order': question.once_per_order,
+ })
+ for question in event.event_type_id.question_ids
+ ]
diff --git a/addons/website_event_questions/tests/test_event_internals.py b/addons/website_event_questions/tests/test_event_internals.py
index aedaf148fc9..d3494cae49c 100644
--- a/addons/website_event_questions/tests/test_event_internals.py
+++ b/addons/website_event_questions/tests/test_event_internals.py
@@ -22,7 +22,7 @@ class TestEventData(TestEventQuestionCommon):
'date_begin': FieldsDatetime.to_string(datetime.today() + timedelta(days=1)),
'date_end': FieldsDatetime.to_string(datetime.today() + timedelta(days=15)),
})
- event._onchange_type()
+
self.assertEqual(event.specific_question_ids.title, 'Question1')
self.assertEqual(
set(event.specific_question_ids.mapped('answer_ids.name')),