-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] mail_brand: add brand to mails
If mails are send with a brand assigned (for instanse from a sales order) the brand info will be shown instead of the company info.
- Loading branch information
Showing
15 changed files
with
725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
=========== | ||
Email Brand | ||
=========== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fbrand-lightgray.png?logo=github | ||
:target: https://github.com/OCA/brand/tree/15.0/mail_brand | ||
:alt: OCA/brand | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/brand-15-0/brand-15-0-mail_brand | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/284/15.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
If a model has a brand defined to it, emails send from this model will be branded accordingly. | ||
|
||
If the brand module gets implemented more broadly this module could need extension to work properly, because not all | ||
odoo modules use the same mail templates | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/brand/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/brand/issues/new?body=module:%20mail_brand%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. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Gert Pellin / Snakebyte Development | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Gert Pellin <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
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. | ||
|
||
.. |maintainer-switch87| image:: https://github.com/switch87.png?size=40px | ||
:target: https://github.com/switch87 | ||
:alt: switch87 | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-switch87| | ||
|
||
This module is part of the `OCA/brand <https://github.com/OCA/brand/tree/15.0/mail_brand>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2022 Snakebyte | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Email Brand", | ||
"summary": """ | ||
If a model has a brand defined to it, emails send from this model will be | ||
branded accordingly. If the brand module gets implemented more broadly this | ||
module could need extension to work properly. | ||
""", | ||
"license": "AGPL-3", | ||
"author": "Odoo Community Association (OCA), Gert Pellin / Snakebyte Development", | ||
"website": "https://github.com/OCA/brand", | ||
"version": "15.0.1.0.1", | ||
"depends": ["mail", "brand"], | ||
"data": [ | ||
"data/mail_template.xml", | ||
], | ||
"maintainers": ["switch87"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Copyright (C) 2022 Snakebyte | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
import base64 | ||
import functools | ||
import io | ||
|
||
import odoo | ||
from odoo import http | ||
from odoo.modules import get_resource_path | ||
from odoo.tools.mimetypes import guess_mimetype | ||
|
||
from odoo.addons.web.controllers.main import Binary | ||
|
||
|
||
class BrandBinary(Binary): | ||
@http.route() | ||
def company_logo(self, dbname=None, **kw): | ||
response = False | ||
imgname = "logo" | ||
imgext = ".png" | ||
uid = None | ||
placeholder = functools.partial(get_resource_path, "web", "static", "img") | ||
if http.request.session.db: | ||
dbname = http.request.session.db | ||
uid = http.request.session.uid | ||
elif dbname is None: | ||
dbname = http.db_monodb() | ||
if not uid: | ||
uid = odoo.SUPERUSER_ID | ||
if not dbname: | ||
response = http.send_file(placeholder(imgname + imgext)) | ||
else: | ||
try: | ||
has_brand = ( | ||
int(kw["has_brand"]) if kw and kw.get("has_brand") else False | ||
) | ||
if has_brand: | ||
registry = odoo.modules.registry.Registry(dbname) | ||
with registry.cursor() as cr: | ||
brand = int(kw["company"]) | ||
if brand: | ||
cr.execute( | ||
""" | ||
SELECT logo_web, write_date | ||
FROM res_brand | ||
WHERE id = %s | ||
""", | ||
(brand,), | ||
) | ||
row = cr.fetchone() | ||
if row and row[0]: | ||
image_base64 = base64.b64decode(row[0]) | ||
image_data = io.BytesIO(image_base64) | ||
mimetype = guess_mimetype( | ||
image_base64, default="image/png" | ||
) | ||
imgext = "." + mimetype.split("/")[1] | ||
if imgext == ".svg+xml": | ||
imgext = ".svg" | ||
response = http.send_file( | ||
image_data, | ||
filename=imgname + imgext, | ||
mimetype=mimetype, | ||
mtime=row[1], | ||
) | ||
except Exception: | ||
response = http.send_file(placeholder(imgname + imgext)) | ||
return response or super().company_logo(dbname, **kw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<data> | ||
<template | ||
id="message_notification_email_brand" | ||
inherit_id="mail.message_notification_email" | ||
> | ||
<xpath expr="//tbody//img" position="replace"> | ||
<img | ||
t-att-src="'/logo.png?company=%s&has_brand=%i' % (company.id or 0, has_brand or 0)" | ||
style="padding: 0px; margin: 0px; height: auto; max-width: 200px; max-height: 36px;" | ||
t-att-alt="'%s' % company.name" | ||
/> | ||
</xpath> | ||
</template> | ||
|
||
<template | ||
id="mail_notification_borders_brand" | ||
inherit_id="mail.mail_notification_borders" | ||
> | ||
<xpath expr="//tbody//img" position="replace"> | ||
<img | ||
t-att-src="'/logo.png?company=%s&has_brand=%i' % (company.id or 0, has_brand or 0)" | ||
style="padding: 0px; margin: 0px; height: auto; width: 80px;" | ||
t-att-alt="'%s' % company.name" | ||
/> | ||
</xpath> | ||
</template> | ||
|
||
<template | ||
id="mail_notification_light_brand" | ||
inherit_id="mail.mail_notification_light" | ||
> | ||
<xpath expr="//tbody//img" position="replace"> | ||
<img | ||
t-att-src="'/logo.png?company=%s&has_brand=%i' % (company.id or 0, has_brand or 0)" | ||
style="padding: 0px; margin: 0px; height: 48px;" | ||
t-att-alt="'%s' % company.name" | ||
/> | ||
</xpath> | ||
</template> | ||
|
||
<template | ||
id="mail_notification_paynow_brand" | ||
inherit_id="mail.mail_notification_paynow" | ||
> | ||
<xpath expr="//tbody//img" position="replace"> | ||
<img | ||
t-att-src="'/logo.png?company=%s&has_brand=%i' % (company.id or 0, has_brand or 0)" | ||
style="padding: 0px; margin: 0px; height: 48px;" | ||
t-att-alt="'%s' % company.name" | ||
/> | ||
</xpath> | ||
</template> | ||
</data> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from . import ir_model | ||
from . import res_brand | ||
from . import mail_thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (C) 2022 Snakebyte | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class BaseModel(models.AbstractModel): | ||
_inherit = "base" | ||
|
||
def get_base_url(self): | ||
if not self: | ||
return super().get_base_url() | ||
if "brand_id" in self and "website_id" in self.brand_id: | ||
return self.brand_id.website_website_id.domain | ||
else: | ||
return super().get_base_url() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (C) 2022 Snakebyte | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class MailThread(models.AbstractModel): | ||
_inherit = "mail.thread" | ||
|
||
@api.model | ||
def _notify_prepare_template_context( | ||
self, message, msg_vals, model_description=False, mail_auto_delete=True | ||
): | ||
result = super()._notify_prepare_template_context( | ||
message, msg_vals, model_description, mail_auto_delete | ||
) | ||
|
||
result["has_brand"] = hasattr(self, "brand_id") | ||
if result["has_brand"]: | ||
result["company"] = self.brand_id | ||
if self.brand_id.website: | ||
result["website_url"] = ( | ||
"https://%s" % self.brand_id.website | ||
if not self.brand_id.website.lower().startswith(("http:", "https:")) | ||
else self.brand_id.website | ||
) | ||
else: | ||
result["website_url"] = False | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2022 Snakebyte | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
from odoo.tools import image_process | ||
|
||
|
||
class ResBrand(models.Model): | ||
|
||
_inherit = "res.brand" | ||
|
||
logo_web = fields.Binary(compute="_compute_logo_web", store=True, attachment=False) | ||
|
||
@api.depends("partner_id.image_1920") | ||
def _compute_logo_web(self): | ||
for brand in self: | ||
brand.logo_web = image_process(brand.partner_id.image_1920, size=(180, 0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Gert Pellin <[email protected]> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
If a model has a brand defined to it, emails send from this model will be branded accordingly. | ||
|
||
If the brand module gets implemented more broadly this module could need extension to work properly, because not all | ||
odoo modules use the same mail templates |
Empty file.
Oops, something went wrong.