Skip to content

Commit

Permalink
[MIG] event_session: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dalonsod committed Apr 5, 2021
1 parent 3f8f65c commit 1bff4df
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 86 deletions.
4 changes: 2 additions & 2 deletions event_session/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

{
"name": "Event Sessions",
"version": "12.0.1.0.3",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"version": "13.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/oca/event.git",
"category": "Marketing",
Expand Down
6 changes: 0 additions & 6 deletions event_session/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,23 @@ class EventEvent(models.Model):
store=True,
)

@api.multi
@api.depends("session_ids")
def _compute_sessions_count(self):
for event in self:
event.sessions_count = len(event.session_ids)

@api.multi
@api.constrains("seats_max", "seats_available")
def _check_seats_limit(self):
for event in self:
if not event.session_ids:
return super(EventEvent, event)._check_seats_limit()

@api.multi
@api.depends("seats_max", "seats_expected")
def _compute_seats_available_expected(self):
for this in self:
seats = this.seats_max - this.seats_expected
this.seats_available_expected = seats

@api.multi
@api.depends("registration_ids.state")
def _compute_state_numbers(self):
for this in self:
Expand All @@ -81,7 +77,6 @@ class EventRegistration(models.Model):
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"):
Expand All @@ -92,7 +87,6 @@ def _check_seats_limit(self):
):
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:
Expand Down
23 changes: 8 additions & 15 deletions event_session/models/event_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class EventMailScheduler(models.Model):
_inherit = "event.mail"

event_id = fields.Many2one(required=False,)
event_id = fields.Many2one(required=False)
session_id = fields.Many2one(
comodel_name="event.session", string="Session", ondelete="cascade",
)
Expand All @@ -26,15 +26,14 @@ class EventMailScheduler(models.Model):
ondelete="cascade",
)

@api.multi
@api.depends(
"mail_sent",
"interval_type",
"event_id.registration_ids",
"mail_registration_ids",
)
def _compute_done(self):
super(EventMailScheduler, self)._compute_done()
super()._compute_done()
for event_mail in self:
if event_mail.session_id and event_mail.interval_type not in [
"before_event",
Expand All @@ -49,7 +48,6 @@ def _compute_done(self):
and all(line.mail_sent for line in event_mail.mail_registration_ids)
)

@api.multi
@api.depends(
"event_id.state",
"event_id.date_begin",
Expand All @@ -58,7 +56,7 @@ def _compute_done(self):
"interval_nbr",
)
def _compute_scheduled_date(self):
super(EventMailScheduler, self)._compute_scheduled_date()
super()._compute_scheduled_date()
for event_mail in self:
if not event_mail.session_id:
continue
Expand All @@ -71,31 +69,26 @@ def _compute_scheduled_date(self):
date, sign = event_mail.session_id.date_begin, -1
else:
date, sign = event_mail.session_id.date_end, 1
event_mail.scheduled_date = fields.Datetime.from_string(
date
) + _INTERVALS[event_mail.interval_unit](sign * event_mail.interval_nbr)
event_mail.scheduled_date = date + _INTERVALS[event_mail.interval_unit](
sign * event_mail.interval_nbr
)


class EventMailRegistration(models.Model):
_inherit = "event.mail.registration"

@api.multi
@api.depends(
"registration_id", "scheduler_id.interval_unit", "scheduler_id.interval_type"
)
def _compute_scheduled_date(self):
super(EventMailRegistration, self)._compute_scheduled_date()
super()._compute_scheduled_date()
for event_mail_reg in self:
if (
event_mail_reg.registration_id
and event_mail_reg.registration_id.session_id
):
date_open = event_mail_reg.registration_id.date_open
date_open_datetime = (
date_open
and fields.Datetime.from_string(date_open)
or fields.datetime.now()
)
date_open_datetime = date_open and date_open or fields.datetime.now()
event_mail_reg.scheduled_date = date_open_datetime + _INTERVALS[
event_mail_reg.scheduler_id.interval_unit
](event_mail_reg.scheduler_id.interval_nbr)
47 changes: 17 additions & 30 deletions event_session/models/event_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def get_locale(env):
"""
Get the locale from the environment as done in ir.qweb.field
https://github.com/odoo/odoo/blob/12.0/odoo/addons/base/models/ir_qweb_fields.py#L235
https://github.com/odoo/odoo/blob/13.0/odoo/addons/base/models
/ir_qweb_fields.py#L238
"""
lang = env["ir.qweb.field"].user_lang()
locale = babel.Locale.parse(lang.code)
Expand Down Expand Up @@ -68,9 +69,9 @@ class EventSession(models.Model):
company_id = fields.Many2one(
comodel_name="res.company", related="event_id.company_id", store=True,
)
event_id = fields.Many2one(comodel_name="event.event", string="Event",)
seats_min = fields.Integer(string="Minimum seats",)
seats_max = fields.Integer(string="Maximum seats",)
event_id = fields.Many2one(comodel_name="event.event", string="Event")
seats_min = fields.Integer(string="Minimum seats")
seats_max = fields.Integer(string="Maximum seats")
seats_availability = fields.Selection(
[("limited", "Limited"), ("unlimited", "Unlimited")],
"Maximum Attendees",
Expand All @@ -81,21 +82,15 @@ class EventSession(models.Model):
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",
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,
Expand All @@ -114,9 +109,9 @@ class EventSession(models.Model):
store=True,
)
seats_available_pc = fields.Float(
string="Full %", readonly=True, compute="_compute_seats",
string="Full %", store=True, readonly=True, compute="_compute_seats",
)
date_tz = fields.Selection(string="Timezone", related="event_id.date_tz",)
date_tz = fields.Selection(string="Timezone", related="event_id.date_tz")
date_begin = fields.Datetime(
string="Session start date",
required=True,
Expand Down Expand Up @@ -146,16 +141,15 @@ class EventSession(models.Model):
copy=True,
)

@api.multi
@api.depends("date_begin", "date_end")
def _compute_name(self):
locale = get_locale(self.env)
for session in self:
if not (session.date_begin and session.date_end):
session.name = "/"
continue
date_begin = fields.Datetime.from_string(session.date_begin_located)
date_end = fields.Datetime.from_string(session.date_end_located)
date_begin = session.date_begin_located
date_end = session.date_end_located

dt_formats = [datetime_format("EEEE"), datetime_format("short")]

Expand All @@ -164,7 +158,9 @@ def _compute_name(self):
if date_begin.date() == date_end.date():
dt_formats = [time_format("short")]

name = "{} - {}".format(name, localized_format(date_end, dt_formats, locale))
name = "{} - {}".format(
name, localized_format(date_end, dt_formats, locale)
)
session.name = name

def _session_mails_from_template(self, event_id, mail_template=None):
Expand Down Expand Up @@ -194,7 +190,6 @@ def _session_mails_from_template(self, event_id, mail_template=None):
)
return vals

@api.multi
def name_get(self):
"""Redefine the name_get method to show the event name with the event
session.
Expand All @@ -215,9 +210,8 @@ def create(self, vals):
vals.update(
{"event_mail_ids": self._session_mails_from_template(vals["event_id"])}
)
return super(EventSession, self).create(vals)
return super().create(vals)

@api.multi
def unlink(self):
for this in self:
if this.registration_ids:
Expand All @@ -227,9 +221,8 @@ def unlink(self):
sessions with active registrations"
)
)
return super(EventSession, self).unlink()
return super().unlink()

@api.multi
@api.depends("seats_max", "registration_ids.state")
def _compute_seats(self):
"""Determine reserved, available, reserved but unconfirmed and used
Expand Down Expand Up @@ -271,22 +264,20 @@ def _compute_seats(self):
session.seats_expected * 100 / float(session.seats_max)
)

@api.multi
@api.depends("date_tz", "date_begin")
def _compute_date_begin_located(self):
for session in self.filtered("date_begin"):
self_in_tz = session.with_context(tz=(session.date_tz or "UTC"))
date_begin = fields.Datetime.from_string(session.date_begin)
date_begin = session.date_begin
session.date_begin_located = fields.Datetime.to_string(
fields.Datetime.context_timestamp(self_in_tz, date_begin),
)

@api.multi
@api.depends("date_tz", "date_end")
def _compute_date_end_located(self):
for session in self.filtered("date_end"):
self_in_tz = session.with_context(tz=(session.date_tz or "UTC"))
date_end = fields.Datetime.from_string(session.date_end)
date_end = session.date_end
session.date_end_located = fields.Datetime.to_string(
fields.Datetime.context_timestamp(self_in_tz, date_end),
)
Expand All @@ -303,7 +294,6 @@ def onchange_event_id(self):
}
)

@api.multi
@api.constrains("seats_max", "seats_available")
def _check_seats_limit(self):
for session in self:
Expand All @@ -314,7 +304,6 @@ def _check_seats_limit(self):
):
raise ValidationError(_("No more available seats for this session."))

@api.multi
@api.constrains("date_begin", "date_end")
def _check_dates(self):
for session in self:
Expand All @@ -328,14 +317,12 @@ def _check_dates(self):
_("Session date is out of this event dates range")
)

@api.multi
@api.constrains("date_begin", "date_end")
def _check_zero_duration(self):
for session in self:
if session.date_begin == session.date_end:
raise ValidationError(_("Ending and starting time can't be the same!"))

@api.multi
def button_open_registration(self):
"""Opens session registrations"""
self.ensure_one()
Expand Down
1 change: 1 addition & 0 deletions event_session/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* David Vidal <david.vidal@tecnativa.com>

* Nikos Tsirintanis <ntsirintanis@therp.nl>
* David Alonso <david.alonso@solvos.es>

0 comments on commit 1bff4df

Please sign in to comment.