Skip to content

Commit

Permalink
[MIG] event_session: Migration to 14.0
Browse files Browse the repository at this point in the history
TT34351
  • Loading branch information
chienandalu committed Mar 23, 2022
1 parent 2771123 commit fb86281
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 99 deletions.
10 changes: 5 additions & 5 deletions event_session/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Event Sessions
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github
:target: https://github.com/OCA/event/tree/13.0/event_session
:target: https://github.com/OCA/event/tree/14.0/event_session
:alt: OCA/event
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/event-13-0/event-13-0-event_session
:target: https://translation.odoo-community.org/projects/event-14-0/event-14-0-event_session
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/199/13.0
:target: https://runbot.odoo-community.org/runbot/199/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -47,7 +47,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/event/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/event/issues/new?body=module:%20event_session%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/event/issues/new?body=module:%20event_session%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -84,6 +84,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/event <https://github.com/OCA/event/tree/13.0/event_session>`_ project on GitHub.
This module is part of the `OCA/event <https://github.com/OCA/event/tree/14.0/event_session>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion event_session/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Event Sessions",
"version": "13.0.1.0.2",
"version": "14.0.1.0.0",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/event",
Expand Down
10 changes: 10 additions & 0 deletions event_session/migrations/14.0.1.0.0/noupdate_changes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record model="ir.rule" id="event_session_company_rule">
<field name="name">Event Session: multi-company</field>
<field name="model_id" ref="model_event_session" />
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>
</odoo>
10 changes: 10 additions & 0 deletions event_session/migrations/14.0.1.0.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2022 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
openupgrade.load_data(
env.cr, "event_session", "migrations/14.0.1.0.0/noupdate_changes.xml"
)
24 changes: 24 additions & 0 deletions event_session/migrations/14.0.1.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2022 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade


def rename_event_session_seats(env):
openupgrade.logged_query(
env.cr,
"""
ALTER TABLE event_session
ADD COLUMN seats_limited boolean""",
)
openupgrade.logged_query(
env.cr,
"""
UPDATE event_session
SET seats_limited = CASE
WHEN seats_availability = 'limited' THEN TRUE ELSE FALSE END""",
)


@openupgrade.migrate()
def migrate(env, version):
rename_event_session_seats(env)
3 changes: 2 additions & 1 deletion event_session/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class EventEvent(models.Model):
string=" # No of Confirmed Registrations",
store=True,
)
generate_sessions_button_visible = fields.Boolean(related="stage_id.pipe_end")

@api.depends("session_ids")
def _compute_sessions_count(self):
Expand Down Expand Up @@ -88,7 +89,7 @@ class EventRegistration(models.Model):
def _check_seats_limit(self):
for registration in self.filtered("session_id"):
if (
registration.session_id.seats_availability == "limited"
registration.session_id.seats_limited
and registration.session_id.seats_available < 1
and registration.state == "open"
):
Expand Down
50 changes: 13 additions & 37 deletions event_session/models/event_mail.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
# Copyright 2017 David Vidal<david.vidal@tecnativa.com>
# Copyright 2017-22 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)

try:
from odoo.addons.event.models.event_mail import _INTERVALS
except ImportError:
_logger.debug("Can not import events module.")
from odoo.addons.event.models.event_mail import _INTERVALS


class EventMailScheduler(models.Model):
Expand All @@ -28,12 +20,7 @@ class EventMailScheduler(models.Model):
ondelete="cascade",
)

@api.depends(
"mail_sent",
"interval_type",
"event_id.registration_ids",
"mail_registration_ids",
)
@api.depends()
def _compute_done(self):
super()._compute_done()
for event_mail in self:
Expand All @@ -50,38 +37,27 @@ def _compute_done(self):
and all(line.mail_sent for line in event_mail.mail_registration_ids)
)

@api.depends(
"event_id.state",
"event_id.date_begin",
"interval_type",
"interval_unit",
"interval_nbr",
)
@api.depends("session_id.date_begin", "session_id.date_end")
def _compute_scheduled_date(self):
super()._compute_scheduled_date()
for event_mail in self:
if not event_mail.session_id:
continue
if event_mail.event_id.state not in ["confirm", "done"]:
event_mail.scheduled_date = False
if event_mail.interval_type == "after_sub":
date, sign = event_mail.session_id.create_date, 1
elif event_mail.interval_type == "before_event":
date, sign = event_mail.session_id.date_begin, -1
else:
if event_mail.interval_type == "after_sub":
date, sign = event_mail.session_id.create_date, 1
elif event_mail.interval_type == "before_event":
date, sign = event_mail.session_id.date_begin, -1
else:
date, sign = event_mail.session_id.date_end, 1
event_mail.scheduled_date = date + _INTERVALS[event_mail.interval_unit](
sign * event_mail.interval_nbr
)
date, sign = event_mail.session_id.date_end, 1
event_mail.scheduled_date = date + _INTERVALS[event_mail.interval_unit](
sign * event_mail.interval_nbr
)


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

@api.depends(
"registration_id", "scheduler_id.interval_unit", "scheduler_id.interval_type"
)
@api.depends()
def _compute_scheduled_date(self):
super()._compute_scheduled_date()
for event_mail_reg in self:
Expand Down
33 changes: 13 additions & 20 deletions event_session/models/event_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ class EventSession(models.Model):
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")
seats_availability = fields.Selection(
[("limited", "Limited"), ("unlimited", "Unlimited")],
"Maximum Attendees",
required=True,
default="unlimited",
)
seats_limited = fields.Boolean(string="Maximum Attendees", required=True)
seats_reserved = fields.Integer(
string="Reserved Seats",
store=True,
Expand Down Expand Up @@ -147,7 +141,6 @@ class EventSession(models.Model):
comodel_name="event.registration",
inverse_name="session_id",
string="Attendees",
state={"done": [("readonly", True)]},
)
event_mail_ids = fields.One2many(
comodel_name="event.mail",
Expand Down Expand Up @@ -219,7 +212,7 @@ def create(self, vals):
# Config availabilities based on event
if vals.get("event_id", False):
event = self.env["event.event"].browse(vals.get("event_id"))
vals["seats_availability"] = event.seats_availability
vals["seats_limited"] = event.seats_limited
vals["seats_max"] = event.seats_max
if not vals.get("event_mail_ids", False):
vals.update(
Expand All @@ -228,14 +221,13 @@ def create(self, vals):
return super().create(vals)

def unlink(self):
for this in self:
if this.registration_ids:
raise ValidationError(
_(
"You are trying to delete one or more \
sessions with active registrations"
)
if self.filtered("registration_ids"):
raise ValidationError(
_(
"You are trying to delete one or more \
sessions with active registrations"
)
)
return super().unlink()

@api.depends("seats_max", "registration_ids.state")
Expand Down Expand Up @@ -306,9 +298,8 @@ def _compute_date_end_located(self):
def onchange_event_id(self):
self.update(
{
"seats_min": self.event_id.seats_min,
"seats_max": self.event_id.seats_max,
"seats_availability": self.event_id.seats_availability,
"seats_limited": self.event_id.seats_limited,
"date_begin": self.event_id.date_begin,
"date_end": self.event_id.date_end,
}
Expand All @@ -318,7 +309,7 @@ def onchange_event_id(self):
def _check_seats_limit(self):
for session in self:
if (
session.seats_availability == "limited"
session.seats_limited
and session.seats_max
and session.seats_available < 0
):
Expand Down Expand Up @@ -346,7 +337,9 @@ def _check_zero_duration(self):
def button_open_registration(self):
"""Opens session registrations"""
self.ensure_one()
action = self.env.ref("event.act_event_registration_from_event").read()[0]
action = self.env["ir.actions.actions"]._for_xml_id(
"event.act_event_registration_from_event"
)
action["domain"] = [("id", "in", self.registration_ids.ids)]
action["context"] = {
"default_event_id": self.event_id.id,
Expand Down
3 changes: 1 addition & 2 deletions event_session/security/event_session_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<record model="ir.rule" id="event_session_company_rule">
<field name="name">Event Session: multi-company</field>
<field name="model_id" ref="model_event_session" />
<field name="global" eval="True" />
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id]),]</field>
>['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>
</odoo>
4 changes: 4 additions & 0 deletions event_session/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_event_session_user,event.session.user,event_session.model_event_session,event.group_event_user,1,0,0,0
access_event_session_admin,event.session.admin,event_session.model_event_session,event.group_event_manager,1,1,1,1
access_wizard_event_session_user,event.session.user,event_session.model_wizard_event_session,event.group_event_user,1,0,0,0
access_wizard_event_session_admin,event.session.admin,event_session.model_wizard_event_session,event.group_event_manager,1,1,1,1
access_wizard_event_session_hours_user,event.session.user,event_session.model_wizard_event_session_hours,event.group_event_user,1,0,0,0
access_wizard_event_session_hours_admin,event.session.admin,event_session.model_wizard_event_session_hours,event.group_event_manager,1,1,1,1
8 changes: 4 additions & 4 deletions event_session/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Event Sessions</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Event Sessions</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/event/tree/13.0/event_session"><img alt="OCA/event" src="https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/event-13-0/event-13-0-event_session"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/199/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/event/tree/14.0/event_session"><img alt="OCA/event" src="https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/event-14-0/event-14-0-event_session"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/199/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows to create sessions associated with events.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
Expand Down Expand Up @@ -396,7 +396,7 @@ <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/event/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/event/issues/new?body=module:%20event_session%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/event/issues/new?body=module:%20event_session%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -427,7 +427,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/event/tree/13.0/event_session">OCA/event</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/event/tree/14.0/event_session">OCA/event</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
17 changes: 6 additions & 11 deletions event_session/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ def setUpClass(cls):
"name": "Test event",
"date_begin": "2017-05-26 20:00:00",
"date_end": "2017-05-30 22:00:00",
"seats_availability": "limited",
"seats_limited": True,
"seats_max": "5",
"seats_min": "1",
}
)
cls.session = cls.env["event.session"].create(
{
"date_begin": "2017-05-26 20:00:00",
"date_end": "2017-05-26 22:00:00",
"event_id": cls.event.id,
"seats_availability": cls.event.seats_availability,
"seats_limited": cls.event.seats_limited,
"seats_max": cls.event.seats_max,
"seats_min": cls.event.seats_min,
}
)
cls.attendee = cls.env["event.registration"].create(
Expand Down Expand Up @@ -184,9 +182,9 @@ def test_wizard(self):
"""Test Session Generation Wizard"""
self.event.date_end = "2017-06-11 23:59:59"
self.event.date_begin = "2017-06-05 00:00:00"
self.wizard.delete_existing_session = True
self.wizard.delete_existing_sessions = False
self.wizard.action_generate_sessions()
# delete previous sessions
# Delete previous sessions
self.wizard.update({"delete_existing_sessions": True})
self.wizard.update({"event_mail_template_id": self.template})
with self.assertRaises(ValidationError) as error, self.cr.savepoint():
Expand All @@ -205,7 +203,7 @@ def test_wizard(self):
for session in sessions:
self.assertTrue(session.event_mail_ids)
self.assertEqual(session.seats_max, self.event.seats_max)
self.assertEqual(session.seats_availability, self.event.seats_availability)
self.assertEqual(session.seats_limited, self.event.seats_limited)
with self.assertRaises(ValidationError), self.cr.savepoint():
# session duration = 0
self.wizard.update(
Expand Down Expand Up @@ -251,8 +249,6 @@ def test_wizard(self):
self.wizard.action_generate_sessions()

def test_event_mail_compute_scheduled_date(self):
self.assertFalse(self.scheduler.scheduled_date)
self.scheduler.event_id.update({"state": "confirm"})
date = self.scheduler.session_id.create_date + relativedelta(hours=+1)
self.assertEqual(self.scheduler.scheduled_date, date)
self.scheduler.update({"interval_type": "before_event"})
Expand Down Expand Up @@ -448,9 +444,8 @@ def test_atendee_counting(self):
"date_begin": "2017-05-27 20:00:00",
"date_end": "2017-05-27 22:00:00",
"event_id": self.event.id,
"seats_availability": self.event.seats_availability,
"seats_limited": self.event.seats_limited,
"seats_max": self.event.seats_max,
"seats_min": self.event.seats_min,
}
)
atendee_1 = self.env["event.registration"].create(
Expand Down
Loading

0 comments on commit fb86281

Please sign in to comment.