diff options
| author | Thibault Delavallée <tde@odoo.com> | 2020-01-09 14:29:26 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-01-10 16:06:40 +0000 |
| commit | abcd6c15cf27d0e5da77b2e08a742f40e11c4e84 (patch) | |
| tree | 123ce41b18972f5cd4ad65a24215499fe4877866 /addons/website_event_questions/models | |
| parent | 59e5c8630fef744de7d1f4cdd648edd809507c6d (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')
| -rw-r--r-- | addons/website_event_questions/models/__init__.py | 4 | ||||
| -rw-r--r-- | addons/website_event_questions/models/event_event.py | 37 | ||||
| -rw-r--r-- | addons/website_event_questions/models/event_question.py (renamed from addons/website_event_questions/models/event.py) | 54 | ||||
| -rw-r--r-- | addons/website_event_questions/models/event_registration.py | 25 |
4 files changed, 65 insertions, 55 deletions
diff --git a/addons/website_event_questions/models/__init__.py b/addons/website_event_questions/models/__init__.py index 5004a8f8411..14919447769 100644 --- a/addons/website_event_questions/models/__init__.py +++ b/addons/website_event_questions/models/__init__.py @@ -1,3 +1,5 @@ # -*- coding: utf-8 -*- -from . import event +from . import event_event +from . import event_question +from . import event_registration 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 + ] diff --git a/addons/website_event_questions/models/event.py b/addons/website_event_questions/models/event_question.py index 43b33d1368f..f54fbdcc83b 100644 --- a/addons/website_event_questions/models/event.py +++ b/addons/website_event_questions/models/event_question.py @@ -5,60 +5,6 @@ from odoo import api, fields, models, _ from odoo.exceptions import UserError -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 - ] - - -class EventRegistrationAnswer(models.Model): - ''' This m2m table has to be explicitly instanciated as we need unique ids - in the reporting view event.question.report. - - This model is purely technical. ''' - - _name = 'event.registration.answer' - _table = 'event_registration_answer' - _description = 'Event Registration Answer' - - event_answer_id = fields.Many2one('event.answer', required=True, ondelete='cascade') - event_registration_id = fields.Many2one('event.registration', required=True, ondelete='cascade') - - -class EventRegistration(models.Model): - """ Store answers on attendees. """ - _inherit = 'event.registration' - - answer_ids = fields.Many2many('event.answer', 'event_registration_answer', string='Answers') - - class EventQuestion(models.Model): _name = 'event.question' _rec_name = 'title' diff --git a/addons/website_event_questions/models/event_registration.py b/addons/website_event_questions/models/event_registration.py new file mode 100644 index 00000000000..b8f23da99d7 --- /dev/null +++ b/addons/website_event_questions/models/event_registration.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class EventRegistrationAnswer(models.Model): + ''' This m2m table has to be explicitly instanciated as we need unique ids + in the reporting view event.question.report. + + This model is purely technical. ''' + + _name = 'event.registration.answer' + _table = 'event_registration_answer' + _description = 'Event Registration Answer' + + event_answer_id = fields.Many2one('event.answer', required=True, ondelete='cascade') + event_registration_id = fields.Many2one('event.registration', required=True, ondelete='cascade') + + +class EventRegistration(models.Model): + """ Store answers on attendees. """ + _inherit = 'event.registration' + + answer_ids = fields.Many2many('event.answer', 'event_registration_answer', string='Answers') |
