Skip to content

Commit

Permalink
Merge pull request #282 from akretion/14.0-add-mail_preview_send
Browse files Browse the repository at this point in the history
mail_preview_send: add module
  • Loading branch information
sebastienbeau authored Oct 30, 2023
2 parents 0e75ca7 + 9c68b37 commit 6fb5e3d
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions mail_preview_send/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Faire la preview de mail avec envoie par mail
1 change: 1 addition & 0 deletions mail_preview_send/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import wizards
27 changes: 27 additions & 0 deletions mail_preview_send/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# 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": [],
}
1 change: 1 addition & 0 deletions mail_preview_send/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_template_preview
31 changes: 31 additions & 0 deletions mail_preview_send/wizards/mail_template_preview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Sébastien BEAU <[email protected]>
# 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())
26 changes: 26 additions & 0 deletions mail_preview_send/wizards/mail_template_preview_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>


<record id="mail_template_preview_view_form" model="ir.ui.view">
<field name="model">mail.template.preview</field>
<field name="inherit_id" ref="mail.mail_template_preview_view_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='lang']/../.." position="after">
<div class="row">
<span
class="col-md-5 col-lg-4 col-sm-12 pl-0"
>Choisir un layout: </span>
<div class="col-md-7 col-lg-6 col-sm-12 pl-0">
<field name="layout_domain" invisible="1" />
<field name="layout_id" domain="layout_domain" />
</div>
</div>
</xpath>
<button special="cancel" position="before">
<button name="send" type="object" string="Send" class="btn btn-primary" />
</button>
</field>
</record>

</odoo>
9 changes: 8 additions & 1 deletion mail_unique_layout/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions setup/mail_preview_send/odoo/addons/mail_preview_send
6 changes: 6 additions & 0 deletions setup/mail_preview_send/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 6fb5e3d

Please sign in to comment.