summaryrefslogtreecommitdiff
path: root/addons/website_event_questions/models/event_event.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-01-09 14:29:26 +0000
committerThibault Delavallée <tde@odoo.com>2020-01-10 16:06:40 +0000
commitabcd6c15cf27d0e5da77b2e08a742f40e11c4e84 (patch)
tree123ce41b18972f5cd4ad65a24215499fe4877866 /addons/website_event_questions/models/event_event.py
parent59e5c8630fef744de7d1f4cdd648edd809507c6d (diff)
[MOV] (website_)event(_sale/_question/_track): split main model files
PURPOSE As event will soon evolve (onchange -> compute, code improvements, addition of new features) cleaning and improving tests is necessary to help avoid issues. SPECIFICATIONS As event model grow in complexity and features, it is easier to find its way through the application with having registration model lying in its own file to separate it from event-specific models (event.type, event.event). Ticket (event_sale) and sponsor (website_event_track) models are also extracted in their own file. LINKS LINKS Side effect of Task ID 2089156 (event onchange to compute) Community PR odoo/odoo#43127 Enterprise PR odoo/enterprise#7656
Diffstat (limited to 'addons/website_event_questions/models/event_event.py')
-rw-r--r--addons/website_event_questions/models/event_event.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/addons/website_event_questions/models/event_event.py b/addons/website_event_questions/models/event_event.py
new file mode 100644
index 00000000000..c5c04f169f7
--- /dev/null
+++ b/addons/website_event_questions/models/event_event.py
@@ -0,0 +1,37 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+
+
+class EventType(models.Model):
+ _inherit = 'event.type'
+
+ use_questions = fields.Boolean('Questions to Attendees')
+ question_ids = fields.One2many(
+ 'event.question', 'event_type_id',
+ string='Questions', copy=True)
+
+
+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)
+ general_question_ids = fields.One2many('event.question', 'event_id', 'General Questions',
+ domain=[('is_individual', '=', False)])
+ specific_question_ids = fields.One2many('event.question', 'event_id', 'Specific Questions',
+ domain=[('is_individual', '=', True)])
+
+ @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,
+ 'is_individual': question.is_individual,
+ })
+ for question in self.event_type_id.question_ids
+ ]