From 787b4c7c44eba494e97ced4b709b61476cd40d61 Mon Sep 17 00:00:00 2001 From: Ernesto Tejeda Date: Mon, 25 Oct 2021 13:27:19 -0400 Subject: [PATCH] [MIG] event_mail: Migration to 14.0 --- event_mail/README.rst | 13 ++++---- event_mail/__manifest__.py | 2 +- event_mail/models/event.py | 38 ++++++++++----------- event_mail/models/event_mail.py | 20 ++++++++--- event_mail/models/event_type.py | 42 ++++++++++++++---------- event_mail/readme/CONTRIBUTORS.rst | 1 + event_mail/static/description/index.html | 9 ++--- event_mail/tests/test_event_mail.py | 29 +++------------- 8 files changed, 78 insertions(+), 76 deletions(-) diff --git a/event_mail/README.rst b/event_mail/README.rst index d070a6ac5..95de40863 100644 --- a/event_mail/README.rst +++ b/event_mail/README.rst @@ -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| @@ -46,7 +46,7 @@ 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 =========== @@ -54,7 +54,7 @@ Bug Tracker Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -73,6 +73,7 @@ Contributors * Sergio Teruel * David Vidal + * Ernesto Tejeda Maintainers ~~~~~~~~~~~ @@ -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 `_ project on GitHub. +This module is part of the `OCA/event `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/event_mail/__manifest__.py b/event_mail/__manifest__.py index f0d30d738..8b39647ad 100644 --- a/event_mail/__manifest__.py +++ b/event_mail/__manifest__.py @@ -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", diff --git a/event_mail/models/event.py b/event_mail/models/event.py index 4db443f98..4844ccf58 100644 --- a/event_mail/models/event.py +++ b/event_mail/models/event.py @@ -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() diff --git a/event_mail/models/event_mail.py b/event_mail/models/event_mail.py index 2dd4e6039..d9f28e6f2 100644 --- a/event_mail/models/event_mail.py +++ b/event_mail/models/event_mail.py @@ -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( diff --git a/event_mail/models/event_type.py b/event_mail/models/event_type.py index e481257b5..90c6795c3 100644 --- a/event_mail/models/event_type.py +++ b/event_mail/models/event_type.py @@ -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)] diff --git a/event_mail/readme/CONTRIBUTORS.rst b/event_mail/readme/CONTRIBUTORS.rst index 20fa0a2b8..0d5da7862 100644 --- a/event_mail/readme/CONTRIBUTORS.rst +++ b/event_mail/readme/CONTRIBUTORS.rst @@ -2,3 +2,4 @@ * Sergio Teruel * David Vidal + * Ernesto Tejeda diff --git a/event_mail/static/description/index.html b/event_mail/static/description/index.html index 6cedc2a76..b4e1609b4 100644 --- a/event_mail/static/description/index.html +++ b/event_mail/static/description/index.html @@ -3,7 +3,7 @@ - + Event Mail