Skip to content

Commit

Permalink
[MIG] event_session: Migration to 11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsirintanis committed Nov 28, 2018
1 parent 94f0c1f commit 5585ec1
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 526 deletions.
1 change: 1 addition & 0 deletions event_session/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Contributors

* Sergio Teruel <sergio.teruel@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
* Nikos Tsirintanis <ntsirintanis@therp.nl>

Maintainer
----------
Expand Down
3 changes: 0 additions & 3 deletions event_session/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
from . import wizards
from . import reports
from . import tests
6 changes: 2 additions & 4 deletions event_session/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2017 David Vidal<david.vidal@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Event Sessions',
'version': '10.0.1.0.0',
'version': '11.0.1.0.0',
'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
"license": "AGPL-3",
'website': 'https://odoo-community.org/',
'category': 'Marketing',
'summary': 'Sessions in events',
'depends': ['event', 'event_mail'],
'depends': ['event'],
'data': [
'security/ir.model.access.csv',
'security/event_session_security.xml',
'views/event_session_view.xml',
'views/event_view.xml',
'wizards/wizard_event_session_view.xml',
'reports/report_event_registration_view.xml',
],
'installable': True,
}
4 changes: 1 addition & 3 deletions event_session/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from . import event_session
from . import event
from . import event_mail
from . import event_session
52 changes: 14 additions & 38 deletions event_session/models/event.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2017 David Vidal<david.vidal@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo import api, fields, models


class EventEvent(models.Model):
Expand All @@ -20,6 +18,19 @@ class EventEvent(models.Model):
store=True,
)
seats_expected = fields.Integer(store=True)
seats_available_expected = fields.Integer(
string='Available expected seats',
compute='_compute_seats_available_expected',
store=True,
readonly=True,
)

@api.multi
@api.depends('seats_max', 'seats_expected')
def _compute_seats_available_expected(self):
for event in self:
event.seats_available_expected =\
event.seats_max - event.seats_expected

@api.multi
@api.depends('session_ids')
Expand All @@ -33,38 +44,3 @@ def _check_seats_limit(self):
for event in self:
if not event.session_ids:
return super(EventEvent, event)._check_seats_limit()


class EventRegistration(models.Model):
_inherit = 'event.registration'

event_sessions_count = fields.Integer(
related='event_id.sessions_count',
readonly=True,
)
session_id = fields.Many2one(
comodel_name='event.session',
string='Session',
ondelete='restrict',
)

@api.multi
@api.constrains('event_id', 'session_id', 'state')
def _check_seats_limit(self):
for registration in self.filtered('session_id'):
if (registration.session_id.seats_availability == 'limited' and
registration.session_id.seats_available < 1 and
registration.state == 'open'):
raise ValidationError(
_('No more seats available for this event.'))

@api.multi
def confirm_registration(self):
for reg in self:
if not reg.event_id.session_ids:
super(EventRegistration, reg).confirm_registration()
reg.state = 'open'
onsubscribe_schedulers = \
reg.session_id.event_mail_ids.filtered(
lambda s: s.interval_type == 'after_sub')
onsubscribe_schedulers.execute()
84 changes: 0 additions & 84 deletions event_session/models/event_mail.py

This file was deleted.

125 changes: 0 additions & 125 deletions event_session/models/event_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 David Vidal<david.vidal@tecnativa.com>
# Copyright 2017 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
Expand Down Expand Up @@ -38,32 +37,6 @@ class EventSession(models.Model):
[('limited', 'Limited'), ('unlimited', 'Unlimited')],
'Maximum Attendees', required=True, default='unlimited',
)
seats_reserved = fields.Integer(
string='Reserved Seats', store=True, readonly=True,
compute='_compute_seats',
)
seats_available = fields.Integer(
oldname='register_avail', string='Available Seats',
store=True, readonly=True, compute='_compute_seats')
seats_unconfirmed = fields.Integer(
oldname='register_prospect', string='Unconfirmed Seat Reservations',
store=True, readonly=True, compute='_compute_seats')
seats_used = fields.Integer(
oldname='register_attended', string='Number of Participants',
store=True, readonly=True, compute='_compute_seats')
seats_expected = fields.Integer(
string='Number of Expected Attendees',
readonly=True, compute='_compute_seats',
store=True)
seats_available_expected = fields.Integer(
string='Available Expected Seats',
readonly=True, compute='_compute_seats',
store=True)
seats_available_pc = fields.Float(
string='Full %',
readonly=True,
compute='_compute_seats',
)
date_tz = fields.Selection(
string='Timezone', related="event_id.date_tz",
)
Expand All @@ -83,18 +56,6 @@ class EventSession(models.Model):
date_end_located = fields.Datetime(
string='End Date Located', compute='_compute_date_end_located',
)
registration_ids = fields.One2many(
comodel_name='event.registration',
inverse_name='session_id',
string='Attendees',
state={'done': [('readonly', True)]},
)
event_mail_ids = fields.One2many(
comodel_name='event.mail',
inverse_name='session_id',
string='Mail Schedule',
copy=True
)

@api.multi
@api.depends('date_begin', 'date_end')
Expand All @@ -114,27 +75,6 @@ def _compute_name(self):
name += " - " + date_end.strftime(dt_format)
session.name = name.capitalize()

def _session_mails_from_template(self, event_id, mail_template=None):
vals = [(6, 0, [])]
if not mail_template:
mail_template = self.env['ir.values'].get_default(
'event.config.settings', 'event_mail_template_id')
if not mail_template:
# Not template scheduler defined in event settings
return vals
if isinstance(mail_template, int):
mail_template = self.env['event.mail.template'].browse(
mail_template)
for scheduler in mail_template.scheduler_template_ids:
vals.append((0, 0, {
'event_id': event_id,
'interval_nbr': scheduler.interval_nbr,
'interval_unit': scheduler.interval_unit,
'interval_type': scheduler.interval_type,
'template_id': scheduler.template_id.id,
}))
return vals

@api.multi
def name_get(self):
"""Redefine the name_get method to show the event name with the event
Expand All @@ -145,49 +85,6 @@ def name_get(self):
res.append((item.id, "[%s] %s" % (item.event_id.name, item.name)))
return res

@api.model
def create(self, vals):
if not vals.get('event_mail_ids', False):
vals.update({
'event_mail_ids':
self._session_mails_from_template(vals['event_id'])
})
return super(EventSession, self).create(vals)

@api.multi
@api.depends('seats_max', 'registration_ids.state')
def _compute_seats(self):
"""Determine reserved, available, reserved but unconfirmed and used
seats by session.
"""
# aggregate registrations by event session and by state
if len(self.ids) > 0:
state_field = {
'draft': 'seats_unconfirmed',
'open': 'seats_reserved',
'done': 'seats_used',
}
result = self.env['event.registration'].read_group([
('session_id', 'in', self.ids),
('state', 'in', ['draft', 'open', 'done'])
], ['state', 'session_id'], ['session_id', 'state'], lazy=False)
for res in result:
session = self.browse(res['session_id'][0])
session[state_field[res['state']]] += res['__count']
# compute seats_available
for session in self:
if session.seats_max > 0:
session.seats_available = session.seats_max - (
session.seats_reserved + session.seats_used)
session.seats_expected = (
session.seats_unconfirmed + session.seats_reserved +
session.seats_used)
session.seats_available_expected = (
session.seats_max - session.seats_expected)
if session.seats_max > 0:
session.seats_available_pc = (
session.seats_expected * 100 / float(session.seats_max))

@api.multi
@api.depends('date_tz', 'date_begin')
def _compute_date_begin_located(self):
Expand Down Expand Up @@ -222,15 +119,6 @@ def onchange_event_id(self):
'date_end': self.event_id.date_end,
})

@api.multi
@api.constrains('seats_max', 'seats_available')
def _check_seats_limit(self):
for session in self:
if (session.seats_availability == 'limited' and
session.seats_max and session.seats_available < 0):
raise ValidationError(
_('No more available seats for this session.'))

@api.multi
@api.constrains('date_begin', 'date_end')
def _check_dates(self):
Expand All @@ -251,16 +139,3 @@ def _check_zero_duration(self):
raise ValidationError(
_("Ending and starting time can't be the same!")
)

@api.multi
def button_open_registration(self):
"""Opens session registrations"""
self.ensure_one()
action = self.env.ref(
'event.act_event_registration_from_event').read()[0]
action['domain'] = [('id', 'in', self.registration_ids.ids)]
action['context'] = {
'default_event_id': self.event_id.id,
'default_session_id': self.id,
}
return action
3 changes: 0 additions & 3 deletions event_session/reports/__init__.py

This file was deleted.

0 comments on commit 5585ec1

Please sign in to comment.