diff --git a/mail_attach_existing_attachment/README.rst b/mail_attach_existing_attachment/README.rst index bc5c76d59f..179056eca0 100644 --- a/mail_attach_existing_attachment/README.rst +++ b/mail_attach_existing_attachment/README.rst @@ -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 =============================== @@ -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 @@ -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** @@ -46,7 +58,13 @@ 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 @@ -54,7 +72,7 @@ To use this module, you need to: 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 =========== @@ -74,6 +92,7 @@ Authors * ACSONE SA/NV * Tecnativa +* Therp BV Contributors ~~~~~~~~~~~~ @@ -84,6 +103,9 @@ Contributors * Sergio Teruel * Ernesto Tejeda +* `Therp BV `_: + + * Nikos Tsirintanis Maintainers ~~~~~~~~~~~ diff --git a/mail_attach_existing_attachment/__manifest__.py b/mail_attach_existing_attachment/__manifest__.py index 16446dd3f0..b2bfea8c0e 100644 --- a/mail_attach_existing_attachment/__manifest__.py +++ b/mail_attach_existing_attachment/__manifest__.py @@ -1,13 +1,14 @@ # Copyright 2015 ACSONE SA/NV +# Copyright 2026 Therp BV . # 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"], diff --git a/mail_attach_existing_attachment/readme/CONTRIBUTORS.rst b/mail_attach_existing_attachment/readme/CONTRIBUTORS.rst index 4113412635..bfd1821df4 100644 --- a/mail_attach_existing_attachment/readme/CONTRIBUTORS.rst +++ b/mail_attach_existing_attachment/readme/CONTRIBUTORS.rst @@ -4,3 +4,6 @@ * Sergio Teruel * Ernesto Tejeda +* `Therp BV `_: + + * Nikos Tsirintanis diff --git a/mail_attach_existing_attachment/readme/DESCRIPTION.rst b/mail_attach_existing_attachment/readme/DESCRIPTION.rst index 189719c21e..ae6c369062 100644 --- a/mail_attach_existing_attachment/readme/DESCRIPTION.rst +++ b/mail_attach_existing_attachment/readme/DESCRIPTION.rst @@ -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. diff --git a/mail_attach_existing_attachment/readme/ROADMAP.rst b/mail_attach_existing_attachment/readme/ROADMAP.rst index 5d24095fd1..12725394b8 100644 --- a/mail_attach_existing_attachment/readme/ROADMAP.rst +++ b/mail_attach_existing_attachment/readme/ROADMAP.rst @@ -1 +1 @@ -* The module only allows the addition of attachments linked to the object. +* Model attachments are filtered by model but not further restricted. diff --git a/mail_attach_existing_attachment/readme/USAGE.rst b/mail_attach_existing_attachment/readme/USAGE.rst index 68fac75449..040d6ba095 100644 --- a/mail_attach_existing_attachment/readme/USAGE.rst +++ b/mail_attach_existing_attachment/readme/USAGE.rst @@ -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 diff --git a/mail_attach_existing_attachment/static/description/index.html b/mail_attach_existing_attachment/static/description/index.html index a798469614..a36cf584bd 100644 --- a/mail_attach_existing_attachment/static/description/index.html +++ b/mail_attach_existing_attachment/static/description/index.html @@ -3,15 +3,16 @@ -Mail Attach Existing Attachment +README.rst -
-

Mail Attach Existing Attachment

+
+ + +Odoo Community Association + +
+

Mail Attach Existing Attachment

-

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

-

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

+

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

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

    @@ -386,7 +399,7 @@

    Mail Attach Existing Attachment

-

Usage

+

Usage

To use this module, you need to:

  • Add some attachments on an object by creating a new Log note
  • @@ -395,20 +408,26 @@

    Usage

    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.
    • +
    +
Sends the Purchase Order by email
-

Known issues / Roadmap

+

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

+

Bug Tracker

Bugs are tracked on GitHub Issues. 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 @@ -416,16 +435,17 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • ACSONE SA/NV
  • Tecnativa
  • +
  • Therp BV
-

Contributors

+

Contributors

+
  • Therp BV: +
  • -

    Maintainers

    +

    Maintainers

    This module is maintained by the OCA.

    -Odoo Community Association + +Odoo Community Association +

    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.

    @@ -448,5 +474,6 @@

    Maintainers

    +
    diff --git a/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py b/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py index d762a36b7a..4117d7130b 100644 --- a/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py +++ b/mail_attach_existing_attachment/tests/test_mail_attach_existing_attachment.py @@ -1,4 +1,5 @@ # Copyright 2015 ACSONE SA/NV +# Copyright 2026 Therp BV . # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo.tests import common @@ -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( @@ -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"]) diff --git a/mail_attach_existing_attachment/wizard/mail_compose_message.py b/mail_attach_existing_attachment/wizard/mail_compose_message.py index 671bb987c7..ab8df6d1ff 100644 --- a/mail_attach_existing_attachment/wizard/mail_compose_message.py +++ b/mail_attach_existing_attachment/wizard/mail_compose_message.py @@ -1,4 +1,5 @@ # Copyright 2015 ACSONE SA/NV +# Copyright 2026 Therp BV . # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import api, fields, models @@ -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 diff --git a/mail_attach_existing_attachment/wizard/mail_compose_message_view.xml b/mail_attach_existing_attachment/wizard/mail_compose_message_view.xml index 9e5efdedd5..16fe35e5a4 100644 --- a/mail_attach_existing_attachment/wizard/mail_compose_message_view.xml +++ b/mail_attach_existing_attachment/wizard/mail_compose_message_view.xml @@ -15,6 +15,13 @@ domain="[('res_model', '=', model), ('res_id', '=', res_id)]" attrs="{'invisible': [('can_attach_attachment', '=', False)]}" /> +