diff --git a/mail_attach_existing_attachment_account/README.rst b/mail_attach_existing_attachment_account/README.rst new file mode 100644 index 000000000..bc4dfb87e --- /dev/null +++ b/mail_attach_existing_attachment_account/README.rst @@ -0,0 +1,107 @@ +.. 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 (Account) +========================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:cfe4cc384af8ee475e5a4ef3c6abe6ac99140fa4fbc19deba6d2df07a553a78b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/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%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/20.0/mail_attach_existing_attachment_account + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-20-0/mail-20-0-mail_attach_existing_attachment_account + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=20.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This Module adds the mail_attach_existing_attachment feature to the +account module, since there is a change in odoo 12.0, which adds a new +mail wizard form to the account module + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +- On invoices, only some supported document types are linked to the + document. The default supported types are PDF, CSV, Excel/OpenDocument + spreadsheets, Word/OpenDocument documents, PowerPoint/OpenDocument + presentations, and parseable XML files. Chatter-only attachments are + therefore not selectable by this module. + +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 +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Thore Baden + +Contributors +------------ + +- Thore Baden +- `Tecnativa `__: + + - Víctor Martínez + - Ernesto Tejeda + - Carlos Lopez + +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-chienandalu| image:: https://github.com/chienandalu.png?size=40px + :target: https://github.com/chienandalu + :alt: chienandalu +.. |maintainer-rafaelbn| image:: https://github.com/rafaelbn.png?size=40px + :target: https://github.com/rafaelbn + :alt: rafaelbn + +Current `maintainers `__: + +|maintainer-chienandalu| |maintainer-rafaelbn| + +This module is part of the `OCA/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_attach_existing_attachment_account/__init__.py b/mail_attach_existing_attachment_account/__init__.py new file mode 100644 index 000000000..78695683c --- /dev/null +++ b/mail_attach_existing_attachment_account/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import wizard diff --git a/mail_attach_existing_attachment_account/__manifest__.py b/mail_attach_existing_attachment_account/__manifest__.py new file mode 100644 index 000000000..acb35cd86 --- /dev/null +++ b/mail_attach_existing_attachment_account/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2019 Thore Baden +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Mail Attach Existing Attachment (Account)", + "summary": "Module to use attach existing attachment for account module", + "author": "Thore Baden, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/mail", + "category": "Social Network", + "version": "20.0.1.0.0", + "license": "AGPL-3", + "maintainers": ["chienandalu", "rafaelbn"], + "depends": ["account", "mail_attach_existing_attachment"], + "data": ["wizard/account_move_send_wizard_view.xml"], + "installable": True, + "auto_install": True, +} diff --git a/mail_attach_existing_attachment_account/i18n/it.po b/mail_attach_existing_attachment_account/i18n/it.po new file mode 100644 index 000000000..024ab3d36 --- /dev/null +++ b/mail_attach_existing_attachment_account/i18n/it.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_attach_existing_attachment_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-12-19 10:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model,name:mail_attach_existing_attachment_account.model_account_invoice_send +msgid "Account Invoice Send" +msgstr "Conto invio fattura" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model.fields,field_description:mail_attach_existing_attachment_account.field_account_invoice_send__can_attach_attachment +msgid "Can Attach Attachment" +msgstr "Può inserire allegati" diff --git a/mail_attach_existing_attachment_account/i18n/mail_attach_existing_attachment_account.pot b/mail_attach_existing_attachment_account/i18n/mail_attach_existing_attachment_account.pot new file mode 100644 index 000000000..2deecc6d4 --- /dev/null +++ b/mail_attach_existing_attachment_account/i18n/mail_attach_existing_attachment_account.pot @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_attach_existing_attachment_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 19.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model,name:mail_attach_existing_attachment_account.model_account_move_send_wizard +msgid "Account Move Send Wizard" +msgstr "" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model.fields,field_description:mail_attach_existing_attachment_account.field_account_move_send_wizard__can_attach_attachment +msgid "Can Attach Attachment" +msgstr "" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model.fields,field_description:mail_attach_existing_attachment_account.field_account_move_send_wizard__display_name +msgid "Display Name" +msgstr "" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model.fields,field_description:mail_attach_existing_attachment_account.field_account_move_send_wizard__display_object_attachment_ids +msgid "Display Object Attachment" +msgstr "" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model.fields,field_description:mail_attach_existing_attachment_account.field_account_move_send_wizard__id +msgid "ID" +msgstr "" + +#. module: mail_attach_existing_attachment_account +#: model:ir.model.fields,field_description:mail_attach_existing_attachment_account.field_account_move_send_wizard__object_attachment_ids +msgid "Object Attachments" +msgstr "" diff --git a/mail_attach_existing_attachment_account/pyproject.toml b/mail_attach_existing_attachment_account/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_attach_existing_attachment_account/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_attach_existing_attachment_account/readme/CONTRIBUTORS.md b/mail_attach_existing_attachment_account/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..75dd8847c --- /dev/null +++ b/mail_attach_existing_attachment_account/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- Thore Baden \ +- [Tecnativa](https://www.tecnativa.com): + - Víctor Martínez + - Ernesto Tejeda + - Carlos Lopez diff --git a/mail_attach_existing_attachment_account/readme/DESCRIPTION.md b/mail_attach_existing_attachment_account/readme/DESCRIPTION.md new file mode 100644 index 000000000..6fb430e40 --- /dev/null +++ b/mail_attach_existing_attachment_account/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This Module adds the mail_attach_existing_attachment feature to the +account module, since there is a change in odoo 12.0, which adds a new +mail wizard form to the account module diff --git a/mail_attach_existing_attachment_account/readme/ROADMAP.md b/mail_attach_existing_attachment_account/readme/ROADMAP.md new file mode 100644 index 000000000..c8b54c98a --- /dev/null +++ b/mail_attach_existing_attachment_account/readme/ROADMAP.md @@ -0,0 +1,5 @@ +- On invoices, only some supported document types are linked to the document. The + default supported types are PDF, CSV, Excel/OpenDocument spreadsheets, + Word/OpenDocument documents, PowerPoint/OpenDocument presentations, and + parseable XML files. Chatter-only attachments are therefore not selectable + by this module. diff --git a/mail_attach_existing_attachment_account/static/description/icon.png b/mail_attach_existing_attachment_account/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_attach_existing_attachment_account/static/description/icon.png differ diff --git a/mail_attach_existing_attachment_account/static/description/index.html b/mail_attach_existing_attachment_account/static/description/index.html new file mode 100644 index 000000000..154ca25ae --- /dev/null +++ b/mail_attach_existing_attachment_account/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +Mail Attach Existing Attachment (Account) + + + +
+ + + +Odoo Community Association + +
+

Mail Attach Existing Attachment (Account)

+ +

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

+

This Module adds the mail_attach_existing_attachment feature to the +account module, since there is a change in odoo 12.0, which adds a new +mail wizard form to the account module

+

Table of contents

+ +
+

Known issues / Roadmap

+
    +
  • On invoices, only some supported document types are linked to the +document. The default supported types are PDF, CSV, Excel/OpenDocument +spreadsheets, Word/OpenDocument documents, PowerPoint/OpenDocument +presentations, and parseable XML files. Chatter-only attachments are +therefore not selectable by this module.
  • +
+
+
+

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 +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Thore Baden
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +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.

+

Current maintainers:

+

chienandalu rafaelbn

+

This module is part of the OCA/mail project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/mail_attach_existing_attachment_account/tests/__init__.py b/mail_attach_existing_attachment_account/tests/__init__.py new file mode 100644 index 000000000..277c7fbde --- /dev/null +++ b/mail_attach_existing_attachment_account/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_attach_existing_attachment_account diff --git a/mail_attach_existing_attachment_account/tests/test_mail_attach_existing_attachment_account.py b/mail_attach_existing_attachment_account/tests/test_mail_attach_existing_attachment_account.py new file mode 100644 index 000000000..19f017f01 --- /dev/null +++ b/mail_attach_existing_attachment_account/tests/test_mail_attach_existing_attachment_account.py @@ -0,0 +1,68 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo.tests import Form + +from odoo.addons.base.tests.common import BaseCommon + + +class TestMailAttachExistingAttachmentAccount(BaseCommon): + _test_user_groups = ("account.group_account_invoice",) + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.env["product.product"].create({"name": "Test product"}) + cls.partner = cls.env["res.partner"].create( + {"name": "Mr. Odoo", "email": "mr.odoo@example.org"} + ) + cls.journal = cls.env["account.journal"].create( + {"name": "Test sale journal", "code": "TSALE", "type": "sale"} + ) + invoice_form = Form( + cls.env["account.move"].with_context(default_move_type="out_invoice") + ) + invoice_form.partner_id = cls.partner + with invoice_form.invoice_line_ids.new() as line_form: + line_form.product_id = cls.product + cls.invoice = invoice_form.save() + cls.invoice.action_post() + cls.attachment = cls.env["ir.attachment"].create( + { + "name": "Existing attachment.pdf", + "raw": b"%PDF-1.4 migration test", + "res_model": cls.invoice._name, + "res_id": cls.invoice.id, + } + ) + + def test_account_invoice_send(self): + compose = Form( + self.env["account.move.send.wizard"].with_context( + active_ids=self.invoice.ids, + default_model=self.invoice._name, + default_res_id=self.invoice.id, + default_res_model=self.invoice._name, + ) + ) + self.assertTrue(compose.can_attach_attachment) + wizard = compose.save() + self.assertEqual(wizard.display_object_attachment_ids, self.attachment) + wizard.move_id = False + self.assertFalse(wizard.display_object_attachment_ids) + + def test_account_invoice_send_object_attachment(self): + compose = Form( + self.env["account.move.send.wizard"].with_context( + active_ids=self.invoice.ids, + active_model=self.invoice._name, + ) + ) + compose.object_attachment_ids = self.attachment + wizard = compose.save() + wizard.action_send_and_print() + # Attachments are sent as copies linked to the posted message + message = self.invoice.message_ids.filtered("attachment_ids")[:1] + sent_attachment = message.attachment_ids.filtered( + lambda att: att.name == self.attachment.name + ) + self.assertEqual(sent_attachment.checksum, self.attachment.checksum) diff --git a/mail_attach_existing_attachment_account/wizard/__init__.py b/mail_attach_existing_attachment_account/wizard/__init__.py new file mode 100644 index 000000000..589b902be --- /dev/null +++ b/mail_attach_existing_attachment_account/wizard/__init__.py @@ -0,0 +1 @@ +from . import account_move_send_wizard diff --git a/mail_attach_existing_attachment_account/wizard/account_move_send_wizard.py b/mail_attach_existing_attachment_account/wizard/account_move_send_wizard.py new file mode 100644 index 000000000..975f7f497 --- /dev/null +++ b/mail_attach_existing_attachment_account/wizard/account_move_send_wizard.py @@ -0,0 +1,48 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountMoveSendWizard(models.TransientModel): + _inherit = "account.move.send.wizard" + + can_attach_attachment = fields.Boolean() + object_attachment_ids = fields.Many2many( + comodel_name="ir.attachment", + relation="account_move_send_wizard_ir_attachments_object_rel", + column1="wizard_id", + column2="attachment_id", + string="Object Attachments", + ) + display_object_attachment_ids = fields.One2many( + comodel_name="ir.attachment", + compute="_compute_display_object_attachment_ids", + ) + + @api.depends("move_id") + def _compute_display_object_attachment_ids(self): + for wizard in self: + if wizard.move_id: + attachments = self.env["ir.attachment"].search( + [ + ("res_model", "=", "account.move"), + ("res_id", "=", wizard.move_id.id), + ] + ) + wizard.display_object_attachment_ids = attachments + else: + wizard.display_object_attachment_ids = False + + @api.model + def _get_invoice_extra_attachments(self, move): + res = super()._get_invoice_extra_attachments(move) + res |= self.object_attachment_ids + return res + + @api.model + def default_get(self, fields_list): + res = super().default_get(fields_list) + if res.get("move_id") and not res.get("can_attach_attachment"): + res["can_attach_attachment"] = True # pragma: no cover + return res diff --git a/mail_attach_existing_attachment_account/wizard/account_move_send_wizard_view.xml b/mail_attach_existing_attachment_account/wizard/account_move_send_wizard_view.xml new file mode 100644 index 000000000..7efdb91d3 --- /dev/null +++ b/mail_attach_existing_attachment_account/wizard/account_move_send_wizard_view.xml @@ -0,0 +1,23 @@ + + + + + account.move.send.wizard.form + account.move.send.wizard + + + + + + + + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..03c6a589c --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-mail_attach_existing_attachment @ git+https://github.com/OCA/mail.git@refs/pull/325/head#subdirectory=mail_attach_existing_attachment