Skip to content

Commit 2764e9b

Browse files
committed
[16.0][IMP] mail_attach_existing_attachment: attach from model
1 parent f796174 commit 2764e9b

File tree

10 files changed

+136
-35
lines changed

10 files changed

+136
-35
lines changed

mail_attach_existing_attachment/README.rst

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
15
===============================
26
Mail Attach Existing Attachment
37
===============================
@@ -13,7 +17,7 @@ Mail Attach Existing Attachment
1317
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1418
:target: https://odoo-community.org/page/development-status
1519
:alt: Beta
16-
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
20+
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
1721
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1822
:alt: License: AGPL-3
1923
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
@@ -28,8 +32,16 @@ Mail Attach Existing Attachment
2832

2933
|badge1| |badge2| |badge3| |badge4| |badge5|
3034

31-
This module was written to add the possibility to add attachments located on
32-
the object by sending it by email with the mail compose message wizard
35+
This module extends the mail compose message wizard to allow selecting
36+
existing attachments when sending an email.
37+
38+
It provides two attachment selection mechanisms:
39+
40+
* Object Attachments — attachments linked to the current record.
41+
* Model Attachments — attachments linked to other records of the same model.
42+
43+
This makes it possible to reuse documents already stored on other
44+
records of the same model without re-uploading them.
3345

3446
**Table of contents**
3547

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

49-
* Then, by sending the object via email, you can select the attachment added earlier
61+
* Optionally, add attachments on other records of the same model
62+
(for example, on another Purchase Order or Partner record).
63+
64+
* Then, by sending the object via email, you can:
65+
66+
* Select attachments linked to the current object.
67+
* Select attachments linked to other records of the same model.
5068

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

5472
Known issues / Roadmap
5573
======================
5674

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

5977
Bug Tracker
6078
===========
@@ -74,6 +92,7 @@ Authors
7492

7593
* ACSONE SA/NV
7694
* Tecnativa
95+
* Therp BV
7796

7897
Contributors
7998
~~~~~~~~~~~~
@@ -84,6 +103,9 @@ Contributors
84103

85104
* Sergio Teruel
86105
* Ernesto Tejeda
106+
* `Therp BV <https://www.therp.nl>`_:
107+
108+
* Nikos Tsirintanis <ntsirintanis@therp.nl>
87109

88110
Maintainers
89111
~~~~~~~~~~~

mail_attach_existing_attachment/__manifest__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Copyright 2015 ACSONE SA/NV
2+
# Copyright 2026 Therp BV <https://therp.nl>.
23
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
34

45
{
56
"name": "Mail Attach Existing Attachment",
6-
"summary": "Adding attachment on the object by sending this one",
7-
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
7+
"summary": "Attach existing object or model attachments in mail composer",
8+
"author": "ACSONE SA/NV, Tecnativa, Therp BV, Odoo Community Association (OCA)",
89
"website": "https://github.com/OCA/social",
910
"category": "Social Network",
10-
"version": "16.0.1.1.0",
11+
"version": "16.0.2.0.0",
1112
"license": "AGPL-3",
1213
"depends": ["mail"],
1314
"data": ["wizard/mail_compose_message_view.xml"],

mail_attach_existing_attachment/readme/CONTRIBUTORS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44

55
* Sergio Teruel
66
* Ernesto Tejeda
7+
* `Therp BV <https://www.therp.nl>`_:
8+
9+
* Nikos Tsirintanis <ntsirintanis@therp.nl>
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
This module was written to add the possibility to add attachments located on
2-
the object by sending it by email with the mail compose message wizard
1+
This module extends the mail compose message wizard to allow selecting
2+
existing attachments when sending an email.
3+
4+
It provides two attachment selection mechanisms:
5+
6+
* Object Attachments — attachments linked to the current record.
7+
* Model Attachments — attachments linked to other records of the same model.
8+
9+
This makes it possible to reuse documents already stored on other
10+
records of the same model without re-uploading them.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* The module only allows the addition of attachments linked to the object.
1+
* Model attachments are filtered by model but not further restricted.

mail_attach_existing_attachment/readme/USAGE.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ To use this module, you need to:
55
.. figure:: ../static/description/attachment.png
66
:alt: Attachment on purchase order
77

8-
* Then, by sending the object via email, you can select the attachment added earlier
8+
* Optionally, add attachments on other records of the same model
9+
(for example, on another Purchase Order or Partner record).
10+
11+
* Then, by sending the object via email, you can:
12+
13+
* Select attachments linked to the current object.
14+
* Select attachments linked to other records of the same model.
915

1016
.. figure:: ../static/description/ex_mail_compose_message.png
1117
:alt: Sends the Purchase Order by email

mail_attach_existing_attachment/static/description/index.html

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>Mail Attach Existing Attachment</title>
6+
<title>README.rst</title>
77
<style type="text/css">
88

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

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -359,18 +360,30 @@
359360
</style>
360361
</head>
361362
<body>
362-
<div class="document" id="mail-attach-existing-attachment">
363-
<h1 class="title">Mail Attach Existing Attachment</h1>
363+
<div class="document">
364364

365+
366+
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367+
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368+
</a>
369+
<div class="section" id="mail-attach-existing-attachment">
370+
<h1>Mail Attach Existing Attachment</h1>
365371
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
366372
!! This file is generated by oca-gen-addon-readme !!
367373
!! changes will be overwritten. !!
368374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369375
!! source digest: sha256:ac2a9aa40b0d4a582c625061abbe71035a0b6c6421af29465d20d9e51dcfbda3
370376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371-
<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>
372-
<p>This module was written to add the possibility to add attachments located on
373-
the object by sending it by email with the mail compose message wizard</p>
377+
<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>
378+
<p>This module extends the mail compose message wizard to allow selecting
379+
existing attachments when sending an email.</p>
380+
<p>It provides two attachment selection mechanisms:</p>
381+
<ul class="simple">
382+
<li>Object Attachments — attachments linked to the current record.</li>
383+
<li>Model Attachments — attachments linked to other records of the same model.</li>
384+
</ul>
385+
<p>This makes it possible to reuse documents already stored on other
386+
records of the same model without re-uploading them.</p>
374387
<p><strong>Table of contents</strong></p>
375388
<div class="contents local topic" id="contents">
376389
<ul class="simple">
@@ -386,7 +399,7 @@ <h1 class="title">Mail Attach Existing Attachment</h1>
386399
</ul>
387400
</div>
388401
<div class="section" id="usage">
389-
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
402+
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
390403
<p>To use this module, you need to:</p>
391404
<ul class="simple">
392405
<li>Add some attachments on an object by creating a new <em>Log note</em></li>
@@ -395,37 +408,44 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
395408
<img alt="Attachment on purchase order" src="https://raw.githubusercontent.com/OCA/social/16.0/mail_attach_existing_attachment/static/description/attachment.png" />
396409
</div>
397410
<ul class="simple">
398-
<li>Then, by sending the object via email, you can select the attachment added earlier</li>
411+
<li>Optionally, add attachments on other records of the same model
412+
(for example, on another Purchase Order or Partner record).</li>
413+
<li>Then, by sending the object via email, you can:<ul>
414+
<li>Select attachments linked to the current object.</li>
415+
<li>Select attachments linked to other records of the same model.</li>
416+
</ul>
417+
</li>
399418
</ul>
400419
<div class="figure">
401420
<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" />
402421
</div>
403422
</div>
404423
<div class="section" id="known-issues-roadmap">
405-
<h1><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h1>
424+
<h2><a class="toc-backref" href="#toc-entry-2">Known issues / Roadmap</a></h2>
406425
<ul class="simple">
407-
<li>The module only allows the addition of attachments linked to the object.</li>
426+
<li>Model attachments are filtered by model but not further restricted.</li>
408427
</ul>
409428
</div>
410429
<div class="section" id="bug-tracker">
411-
<h1><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h1>
430+
<h2><a class="toc-backref" href="#toc-entry-3">Bug Tracker</a></h2>
412431
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
413432
In case of trouble, please check there if your issue has already been reported.
414433
If you spotted it first, help us to smash it by providing a detailed and welcomed
415434
<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>
416435
<p>Do not contact contributors directly about support or help with technical issues.</p>
417436
</div>
418437
<div class="section" id="credits">
419-
<h1><a class="toc-backref" href="#toc-entry-4">Credits</a></h1>
438+
<h2><a class="toc-backref" href="#toc-entry-4">Credits</a></h2>
420439
<div class="section" id="authors">
421-
<h2><a class="toc-backref" href="#toc-entry-5">Authors</a></h2>
440+
<h3><a class="toc-backref" href="#toc-entry-5">Authors</a></h3>
422441
<ul class="simple">
423442
<li>ACSONE SA/NV</li>
424443
<li>Tecnativa</li>
444+
<li>Therp BV</li>
425445
</ul>
426446
</div>
427447
<div class="section" id="contributors">
428-
<h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
448+
<h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
429449
<ul class="simple">
430450
<li>Adrien Peiffer &lt;<a class="reference external" href="mailto:adrien.peiffer&#64;acsone.eu">adrien.peiffer&#64;acsone.eu</a>&gt;</li>
431451
<li>Benoit Aimont &lt;<a class="reference external" href="mailto:benoit.aimont&#64;acsone.eu">benoit.aimont&#64;acsone.eu</a>&gt;</li>
@@ -434,12 +454,18 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
434454
<li>Ernesto Tejeda</li>
435455
</ul>
436456
</li>
457+
<li><a class="reference external" href="https://www.therp.nl">Therp BV</a>:<ul>
458+
<li>Nikos Tsirintanis &lt;<a class="reference external" href="mailto:ntsirintanis&#64;therp.nl">ntsirintanis&#64;therp.nl</a>&gt;</li>
459+
</ul>
460+
</li>
437461
</ul>
438462
</div>
439463
<div class="section" id="maintainers">
440-
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
464+
<h3><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h3>
441465
<p>This module is maintained by the OCA.</p>
442-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
466+
<a class="reference external image-reference" href="https://odoo-community.org">
467+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
468+
</a>
443469
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
444470
mission is to support the collaborative development of Odoo features and
445471
promote its widespread use.</p>
@@ -448,5 +474,6 @@ <h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
448474
</div>
449475
</div>
450476
</div>
477+
</div>
451478
</body>
452479
</html>

mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2015 ACSONE SA/NV
2+
# Copyright 2026 Therp BV <https://therp.nl>.
23
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
34

45
from odoo.tests import common
@@ -16,6 +17,14 @@ def setUp(self):
1617
"parent_id": False,
1718
}
1819
)
20+
self.partner_02 = self.env["res.partner"].create(
21+
{
22+
"name": "Partner 2",
23+
"email": "partner2@example.org",
24+
"is_company": True,
25+
"parent_id": False,
26+
}
27+
)
1928

2029
def test_send_email_attachment(self):
2130
attach1 = self.env["ir.attachment"].create(
@@ -26,12 +35,23 @@ def test_send_email_attachment(self):
2635
"res_id": self.partner_01.id,
2736
}
2837
)
38+
attach2 = self.env["ir.attachment"].create(
39+
{
40+
"name": "Attach2",
41+
"datas": "bW9kZWwgdGVzdA==",
42+
"res_model": "res.partner",
43+
"res_id": self.partner_02.id,
44+
}
45+
)
2946
vals = {
3047
"model": "res.partner",
3148
"partner_ids": [(6, 0, [self.partner_01.id])],
3249
"res_id": self.partner_01.id,
3350
"object_attachment_ids": [(6, 0, [attach1.id])],
51+
# NEW
52+
"model_attachment_ids": [(6, 0, [attach2.id])],
3453
}
3554
mail = self.env["mail.compose.message"].create(vals)
3655
values = mail.get_mail_values([self.partner_01.id])
3756
self.assertTrue(attach1.id in values[self.partner_01.id]["attachment_ids"])
57+
self.assertTrue(attach2.id in values[self.partner_01.id]["attachment_ids"])

mail_attach_existing_attachment/wizard/mail_compose_message.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright 2015 ACSONE SA/NV
2+
# Copyright 2026 Therp BV <https://therp.nl>.
23
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
34

45
from odoo import api, fields, models
@@ -27,11 +28,17 @@ def default_get(self, fields_list):
2728
column2="attachment_id",
2829
string="Object Attachments",
2930
)
31+
model_attachment_ids = fields.Many2many(
32+
comodel_name="ir.attachment",
33+
string="Model Attachments",
34+
)
3035

3136
def get_mail_values(self, res_ids):
3237
res = super().get_mail_values(res_ids)
33-
if self.object_attachment_ids.ids and self.model and len(res_ids) == 1:
34-
res[res_ids[0]].setdefault("attachment_ids", []).extend(
35-
self.object_attachment_ids.ids
36-
)
38+
if self.model and len(res_ids) == 1:
39+
attachment_ids = set(res[res_ids[0]].get("attachment_ids", []))
40+
attachment_ids.update(self.object_attachment_ids.ids)
41+
attachment_ids.update(self.model_attachment_ids.ids)
42+
if attachment_ids:
43+
res[res_ids[0]]["attachment_ids"] = list(attachment_ids)
3744
return res

mail_attach_existing_attachment/wizard/mail_compose_message_view.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
domain="[('res_model', '=', model), ('res_id', '=', res_id)]"
1616
attrs="{'invisible': [('can_attach_attachment', '=', False)]}"
1717
/>
18+
<field
19+
name="model_attachment_ids"
20+
widget="many2many_tags"
21+
options="{'no_create': True}"
22+
domain="[('res_model', '=', model), ('res_id', '!=', False), ('res_id', '!=', res_id)]"
23+
attrs="{'invisible': [('can_attach_attachment', '=', False)]}"
24+
/>
1825
</xpath>
1926
</field>
2027
</record>

0 commit comments

Comments
 (0)