diff --git a/product_attachment_zipped_download/README.rst b/product_attachment_zipped_download/README.rst new file mode 100644 index 00000000000..d001565b509 --- /dev/null +++ b/product_attachment_zipped_download/README.rst @@ -0,0 +1,87 @@ +================================== +Product Attachment Zipped Download +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:83ad066d1fff91f3a30547d9094b4d4bacd0e7614498a95854047bb2e9e52f0b + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/16.0/product_attachment_zipped_download + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-product_attachment_zipped_download + :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/product-attribute&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows the possibility to download attachments in a .zip file of the selected products. + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza + +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-victoralmau| image:: https://github.com/victoralmau.png?size=40px + :target: https://github.com/victoralmau + :alt: victoralmau + +Current `maintainer `__: + +|maintainer-victoralmau| + +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/product_attachment_zipped_download/__init__.py b/product_attachment_zipped_download/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/product_attachment_zipped_download/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_attachment_zipped_download/__manifest__.py b/product_attachment_zipped_download/__manifest__.py new file mode 100644 index 00000000000..85655731280 --- /dev/null +++ b/product_attachment_zipped_download/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Product Attachment Zipped Download", + "version": "16.0.1.0.0", + "category": "Product Management", + "website": "https://github.com/OCA/product-attribute", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["attachment_zipped_download", "product"], + "data": ["data/ir_actions_server_data.xml"], + "installable": True, + "maintainers": ["victoralmau"], +} diff --git a/product_attachment_zipped_download/data/ir_actions_server_data.xml b/product_attachment_zipped_download/data/ir_actions_server_data.xml new file mode 100644 index 00000000000..88b273208bc --- /dev/null +++ b/product_attachment_zipped_download/data/ir_actions_server_data.xml @@ -0,0 +1,26 @@ + + + + Download attachments + + + list,form + code + + action = records.action_download_attachments() + + + + Download attachments + + + list,form + code + + action = records.action_download_attachments() + + + diff --git a/product_attachment_zipped_download/i18n/es.po b/product_attachment_zipped_download/i18n/es.po new file mode 100644 index 00000000000..8cd23a023a4 --- /dev/null +++ b/product_attachment_zipped_download/i18n/es.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_attachment_zipped_download +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-04-15 07:00+0000\n" +"PO-Revision-Date: 2024-04-15 09:01+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 3.0.1\n" + +#. module: product_attachment_zipped_download +#: model:ir.actions.server,name:product_attachment_zipped_download.action_download_product_product_attachements +#: model:ir.actions.server,name:product_attachment_zipped_download.action_download_product_template_attachements +msgid "Download attachments" +msgstr "Descargar adjuntos" + +#. module: product_attachment_zipped_download +#: model:ir.model,name:product_attachment_zipped_download.model_product_product +#, fuzzy +msgid "Product" +msgstr "Producto" + +#. module: product_attachment_zipped_download +#: model:ir.model,name:product_attachment_zipped_download.model_product_template +msgid "Product Template" +msgstr "Plantilla de producto" diff --git a/product_attachment_zipped_download/i18n/product_attachment_zipped_download.pot b/product_attachment_zipped_download/i18n/product_attachment_zipped_download.pot new file mode 100644 index 00000000000..eb4b81b13ac --- /dev/null +++ b/product_attachment_zipped_download/i18n/product_attachment_zipped_download.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * product_attachment_zipped_download +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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: product_attachment_zipped_download +#: model:ir.actions.server,name:product_attachment_zipped_download.action_download_product_product_attachements +#: model:ir.actions.server,name:product_attachment_zipped_download.action_download_product_template_attachements +msgid "Download attachments" +msgstr "" + +#. module: product_attachment_zipped_download +#: model:ir.model,name:product_attachment_zipped_download.model_product_product +msgid "Product" +msgstr "" + +#. module: product_attachment_zipped_download +#: model:ir.model,name:product_attachment_zipped_download.model_product_template +msgid "Product Template" +msgstr "" diff --git a/product_attachment_zipped_download/models/__init__.py b/product_attachment_zipped_download/models/__init__.py new file mode 100644 index 00000000000..18b37e85320 --- /dev/null +++ b/product_attachment_zipped_download/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_product +from . import product_template diff --git a/product_attachment_zipped_download/models/product_product.py b/product_attachment_zipped_download/models/product_product.py new file mode 100644 index 00000000000..2b9ae061f02 --- /dev/null +++ b/product_attachment_zipped_download/models/product_product.py @@ -0,0 +1,23 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class Productproduct(models.Model): + _name = "product.product" + _inherit = ["product.product", "ir.attachment.action_download"] + + def _get_downloadable_attachments(self): + """Overwrite to get the attachments from template or variants.""" + return self.env["ir.attachment"].search( + [ + "|", + "&", + ("res_model", "=", "product.product"), + ("res_id", "in", self.ids), + "&", + ("res_model", "=", "product.template"), + ("res_id", "in", self.product_tmpl_id.ids), + ] + ) diff --git a/product_attachment_zipped_download/models/product_template.py b/product_attachment_zipped_download/models/product_template.py new file mode 100644 index 00000000000..077adf1a81c --- /dev/null +++ b/product_attachment_zipped_download/models/product_template.py @@ -0,0 +1,23 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ProductTemplate(models.Model): + _name = "product.template" + _inherit = ["product.template", "ir.attachment.action_download"] + + def _get_downloadable_attachments(self): + """Overwrite to get the attachments from template or variants.""" + return self.env["ir.attachment"].search( + [ + "|", + "&", + ("res_model", "=", "product.product"), + ("res_id", "in", self.product_variant_ids.ids), + "&", + ("res_model", "=", "product.template"), + ("res_id", "in", self.ids), + ] + ) diff --git a/product_attachment_zipped_download/readme/CONTRIBUTORS.rst b/product_attachment_zipped_download/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..5fb71305308 --- /dev/null +++ b/product_attachment_zipped_download/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Víctor Martínez + * Pedro M. Baeza diff --git a/product_attachment_zipped_download/readme/DESCRIPTION.rst b/product_attachment_zipped_download/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..3082a273671 --- /dev/null +++ b/product_attachment_zipped_download/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows the possibility to download attachments in a .zip file of the selected products. diff --git a/product_attachment_zipped_download/static/description/icon.png b/product_attachment_zipped_download/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_attachment_zipped_download/static/description/icon.png differ diff --git a/product_attachment_zipped_download/static/description/index.html b/product_attachment_zipped_download/static/description/index.html new file mode 100644 index 00000000000..603e89fb7eb --- /dev/null +++ b/product_attachment_zipped_download/static/description/index.html @@ -0,0 +1,426 @@ + + + + + +Product Attachment Zipped Download + + + +
+

Product Attachment Zipped Download

+ + +

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

+

This module allows the possibility to download attachments in a .zip file of the selected products.

+

Table of contents

+ +
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Víctor Martínez
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

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 maintainer:

+

victoralmau

+

This module is part of the OCA/product-attribute project on GitHub.

+

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

+
+
+
+ + diff --git a/product_attachment_zipped_download/tests/__init__.py b/product_attachment_zipped_download/tests/__init__.py new file mode 100644 index 00000000000..2474da3059c --- /dev/null +++ b/product_attachment_zipped_download/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) + +from . import test_product_attachment_zipped_download diff --git a/product_attachment_zipped_download/tests/test_product_attachment_zipped_download.py b/product_attachment_zipped_download/tests/test_product_attachment_zipped_download.py new file mode 100644 index 00000000000..2208e9458c6 --- /dev/null +++ b/product_attachment_zipped_download/tests/test_product_attachment_zipped_download.py @@ -0,0 +1,99 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import TransactionCase + +from odoo.addons.attachment_zipped_download.tests.test_attachment_zipped_download import ( + TestAttachmentZippedDownloadBase, +) + + +class TestProductAttachmentZippedDownload( + TransactionCase, TestAttachmentZippedDownloadBase +): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product_a = cls.env["product.product"].create({"name": "Test product A"}) + cls.product_b = cls.env["product.product"].create({"name": "Test product B"}) + cls.product_c = cls.env["product.product"].create({"name": "Test product C"}) + cls.attachment_a = cls._create_attachment( + cls.env, + cls.env.uid, + "product-a.txt", + model=cls.product_a._name, + res_id=cls.product_a.id, + ) + cls.attachment_b = cls._create_attachment( + cls.env, + cls.env.uid, + "product-b.txt", + model=cls.product_b._name, + res_id=cls.product_b.id, + ) + cls.attachment_b_extra = cls._create_attachment( + cls.env, + cls.env.uid, + "product-template-b.txt", + model=cls.product_b.product_tmpl_id._name, + res_id=cls.product_b.product_tmpl_id.id, + ) + + def test_action_download_attachments_no_attachment(self): + action = self.product_c.product_tmpl_id.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.client") + self.assertEqual(action["tag"], "display_notification") + action = self.product_c.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.client") + self.assertEqual(action["tag"], "display_notification") + + def test_action_download_attachments_one_attachment_1(self): + action = self.product_a.product_tmpl_id.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.act_url") + self.assertEqual(action["target"], "self") + self.assertEqual( + action["url"], "/web/content/%s?download=1" % self.attachment_a.id + ) + action = self.product_a.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.act_url") + self.assertEqual(action["target"], "self") + self.assertEqual( + action["url"], "/web/content/%s?download=1" % self.attachment_a.id + ) + + def test_action_download_attachments_one_attachment_2(self): + action = self.product_b.product_tmpl_id.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.act_url") + self.assertEqual(action["target"], "self") + self.assertTrue(action["url"].startswith("/web/attachment/download_zip?ids=")) + attachment_ids = sorted(map(int, action["url"].split("=")[1].split(","))) + self.assertNotIn(self.attachment_a.id, attachment_ids) + self.assertIn(self.attachment_b.id, attachment_ids) + self.assertIn(self.attachment_b_extra.id, attachment_ids) + action = self.product_b.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.act_url") + self.assertEqual(action["target"], "self") + self.assertTrue(action["url"].startswith("/web/attachment/download_zip?ids=")) + attachment_ids = sorted(map(int, action["url"].split("=")[1].split(","))) + self.assertNotIn(self.attachment_a.id, attachment_ids) + self.assertIn(self.attachment_b.id, attachment_ids) + self.assertIn(self.attachment_b_extra.id, attachment_ids) + + def test_action_download_attachments_multi_attachment(self): + products = self.product_a + self.product_b + self.product_c + product_templates = products.mapped("product_tmpl_id") + action = product_templates.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.act_url") + self.assertEqual(action["target"], "self") + self.assertTrue(action["url"].startswith("/web/attachment/download_zip?ids=")) + attachment_ids = sorted(map(int, action["url"].split("=")[1].split(","))) + self.assertIn(self.attachment_a.id, attachment_ids) + self.assertIn(self.attachment_b.id, attachment_ids) + self.assertIn(self.attachment_b_extra.id, attachment_ids) + action = products.action_download_attachments() + self.assertEqual(action["type"], "ir.actions.act_url") + self.assertEqual(action["target"], "self") + self.assertTrue(action["url"].startswith("/web/attachment/download_zip?ids=")) + attachment_ids = sorted(map(int, action["url"].split("=")[1].split(","))) + self.assertIn(self.attachment_a.id, attachment_ids) + self.assertIn(self.attachment_b.id, attachment_ids) + self.assertIn(self.attachment_b_extra.id, attachment_ids) diff --git a/setup/product_attachment_zipped_download/odoo/addons/product_attachment_zipped_download b/setup/product_attachment_zipped_download/odoo/addons/product_attachment_zipped_download new file mode 120000 index 00000000000..f5d4f868484 --- /dev/null +++ b/setup/product_attachment_zipped_download/odoo/addons/product_attachment_zipped_download @@ -0,0 +1 @@ +../../../../product_attachment_zipped_download \ No newline at end of file diff --git a/setup/product_attachment_zipped_download/setup.py b/setup/product_attachment_zipped_download/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/product_attachment_zipped_download/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)