Skip to content

Commit

Permalink
[MIG] event_mail: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Tejeda committed May 10, 2023
1 parent 006a15b commit 319325a
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 66 deletions.
23 changes: 13 additions & 10 deletions event_mail/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Event Mail
==========

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:84c63a23ae4fc316aaded3e161fd432db10423bc7968bef843a8e147fdd8bba3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,16 +17,16 @@ 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/14.0/event_mail
:target: https://github.com/OCA/event/tree/15.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-14-0/event-14-0-event_mail
:target: https://translation.odoo-community.org/projects/event-15-0/event-15-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/14.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/event&target_branch=15.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to define mail settings for events. By default the emails
scheduler has been deactivated.
Expand Down Expand Up @@ -53,8 +56,8 @@ 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:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/event/issues/new?body=module:%20event_mail%0Aversion:%2015.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 @@ -88,6 +91,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/14.0/event_mail>`_ project on GitHub.
This module is part of the `OCA/event <https://github.com/OCA/event/tree/15.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": "14.0.1.0.0",
"version": "15.0.1.0.0",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/event",
Expand Down
17 changes: 3 additions & 14 deletions event_mail/models/event.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2017 Tecnativa - Sergio Teruel <sergio.teruel@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo import Command, api, fields, models


class EventEvent(models.Model):
Expand All @@ -22,19 +22,8 @@ def _compute_event_mail_ids(self):
without_template = self - records
for event in records:
command = [(5, 0)] + [
(
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()
},
)
Command.create(line._prepare_event_mail_values())
for line in event.event_mail_template_id.scheduler_template_ids
]
event.event_mail_ids = command
super(EventEvent, without_template)._compute_event_mail_ids()
return super(EventEvent, without_template)._compute_event_mail_ids()
14 changes: 12 additions & 2 deletions event_mail/models/event_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ class EventMailSchedulerTemplate(models.Model):
ondelete="cascade",
)

def _prepare_event_mail_values(self):
self.ensure_one()
return {
"notification_type": self.notification_type,
"interval_nbr": self.interval_nbr,
"interval_unit": self.interval_unit,
"interval_type": self.interval_type,
"template_ref": f"{self.template_ref._name},{self.template_ref.id}",
}


class EventMailTemplate(models.Model):
_name = "event.mail.template"
Expand All @@ -28,14 +38,14 @@ def _default_scheduler_template_ids(self):
"notification_type": "mail",
"interval_unit": "now",
"interval_type": "after_sub",
"template_id": self.env.ref("event.event_subscription").id,
"template_ref": f"mail.template, {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,
"template_ref": f"mail.template, {self.env.ref('event.event_reminder').id}",
},
]

Expand Down
38 changes: 13 additions & 25 deletions event_mail/models/event_type.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
# Copyright 2019 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models
from odoo import Command, models


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

def _compute_event_type_mail_ids(self):
def default_get(self, fields_list):
res = super().default_get(fields_list)
event_mail_template_id = self.env.company.event_mail_template_id
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)]
if event_mail_template_id:
res.update(
{
"event_type_mail_ids": [
Command.create(line._prepare_event_mail_values())
for line in event_mail_template_id.scheduler_template_ids
]
}
)
return res
12 changes: 7 additions & 5 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 @@ -366,8 +366,10 @@ <h1 class="title">Event Mail</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:84c63a23ae4fc316aaded3e161fd432db10423bc7968bef843a8e147fdd8bba3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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><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/15.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-15-0/event-15-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://runboat.odoo-community.org/webui/builds.html?repo=OCA/event&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-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 @@ -402,8 +404,8 @@ <h1><a class="toc-backref" href="#id1">Usage</a></h1>
<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:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/event/issues/new?body=module:%20event_mail%0Aversion:%2015.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 @@ -435,7 +437,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/14.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/15.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
13 changes: 6 additions & 7 deletions event_mail/tests/test_event_mail.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# 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 SavepointCase
from odoo.tests.common import TransactionCase


class EventMailCase(SavepointCase):
class EventMailCase(TransactionCase):
@classmethod
def setUpClass(cls):
"""Add some defaults to let the test run without an accounts chart."""
super().setUpClass()
cls.template1 = cls.env["event.mail.template"].create(
{"name": "Template test 01"}
)
event_reminder = cls.env.ref("event.event_reminder")
cls.template2 = cls.env["event.mail.template"].create(
{
"name": "Template test 01",
Expand All @@ -23,7 +24,7 @@ def setUpClass(cls):
"interval_nbr": 15,
"interval_unit": "days",
"interval_type": "before_event",
"template_id": cls.env.ref("event.event_reminder").id,
"template_ref": f"mail.template, {event_reminder.id}",
},
)
],
Expand Down Expand Up @@ -86,7 +87,7 @@ def test_event_template_no_config(self):
event = self.env["event.event"].create(vals)
self.assertEqual(
len(event.event_mail_ids),
0,
3,
"Event Mail: mails scheduler no created for this event",
)

Expand All @@ -97,9 +98,7 @@ def test_company_event_type(self):
.create({"event_mail_template_id": self.template2.id})
)
event_config.execute()
event_type = self.env["event.type"].create(
{"name": "Physical", "use_mail_schedule": "False"}
)
event_type = self.env["event.type"].create({"name": "Physical"})
self.assertTrue(
event_type.event_type_mail_ids.exists(),
"Must be 'Mail Schedule'",
Expand Down
4 changes: 2 additions & 2 deletions event_mail/views/event_mail_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</group>
<group string="Mail Scheduler">
<field name="scheduler_template_ids" nolabel="1">
<tree string="Email Schedule" editable="bottom">
<tree editable="bottom">
<field name="sequence" widget="handle" />
<field name="template_id" />
<field name="template_ref" />
<field
name="interval_nbr"
attrs="{'readonly':[('interval_unit','=','now')]}"
Expand Down
1 change: 1 addition & 0 deletions setup/event_mail/odoo/addons/event_mail
6 changes: 6 additions & 0 deletions setup/event_mail/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 319325a

Please sign in to comment.