diff --git a/attachment_zipped_download/i18n/attachment_zipped_download.pot b/attachment_zipped_download/i18n/attachment_zipped_download.pot index 7cd8b6de..8939aaf9 100644 --- a/attachment_zipped_download/i18n/attachment_zipped_download.pot +++ b/attachment_zipped_download/i18n/attachment_zipped_download.pot @@ -13,26 +13,66 @@ 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" msgstr "" +#. 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 "" + #. module: attachment_zipped_download #: model:ir.actions.server,name:attachment_zipped_download.action_attachments_download msgid "Download" msgstr "" #. module: attachment_zipped_download -#. odoo-python +#: 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 "" + +#. 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 "" + +#. 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 "" #. module: attachment_zipped_download -#. odoo-python +#: 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 "" + +#. 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 "" diff --git a/attachment_zipped_download/i18n/es.po b/attachment_zipped_download/i18n/es.po index 840609d9..651ad6fc 100644 --- a/attachment_zipped_download/i18n/es.po +++ b/attachment_zipped_download/i18n/es.po @@ -17,37 +17,69 @@ 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" msgstr "Adjunto" +#. 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 "Nombre mostrado" + #. module: attachment_zipped_download #: model:ir.actions.server,name:attachment_zipped_download.action_attachments_download msgid "Download" msgstr "Descargar" #. module: attachment_zipped_download -#. odoo-python +#: 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 "ID" + +#. 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 "Última modificación el" + +#. 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 "" + +#. 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 "" "No se seleccionó ningún archivo adjunto. Solo se permiten archivos adjuntos " "binarios." +#. 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 "" + #. module: attachment_zipped_download #. odoo-python #: 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 "adjuntos.zip" - -#~ msgid "Display Name" -#~ msgstr "Nombre mostrado" - -#~ msgid "ID" -#~ msgstr "ID" - -#~ msgid "Last Modified on" -#~ msgstr "Última modificación el" 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/it.po b/attachment_zipped_download/i18n/it.po index 6b4ad299..15bccd6d 100644 --- a/attachment_zipped_download/i18n/it.po +++ b/attachment_zipped_download/i18n/it.po @@ -16,26 +16,66 @@ 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" msgstr "Allegato" +#. 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 "Nome visualizzato" + #. module: attachment_zipped_download #: model:ir.actions.server,name:attachment_zipped_download.action_attachments_download msgid "Download" msgstr "Scarica" #. module: attachment_zipped_download -#. odoo-python +#: 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 "ID" + +#. 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 "Ultima modifica il" + +#. 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 "" + +#. 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 "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 +#: 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 "" + +#. 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 "attachments.zip" 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 + + +