Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions mail_attach_existing_attachment/README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

===============================
Mail Attach Existing Attachment
===============================
Expand All @@ -13,7 +17,7 @@ Mail Attach Existing Attachment
.. |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
.. |badge2| image:: https://img.shields.io/badge/license-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%2Fsocial-lightgray.png?logo=github
Expand All @@ -28,8 +32,16 @@ Mail Attach Existing Attachment

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

This module was written to add the possibility to add attachments located on
the object by sending it by email with the mail compose message wizard
This module extends the mail compose message wizard to allow selecting
existing attachments when sending an email.

It provides two attachment selection mechanisms:

* Object Attachments — attachments linked to the current record.
* Model Attachments — attachments linked to other records of the same model.

This makes it possible to reuse documents already stored on other
records of the same model without re-uploading them.

**Table of contents**

Expand All @@ -46,15 +58,21 @@ To use this module, you need to:
.. figure:: https://raw.githubusercontent.com/OCA/social/16.0/mail_attach_existing_attachment/static/description/attachment.png
:alt: Attachment on purchase order

* Then, by sending the object via email, you can select the attachment added earlier
* Optionally, add attachments on other records of the same model
(for example, on another Purchase Order or Partner record).

* Then, by sending the object via email, you can:

* Select attachments linked to the current object.
* Select attachments linked to other records of the same model.

.. figure:: https://raw.githubusercontent.com/OCA/social/16.0/mail_attach_existing_attachment/static/description/ex_mail_compose_message.png
:alt: Sends the Purchase Order by email

Known issues / Roadmap
======================

* The module only allows the addition of attachments linked to the object.
* Model attachments are filtered by model but not further restricted.

Bug Tracker
===========
Expand All @@ -74,6 +92,7 @@ Authors

* ACSONE SA/NV
* Tecnativa
* Therp BV

Contributors
~~~~~~~~~~~~
Expand All @@ -84,6 +103,9 @@ Contributors

* Sergio Teruel
* Ernesto Tejeda
* `Therp BV <https://www.therp.nl>`_:

* Nikos Tsirintanis <ntsirintanis@therp.nl>

Maintainers
~~~~~~~~~~~
Expand Down
7 changes: 4 additions & 3 deletions mail_attach_existing_attachment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Copyright 2015 ACSONE SA/NV
# Copyright 2026 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Mail Attach Existing Attachment",
"summary": "Adding attachment on the object by sending this one",
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
"summary": "Attach existing object or model attachments in mail composer",
"author": "ACSONE SA/NV, Tecnativa, Therp BV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"category": "Social Network",
"version": "16.0.1.1.0",
"version": "16.0.2.0.0",
"license": "AGPL-3",
"depends": ["mail"],
"data": ["wizard/mail_compose_message_view.xml"],
Expand Down
3 changes: 3 additions & 0 deletions mail_attach_existing_attachment/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@

* Sergio Teruel
* Ernesto Tejeda
* `Therp BV <https://www.therp.nl>`_:

* Nikos Tsirintanis <ntsirintanis@therp.nl>
12 changes: 10 additions & 2 deletions mail_attach_existing_attachment/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
This module was written to add the possibility to add attachments located on
the object by sending it by email with the mail compose message wizard
This module extends the mail compose message wizard to allow selecting
existing attachments when sending an email.

It provides two attachment selection mechanisms:

* Object Attachments — attachments linked to the current record.
* Model Attachments — attachments linked to other records of the same model.

This makes it possible to reuse documents already stored on other
records of the same model without re-uploading them.
2 changes: 1 addition & 1 deletion mail_attach_existing_attachment/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* The module only allows the addition of attachments linked to the object.
* Model attachments are filtered by model but not further restricted.
8 changes: 7 additions & 1 deletion mail_attach_existing_attachment/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ To use this module, you need to:
.. figure:: ../static/description/attachment.png
:alt: Attachment on purchase order

* Then, by sending the object via email, you can select the attachment added earlier
* Optionally, add attachments on other records of the same model
(for example, on another Purchase Order or Partner record).

* Then, by sending the object via email, you can:

* Select attachments linked to the current object.
* Select attachments linked to other records of the same model.

.. figure:: ../static/description/ex_mail_compose_message.png
:alt: Sends the Purchase Order by email
65 changes: 46 additions & 19 deletions mail_attach_existing_attachment/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>Mail Attach Existing Attachment</title>
<title>README.rst</title>
<style type="text/css">

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -359,18 +360,30 @@
</style>
</head>
<body>
<div class="document" id="mail-attach-existing-attachment">
<h1 class="title">Mail Attach Existing Attachment</h1>
<div class="document">


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="mail-attach-existing-attachment">
<h1>Mail Attach Existing Attachment</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ac2a9aa40b0d4a582c625061abbe71035a0b6c6421af29465d20d9e51dcfbda3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/social/tree/16.0/mail_attach_existing_attachment"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_attach_existing_attachment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module was written to add the possibility to add attachments located on
the object by sending it by email with the mail compose message wizard</p>
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/16.0/mail_attach_existing_attachment"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_attach_existing_attachment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module extends the mail compose message wizard to allow selecting
existing attachments when sending an email.</p>
<p>It provides two attachment selection mechanisms:</p>
<ul class="simple">
<li>Object Attachments — attachments linked to the current record.</li>
<li>Model Attachments — attachments linked to other records of the same model.</li>
</ul>
<p>This makes it possible to reuse documents already stored on other
records of the same model without re-uploading them.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -386,7 +399,7 @@ <h1 class="title">Mail Attach Existing Attachment</h1>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
<p>To use this module, you need to:</p>
<ul class="simple">
<li>Add some attachments on an object by creating a new <em>Log note</em></li>
Expand All @@ -395,37 +408,44 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<img alt="Attachment on purchase order" src="https://raw.githubusercontent.com/OCA/social/16.0/mail_attach_existing_attachment/static/description/attachment.png" />
</div>
<ul class="simple">
<li>Then, by sending the object via email, you can select the attachment added earlier</li>
<li>Optionally, add attachments on other records of the same model
(for example, on another Purchase Order or Partner record).</li>
<li>Then, by sending the object via email, you can:<ul>
<li>Select attachments linked to the current object.</li>
<li>Select attachments linked to other records of the same model.</li>
</ul>
</li>
</ul>
<div class="figure">
<img alt="Sends the Purchase Order by email" src="https://raw.githubusercontent.com/OCA/social/16.0/mail_attach_existing_attachment/static/description/ex_mail_compose_message.png" />
</div>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
<ul class="simple">
<li>The module only allows the addition of attachments linked to the object.</li>
<li>Model attachments are filtered by model but not further restricted.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/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 to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mail_attach_existing_attachment%0Aversion:%2016.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">
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
<ul class="simple">
<li>ACSONE SA/NV</li>
<li>Tecnativa</li>
<li>Therp BV</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<ul class="simple">
<li>Adrien Peiffer &lt;<a class="reference external" href="mailto:adrien.peiffer&#64;acsone.eu">adrien.peiffer&#64;acsone.eu</a>&gt;</li>
<li>Benoit Aimont &lt;<a class="reference external" href="mailto:benoit.aimont&#64;acsone.eu">benoit.aimont&#64;acsone.eu</a>&gt;</li>
Expand All @@ -434,12 +454,18 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Ernesto Tejeda</li>
</ul>
</li>
<li><a class="reference external" href="https://www.therp.nl">Therp BV</a>:<ul>
<li>Nikos Tsirintanis &lt;<a class="reference external" href="mailto:ntsirintanis&#64;therp.nl">ntsirintanis&#64;therp.nl</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<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>
Expand All @@ -448,5 +474,6 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
</div>
</div>
</div>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2015 ACSONE SA/NV
# Copyright 2026 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests import common
Expand All @@ -16,6 +17,14 @@ def setUp(self):
"parent_id": False,
}
)
self.partner_02 = self.env["res.partner"].create(
{
"name": "Partner 2",
"email": "partner2@example.org",
"is_company": True,
"parent_id": False,
}
)

def test_send_email_attachment(self):
attach1 = self.env["ir.attachment"].create(
Expand All @@ -26,12 +35,23 @@ def test_send_email_attachment(self):
"res_id": self.partner_01.id,
}
)
attach2 = self.env["ir.attachment"].create(
{
"name": "Attach2",
"datas": "bW9kZWwgdGVzdA==",
"res_model": "res.partner",
"res_id": self.partner_02.id,
}
)
vals = {
"model": "res.partner",
"partner_ids": [(6, 0, [self.partner_01.id])],
"res_id": self.partner_01.id,
"object_attachment_ids": [(6, 0, [attach1.id])],
# NEW
"model_attachment_ids": [(6, 0, [attach2.id])],
}
mail = self.env["mail.compose.message"].create(vals)
values = mail.get_mail_values([self.partner_01.id])
self.assertTrue(attach1.id in values[self.partner_01.id]["attachment_ids"])
self.assertTrue(attach2.id in values[self.partner_01.id]["attachment_ids"])
15 changes: 11 additions & 4 deletions mail_attach_existing_attachment/wizard/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2015 ACSONE SA/NV
# Copyright 2026 Therp BV <https://therp.nl>.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
Expand Down Expand Up @@ -27,11 +28,17 @@ def default_get(self, fields_list):
column2="attachment_id",
string="Object Attachments",
)
model_attachment_ids = fields.Many2many(
comodel_name="ir.attachment",
string="Model Attachments",
)

def get_mail_values(self, res_ids):
res = super().get_mail_values(res_ids)
if self.object_attachment_ids.ids and self.model and len(res_ids) == 1:
res[res_ids[0]].setdefault("attachment_ids", []).extend(
self.object_attachment_ids.ids
)
if self.model and len(res_ids) == 1:
attachment_ids = set(res[res_ids[0]].get("attachment_ids", []))
attachment_ids.update(self.object_attachment_ids.ids)
attachment_ids.update(self.model_attachment_ids.ids)
if attachment_ids:
res[res_ids[0]]["attachment_ids"] = list(attachment_ids)
return res
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
domain="[('res_model', '=', model), ('res_id', '=', res_id)]"
attrs="{'invisible': [('can_attach_attachment', '=', False)]}"
/>
<field
name="model_attachment_ids"
widget="many2many_tags"
options="{'no_create': True}"
domain="[('res_model', '=', model), ('res_id', '!=', False), ('res_id', '!=', res_id)]"
attrs="{'invisible': [('can_attach_attachment', '=', False)]}"
/>
</xpath>
</field>
</record>
Expand Down