From 9c68b37cfacf8ecf013f64086e40cecde71dfe75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Tue, 26 Sep 2023 12:48:46 +0200 Subject: [PATCH] mail_preview_send: add module --- mail_preview_send/TODO | 1 + mail_preview_send/__init__.py | 1 + mail_preview_send/__manifest__.py | 27 ++++++++++++++++ mail_preview_send/wizards/__init__.py | 1 + .../wizards/mail_template_preview.py | 31 +++++++++++++++++++ .../wizards/mail_template_preview_view.xml | 26 ++++++++++++++++ mail_unique_layout/models/mail_thread.py | 9 +++++- .../odoo/addons/mail_preview_send | 1 + setup/mail_preview_send/setup.py | 6 ++++ 9 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 mail_preview_send/TODO create mode 100644 mail_preview_send/__init__.py create mode 100644 mail_preview_send/__manifest__.py create mode 100644 mail_preview_send/wizards/__init__.py create mode 100644 mail_preview_send/wizards/mail_template_preview.py create mode 100644 mail_preview_send/wizards/mail_template_preview_view.xml create mode 120000 setup/mail_preview_send/odoo/addons/mail_preview_send create mode 100644 setup/mail_preview_send/setup.py diff --git a/mail_preview_send/TODO b/mail_preview_send/TODO new file mode 100644 index 000000000..5676b9ca6 --- /dev/null +++ b/mail_preview_send/TODO @@ -0,0 +1 @@ +- Faire la preview de mail avec envoie par mail diff --git a/mail_preview_send/__init__.py b/mail_preview_send/__init__.py new file mode 100644 index 000000000..5cb1c4914 --- /dev/null +++ b/mail_preview_send/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/mail_preview_send/__manifest__.py b/mail_preview_send/__manifest__.py new file mode 100644 index 000000000..2c6e51ac9 --- /dev/null +++ b/mail_preview_send/__manifest__.py @@ -0,0 +1,27 @@ +# Copyright 2023 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mail Preview send", + "summary": "Send preview email", + "version": "14.0.1.0.0", + "development_status": "Alpha", + "category": "Uncategorized", + "website": "https://github.com/akretion/ak-odoo-incubator", + "author": " Akretion", + "license": "AGPL-3", + "external_dependencies": { + "python": [], + "bin": [], + }, + "depends": [ + "mail", + "web_domain_field", + "mail_unique_layout", + ], + "data": [ + "wizards/mail_template_preview_view.xml", + ], + "demo": [], +} diff --git a/mail_preview_send/wizards/__init__.py b/mail_preview_send/wizards/__init__.py new file mode 100644 index 000000000..344fd2141 --- /dev/null +++ b/mail_preview_send/wizards/__init__.py @@ -0,0 +1 @@ +from . import mail_template_preview diff --git a/mail_preview_send/wizards/mail_template_preview.py b/mail_preview_send/wizards/mail_template_preview.py new file mode 100644 index 000000000..5dc037129 --- /dev/null +++ b/mail_preview_send/wizards/mail_template_preview.py @@ -0,0 +1,31 @@ +# Copyright 2023 Akretion (https://www.akretion.com). +# @author Sébastien BEAU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import json + +from odoo import api, fields, models + + +class MailTemplatePreview(models.TransientModel): + _inherit = "mail.template.preview" + + layout_id = fields.Many2one( + "ir.ui.view", + "Layout", + ) + layout_domain = fields.Char(compute="_compute_layout_domain") + + def send(self): + xml_id = self.layout_id.get_external_id()[self.layout_id.id] + self.mail_template_id.with_context(force_mail_uniq_layout_id=xml_id).send_mail( + self.model_id.id + ) + + def _get_layout_domain(self): + return [] + + @api.depends("mail_template_id") + def _compute_layout_domain(self): + for record in self: + record.layout_domain = json.dumps(self._get_layout_domain()) diff --git a/mail_preview_send/wizards/mail_template_preview_view.xml b/mail_preview_send/wizards/mail_template_preview_view.xml new file mode 100644 index 000000000..e9c860dac --- /dev/null +++ b/mail_preview_send/wizards/mail_template_preview_view.xml @@ -0,0 +1,26 @@ + + + + + + mail.template.preview + + + +
+ Choisir un layout: +
+ + +
+
+
+ +
+
+ +
diff --git a/mail_unique_layout/models/mail_thread.py b/mail_unique_layout/models/mail_thread.py index 7d70f8d7c..5395e8308 100644 --- a/mail_unique_layout/models/mail_thread.py +++ b/mail_unique_layout/models/mail_thread.py @@ -8,9 +8,16 @@ class MailThread(models.AbstractModel): _inherit = "mail.thread" @api.model - def _get_unique_layout_ref(self): + def _get_default_unique_layout_ref(self): return "mail_unique_layout.general_mail_layout" + @api.model + def _get_unique_layout_ref(self): + if self._context.get("force_mail_uniq_layout_id"): + return self._context["force_mail_uniq_layout_id"] + else: + return self._get_default_unique_layout_ref() + @api.returns("mail.message", lambda value: value.id) def message_post(self, *kw, **kwargs): kwargs["email_layout_xmlid"] = self._get_unique_layout_ref() diff --git a/setup/mail_preview_send/odoo/addons/mail_preview_send b/setup/mail_preview_send/odoo/addons/mail_preview_send new file mode 120000 index 000000000..aa9ecddd7 --- /dev/null +++ b/setup/mail_preview_send/odoo/addons/mail_preview_send @@ -0,0 +1 @@ +../../../../mail_preview_send \ No newline at end of file diff --git a/setup/mail_preview_send/setup.py b/setup/mail_preview_send/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mail_preview_send/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)