Skip to content

Commit

Permalink
[MIG] event_mail: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestotejeda committed Oct 26, 2021
1 parent d174eb7 commit 787b4c7
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 76 deletions.
13 changes: 7 additions & 6 deletions event_mail/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Event Mail
: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_mail
:target: https://github.com/OCA/event/tree/14.0/event_mail
: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_mail
:target: https://translation.odoo-community.org/projects/event-14-0/event-14-0-event_mail
: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 @@ -46,15 +46,15 @@ To use this module, you need to:
"Template Mail Scheduler" field.
#. Go to *Events > Events* and create one. All mails schedulers has been
created. Also you can select other template in "Mail Template Scheduler"
field on "Email Schedule" tab.
field on "Communication" tab.

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_mail%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_mail%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 All @@ -73,6 +73,7 @@ Contributors

* Sergio Teruel
* David Vidal
* Ernesto Tejeda

Maintainers
~~~~~~~~~~~
Expand All @@ -87,6 +88,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_mail>`_ project on GitHub.
This module is part of the `OCA/event <https://github.com/OCA/event/tree/14.0/event_mail>`_ 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_mail/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Event Mail",
"summary": "Mail settings in events",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/event",
Expand Down
38 changes: 19 additions & 19 deletions event_mail/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ def _default_event_mail_template_id(self):
default=_default_event_mail_template_id,
)

@api.onchange("event_mail_template_id")
def _onchange_event_mail_template_id(self):
vals = [(6, 0, [])]
if self.event_mail_template_id.exists():
for scheduler in self.event_mail_template_id.scheduler_template_ids:
vals.append(
@api.depends("event_mail_template_id")
def _compute_event_mail_ids(self):
not_custom = self.env["event.event"]
for event in self:
if self.event_mail_template_id:
command = [(5, 0)] + [
(
0,
0,
{
"interval_nbr": scheduler.interval_nbr,
"interval_unit": scheduler.interval_unit,
"interval_type": scheduler.interval_type,
"template_id": scheduler.template_id.id,
attribute_name: line[attribute_name]
if not isinstance(line[attribute_name], models.BaseModel)
else line[attribute_name].id
for attribute_name in self.env[
"event.type.mail"
]._get_event_mail_fields_whitelist()
},
)
)
self.event_mail_ids = vals

@api.onchange("event_type_id")
def _onchange_type(self):
"""If a template is already set, we'll override the event.type
schedulers"""
if not self.event_mail_template_id:
return super()._onchange_type()
for line in event.event_mail_template_id.scheduler_template_ids
]
if command:
event.event_mail_ids = command
else:
not_custom |= event
super(EventEvent, not_custom)._compute_event_mail_ids()
20 changes: 15 additions & 5 deletions event_mail/models/event_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ class EventMailTemplate(models.Model):

@api.model
def _default_scheduler_template_ids(self):
return (
self.env["event.type"]
.with_context(by_pass_config_template=True)
._get_default_event_type_mail_ids()
)
return [
{
"notification_type": "mail",
"interval_unit": "now",
"interval_type": "after_sub",
"template_id": self.env.ref("event.event_subscription").id,
},
{
"notification_type": "mail",
"interval_nbr": 10,
"interval_unit": "days",
"interval_type": "before_event",
"template_id": self.env.ref("event.event_reminder").id,
},
]

name = fields.Char()
scheduler_template_ids = fields.One2many(
Expand Down
42 changes: 25 additions & 17 deletions event_mail/models/event_type.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# Copyright 2019 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
from odoo import models


class EventType(models.Model):
_inherit = "event.type"

@api.model
def _get_default_event_type_mail_ids(self):
if self.env.context.get("by_pass_config_template", False):
return super()._get_default_event_type_mail_ids()
def _compute_event_type_mail_ids(self):
event_mail_template_id = self.env.company.event_mail_template_id
if event_mail_template_id:
return [
{
"template_id": line.template_id,
"interval_nbr": line.interval_nbr,
"interval_unit": line.interval_unit,
"interval_type": line.interval_type,
}
for line in event_mail_template_id.scheduler_template_ids
]
else:
return []
for template in self:
if (
template.use_mail_schedule
and not template.event_type_mail_ids
and event_mail_template_id
):
template.event_type_mail_ids = [
(
0,
0,
{
attribute_name: line[attribute_name]
if not isinstance(line[attribute_name], models.BaseModel)
else line[attribute_name].id
for attribute_name in self.env[
"event.type.mail"
]._get_event_mail_fields_whitelist()
},
)
for line in event_mail_template_id.scheduler_template_ids
]
else:
template.event_type_mail_ids = [(5, 0)]
1 change: 1 addition & 0 deletions event_mail/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

* Sergio Teruel
* David Vidal
* Ernesto Tejeda
9 changes: 5 additions & 4 deletions event_mail/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 Mail</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Event Mail</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_mail"><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_mail"><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_mail"><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_mail"><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 define mail settings for events. By default the emails
scheduler has been deactivated.
You can create mail scheduler templates for events and select one by default
Expand Down Expand Up @@ -403,7 +403,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_mail%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_mail%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 All @@ -422,6 +422,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li>Sergio Teruel</li>
<li>David Vidal</li>
<li>Ernesto Tejeda</li>
</ul>
</blockquote>
</li>
Expand All @@ -434,7 +435,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_mail">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_mail">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
29 changes: 5 additions & 24 deletions event_mail/tests/test_event_mail.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2017 Tecnativa - Sergio Teruel <sergio.teruel@tecnativa.com>
# Copyright 2020 Studio73 - Pablo Fuentes <pablo@studio73.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import Form, SavepointCase
from odoo.tests.common import SavepointCase


class EventMailCase(SavepointCase):
Expand Down Expand Up @@ -52,14 +52,12 @@ def test_event_template_config(self):
"event_mail_template_id": self.template1.id,
}
event = self.env["event.event"].create(vals)
event._onchange_event_mail_template_id()
self.assertTrue(
event.event_mail_ids, "Event Mail: mails scheduler created for this event"
)

# Change template in event
event.event_mail_template_id = self.template2
event._onchange_event_mail_template_id()
self.assertEqual(
len(event.event_mail_ids), 1, "Event Mail: mails scheduler only one"
)
Expand Down Expand Up @@ -92,39 +90,22 @@ def test_event_template_no_config(self):
"Event Mail: mails scheduler no created for this event",
)

def test_event_type(self):
online_type_id = self.env["event.type"].create(
{"name": "Online", "is_online": "True", "use_mail_schedule": "False"}
)
self.assertFalse(
online_type_id.event_type_mail_ids.exists(),
"Musn't be 'Mail Schedule'",
)
with Form(self.env["event.event"]) as event_form:
event_form.name = "Event test"
event_form.date_begin = "2020-10-01"
event_form.date_end = "2020-11-01"
event_form.auto_confirm = False
event_form.is_online = False
event_form.event_type_id = online_type_id
self.assertTrue(event_form.is_online, "Online event should be true")

def test_company_event_type(self):
event_config = (
self.env["res.config.settings"]
.sudo()
.create({"event_mail_template_id": self.template2.id})
)
event_config.execute()
physical_type_id = self.env["event.type"].create(
{"name": "Physical", "is_online": "False", "use_mail_schedule": "False"}
event_type = self.env["event.type"].create(
{"name": "Physical", "use_mail_schedule": "False"}
)
self.assertTrue(
physical_type_id.event_type_mail_ids.exists(),
event_type.event_type_mail_ids.exists(),
"Must be 'Mail Schedule'",
)
self.assertEqual(
len(physical_type_id.event_type_mail_ids),
len(event_type.event_type_mail_ids),
len(self.env.company.event_mail_template_id.scheduler_template_ids),
"Must be same number of 'Mail Schedule' as in company default template",
)

0 comments on commit 787b4c7

Please sign in to comment.