diff --git a/attachment_zipped_download/README.rst b/attachment_zipped_download/README.rst
index b20ddf09..80f2bf69 100644
--- a/attachment_zipped_download/README.rst
+++ b/attachment_zipped_download/README.rst
@@ -2,10 +2,13 @@
Attachment Zipped Download
==========================
-.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+..
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ !! source digest: sha256:ff7e96407afd1498d4d7a92046727ac078de41e9e3789dcbe61c469b4b13ae67
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
@@ -19,14 +22,17 @@ Attachment Zipped Download
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/knowledge-16-0/knowledge-16-0-attachment_zipped_download
:alt: Translate me on Weblate
-.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
- :target: https://runbot.odoo-community.org/runbot/118/16.0
- :alt: Try me on Runbot
+.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/knowledge&target_branch=16.0
+ :alt: Try me on Runboat
-|badge1| |badge2| |badge3| |badge4| |badge5|
+|badge1| |badge2| |badge3| |badge4| |badge5|
This module allows downloading multiple attachments as a zip file.
+This also provide a helper class `IrAttachmentActionDownloadMixin`
+to be used by developer to add action method on models.
+
**Table of contents**
.. contents::
@@ -38,12 +44,88 @@ Usage
#. Go to *Settings > Technical > Database Structure > Attachments* and select some files.
#. Go to *Actions > Download* and a zip file containing the selected files will be downloaded.
+## For developer
+
+You can reuse the `IrAttachmentActionDownloadMixin` on your
+favorite models::
+
+ from odoo import models
+
+
+ class StockPicking(models.Model):
+ _name = "stock.picking"
+ _inherit = ["stock.picking", "ir.attachment.action_download"]
+
+
+Then you can add an action button on list view line or on the action button
+(when multiple lines are selected) to download all files::
+
+
+
+
+
+ stock.picking.tree download attachments
+ stock.picking
+
+
+
+
+
+
+
+
+
+ Download attachments
+
+
+ list
+ code
+
+ action = records.action_download_attachments()
+
+
+
+
+
+.. note::
+
+ Even you will be able to generate a zip file with multiple document with the
+ same name it's advice to overwrite `_compute_zip_file_name` to improve the
+ name. When a slash (`/`) is present in the path it will create a directory.
+ This example will create a directory per stock.picking using its name::
+
+ class IrAttachment(models.Model):
+ _inherit = "ir.attachment"
+
+ def _compute_zip_file_name(self):
+ self.ensure_one()
+ if self.res_model and self.res_model == "stock.picking":
+ return (
+ self.env[self.res_model]
+ .browse(self.res_id)
+ .display_name.replace("/", "-")
+ + "/"
+ + self.name
+ )
+ return super()._compute_zip_file_name()
+
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 smashing it by providing a detailed and welcomed
+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.
@@ -66,6 +148,8 @@ Contributors
* Víctor Martínez
* Pedro M. Baeza
+* Pierre Verkest
+
Maintainers
~~~~~~~~~~~
diff --git a/attachment_zipped_download/__manifest__.py b/attachment_zipped_download/__manifest__.py
index 209dc5e5..ed6ac02b 100644
--- a/attachment_zipped_download/__manifest__.py
+++ b/attachment_zipped_download/__manifest__.py
@@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Attachment Zipped Download",
- "version": "16.0.1.0.2",
+ "version": "16.0.2.0.0",
"category": "Tools",
"website": "https://github.com/OCA/knowledge",
"author": "Tecnativa, Odoo Community Association (OCA)",
diff --git a/attachment_zipped_download/i18n/attachment_zipped_download.pot b/attachment_zipped_download/i18n/attachment_zipped_download.pot
index 7cd8b6de..5e0822ef 100644
--- a/attachment_zipped_download/i18n/attachment_zipped_download.pot
+++ b/attachment_zipped_download/i18n/attachment_zipped_download.pot
@@ -13,6 +13,14 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
+#. module: attachment_zipped_download
+#: model:ir.model,name:attachment_zipped_download.model_ir_attachment_action_download
+msgid ""
+"\n"
+" Mixin to help download attachments linked to record(s).\n"
+" "
+msgstr ""
+
#. module: attachment_zipped_download
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment
msgid "Attachment"
@@ -23,6 +31,13 @@ msgstr ""
msgid "Download"
msgstr ""
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "No attachment!"
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/models/ir_attachment.py:0
@@ -30,6 +45,13 @@ msgstr ""
msgid "None attachment selected. Only binary attachments allowed."
msgstr ""
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "There is no document found to download."
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/controllers/main.py:0
diff --git a/attachment_zipped_download/i18n/es.po b/attachment_zipped_download/i18n/es.po
index 840609d9..db5bb6bf 100644
--- a/attachment_zipped_download/i18n/es.po
+++ b/attachment_zipped_download/i18n/es.po
@@ -17,6 +17,14 @@ msgstr ""
"Plural-Forms: \n"
"X-Generator: Poedit 2.3\n"
+#. module: attachment_zipped_download
+#: model:ir.model,name:attachment_zipped_download.model_ir_attachment_action_download
+msgid ""
+"\n"
+" Mixin to help download attachments linked to record(s).\n"
+" "
+msgstr ""
+
#. module: attachment_zipped_download
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment
msgid "Attachment"
@@ -27,6 +35,13 @@ msgstr "Adjunto"
msgid "Download"
msgstr "Descargar"
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "No attachment!"
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/models/ir_attachment.py:0
@@ -36,6 +51,13 @@ msgstr ""
"No se seleccionó ningún archivo adjunto. Solo se permiten archivos adjuntos "
"binarios."
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "There is no document found to download."
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/controllers/main.py:0
diff --git a/attachment_zipped_download/i18n/fr.po b/attachment_zipped_download/i18n/fr.po
new file mode 100644
index 00000000..8941c643
--- /dev/null
+++ b/attachment_zipped_download/i18n/fr.po
@@ -0,0 +1,78 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * attachment_zipped_download
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 14.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: attachment_zipped_download
+#: model:ir.model,name:attachment_zipped_download.model_ir_attachment_action_download
+msgid ""
+"\n"
+" Mixin to help download attachments linked to record(s).\n"
+" "
+msgstr "Mixin pour faciliter le téléchargements des pièces jointes lié aux enregistrements."
+
+#. module: attachment_zipped_download
+#: model:ir.model,name:attachment_zipped_download.model_ir_attachment
+msgid "Attachment"
+msgstr "Pièce jointe"
+
+#. module: attachment_zipped_download
+#: model:ir.model.fields,field_description:attachment_zipped_download.field_ir_attachment__display_name
+#: model:ir.model.fields,field_description:attachment_zipped_download.field_ir_attachment_action_download__display_name
+msgid "Display Name"
+msgstr "Nom affiché"
+
+#. module: attachment_zipped_download
+#: model:ir.actions.server,name:attachment_zipped_download.action_attachments_download
+msgid "Download"
+msgstr "Télécharger"
+
+#. module: attachment_zipped_download
+#: model:ir.model.fields,field_description:attachment_zipped_download.field_ir_attachment__id
+#: model:ir.model.fields,field_description:attachment_zipped_download.field_ir_attachment_action_download__id
+msgid "ID"
+msgstr ""
+
+#. module: attachment_zipped_download
+#: model:ir.model.fields,field_description:attachment_zipped_download.field_ir_attachment____last_update
+#: model:ir.model.fields,field_description:attachment_zipped_download.field_ir_attachment_action_download____last_update
+msgid "Last Modified on"
+msgstr "Dernière modification le"
+
+#. module: attachment_zipped_download
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#: code:addons/src/knowledge/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "No attachment!"
+msgstr "Aucune pièce jointe !"
+
+#. module: attachment_zipped_download
+#: code:addons/attachment_zipped_download/models/ir_attachment.py:0
+#: code:addons/src/knowledge/attachment_zipped_download/models/ir_attachment.py:0
+#, python-format
+msgid "None attachment selected. Only binary attachments allowed."
+msgstr "Aucune pièce jointe sélectionnée. Seul les picèces jointes de type Binaire sont permises."
+
+#. module: attachment_zipped_download
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#: code:addons/src/knowledge/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "There is no document found to download."
+msgstr "Aucune pièce jointe téléchargeable trouvé."
+
+#. module: attachment_zipped_download
+#: code:addons/attachment_zipped_download/controllers/main.py:0
+#: code:addons/src/knowledge/attachment_zipped_download/controllers/main.py:0
+#, python-format
+msgid "attachments.zip"
+msgstr "pieces-jointes.zip"
diff --git a/attachment_zipped_download/i18n/hr.po b/attachment_zipped_download/i18n/hr.po
index e835301e..cbc23ed2 100644
--- a/attachment_zipped_download/i18n/hr.po
+++ b/attachment_zipped_download/i18n/hr.po
@@ -17,6 +17,14 @@ msgstr ""
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 4.14.1\n"
+#. module: attachment_zipped_download
+#: model:ir.model,name:attachment_zipped_download.model_ir_attachment_action_download
+msgid ""
+"\n"
+" Mixin to help download attachments linked to record(s).\n"
+" "
+msgstr ""
+
#. module: attachment_zipped_download
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment
msgid "Attachment"
@@ -27,6 +35,13 @@ msgstr "Prilog"
msgid "Download"
msgstr "Preuzimanje"
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "No attachment!"
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/models/ir_attachment.py:0
@@ -34,6 +49,13 @@ msgstr "Preuzimanje"
msgid "None attachment selected. Only binary attachments allowed."
msgstr "Nema odabranih priloga. Samo binarni prilozi su dozvoljeni."
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "There is no document found to download."
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/controllers/main.py:0
diff --git a/attachment_zipped_download/i18n/it.po b/attachment_zipped_download/i18n/it.po
index 6b4ad299..96a1f285 100644
--- a/attachment_zipped_download/i18n/it.po
+++ b/attachment_zipped_download/i18n/it.po
@@ -16,6 +16,14 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.14.1\n"
+#. module: attachment_zipped_download
+#: model:ir.model,name:attachment_zipped_download.model_ir_attachment_action_download
+msgid ""
+"\n"
+" Mixin to help download attachments linked to record(s).\n"
+" "
+msgstr ""
+
#. module: attachment_zipped_download
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment
msgid "Attachment"
@@ -26,6 +34,13 @@ msgstr "Allegato"
msgid "Download"
msgstr "Scarica"
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "No attachment!"
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/models/ir_attachment.py:0
@@ -33,9 +48,25 @@ msgstr "Scarica"
msgid "None attachment selected. Only binary attachments allowed."
msgstr "Nessun allegato selezionato. Consentiti solo allegati binari."
+#. module: attachment_zipped_download
+#. odoo-python
+#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
+#, python-format
+msgid "There is no document found to download."
+msgstr ""
+
#. module: attachment_zipped_download
#. odoo-python
#: code:addons/attachment_zipped_download/controllers/main.py:0
#, python-format
msgid "attachments.zip"
msgstr "attachments.zip"
+
+#~ msgid "Display Name"
+#~ msgstr "Nome visualizzato"
+
+#~ msgid "ID"
+#~ msgstr "ID"
+
+#~ msgid "Last Modified on"
+#~ msgstr "Ultima modifica il"
diff --git a/attachment_zipped_download/models/__init__.py b/attachment_zipped_download/models/__init__.py
index aaf38a16..adb66482 100644
--- a/attachment_zipped_download/models/__init__.py
+++ b/attachment_zipped_download/models/__init__.py
@@ -1 +1,2 @@
from . import ir_attachment
+from . import ir_attachment_action_download
diff --git a/attachment_zipped_download/models/ir_attachment_action_download.py b/attachment_zipped_download/models/ir_attachment_action_download.py
new file mode 100644
index 00000000..4316b4cb
--- /dev/null
+++ b/attachment_zipped_download/models/ir_attachment_action_download.py
@@ -0,0 +1,55 @@
+# Copyright 2023 Foodles (https://www.foodles.com/)
+# @author Pierre Verkest
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
+from odoo import _, models
+
+
+class IrAttachmentActionDownloadMixin(models.AbstractModel):
+
+ _name = "ir.attachment.action_download"
+ _description = """
+ Mixin to help download attachments linked to record(s).
+ """
+
+ def _get_downloadable_attachments(self):
+ """Give a chance to easily overwrite this method
+ on sub modules to limit restict attachement able to downlaods
+
+ In some case we probably want the user download some specific
+ document that are probably related to the current model
+
+ By default return all attachment link the the record.
+ """
+ return self.env["ir.attachment"].search(
+ [("res_model", "=", self._name), ("res_id", "in", self.ids)]
+ )
+
+ def action_download_attachments(self):
+ """Return action to:
+ * emit a warning message if no attachment found
+ * download a file if only 1 file found
+ * zip and download the list of attachment returns by `_get_downloadable_attachments`
+ """
+ attachments = self._get_downloadable_attachments()
+ if not attachments:
+ title = _("No attachment!")
+ message = _("There is no document found to download.")
+ return {
+ "type": "ir.actions.client",
+ "tag": "display_notification",
+ "params": {
+ "type": "warning",
+ "title": title,
+ "message": message,
+ "sticky": True,
+ },
+ }
+
+ if len(attachments) == 1:
+ return {
+ "target": "self",
+ "type": "ir.actions.act_url",
+ "url": "/web/content/%s?download=1" % attachments.id,
+ }
+ else:
+ return attachments.action_attachments_download()
diff --git a/attachment_zipped_download/readme/CONTRIBUTORS.rst b/attachment_zipped_download/readme/CONTRIBUTORS.rst
index 536c5890..32b0e75c 100644
--- a/attachment_zipped_download/readme/CONTRIBUTORS.rst
+++ b/attachment_zipped_download/readme/CONTRIBUTORS.rst
@@ -4,3 +4,5 @@
* Víctor Martínez
* Pedro M. Baeza
+
+* Pierre Verkest
diff --git a/attachment_zipped_download/readme/DESCRIPTION.rst b/attachment_zipped_download/readme/DESCRIPTION.rst
index 15f07dbb..38725937 100644
--- a/attachment_zipped_download/readme/DESCRIPTION.rst
+++ b/attachment_zipped_download/readme/DESCRIPTION.rst
@@ -1 +1,4 @@
This module allows downloading multiple attachments as a zip file.
+
+This also provide a helper class `IrAttachmentActionDownloadMixin`
+to be used by developer to add action method on models.
diff --git a/attachment_zipped_download/readme/USAGE.rst b/attachment_zipped_download/readme/USAGE.rst
index 0acc4217..3a4738f9 100644
--- a/attachment_zipped_download/readme/USAGE.rst
+++ b/attachment_zipped_download/readme/USAGE.rst
@@ -1,2 +1,78 @@
#. Go to *Settings > Technical > Database Structure > Attachments* and select some files.
#. Go to *Actions > Download* and a zip file containing the selected files will be downloaded.
+
+## For developer
+
+You can reuse the `IrAttachmentActionDownloadMixin` on your
+favorite models::
+
+ from odoo import models
+
+
+ class StockPicking(models.Model):
+ _name = "stock.picking"
+ _inherit = ["stock.picking", "ir.attachment.action_download"]
+
+
+Then you can add an action button on list view line or on the action button
+(when multiple lines are selected) to download all files::
+
+
+
+
+
+ stock.picking.tree download attachments
+ stock.picking
+
+
+
+
+
+
+
+
+
+ Download attachments
+
+
+ list
+ code
+
+ action = records.action_download_attachments()
+
+
+
+
+
+.. note::
+
+ Even you will be able to generate a zip file with multiple document with the
+ same name it's advice to overwrite `_compute_zip_file_name` to improve the
+ name. When a slash (`/`) is present in the path it will create a directory.
+ This example will create a directory per stock.picking using its name::
+
+ class IrAttachment(models.Model):
+ _inherit = "ir.attachment"
+
+ def _compute_zip_file_name(self):
+ self.ensure_one()
+ if self.res_model and self.res_model == "stock.picking":
+ return (
+ self.env[self.res_model]
+ .browse(self.res_id)
+ .display_name.replace("/", "-")
+ + "/"
+ + self.name
+ )
+ return super()._compute_zip_file_name()
diff --git a/attachment_zipped_download/static/description/index.html b/attachment_zipped_download/static/description/index.html
index c4c17d87..5833d441 100644
--- a/attachment_zipped_download/static/description/index.html
+++ b/attachment_zipped_download/static/description/index.html
@@ -1,20 +1,20 @@
-
+
-
+
Attachment Zipped Download