[IMP] attachment_zipped_download: pre-commit auto fixes

This commit is contained in:
Víctor Martínez
2024-12-18 12:59:33 +01:00
parent 49e38ce17d
commit 422c64a40e
8 changed files with 152 additions and 140 deletions

View File

@@ -0,0 +1,5 @@
- César Fernández Domínguez \<<cesfernandez@outlook.com>\>
- [Tecnativa](https://www.tecnativa.com):
- Víctor Martínez
- Pedro M. Baeza
- Pierre Verkest \<<pierreverkest@gmail.com>\>

View File

@@ -1,8 +0,0 @@
* César Fernández Domínguez <cesfernandez@outlook.com>
* `Tecnativa <https://www.tecnativa.com>`_:
* Víctor Martínez
* Pedro M. Baeza
* Pierre Verkest <pierreverkest@gmail.com>

View File

@@ -0,0 +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.

View File

@@ -1,4 +0,0 @@
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.

View File

@@ -1,10 +1,12 @@
#. 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.
1. Go to *Settings \> Technical \> Database Structure \> Attachments*
and select some files.
2. Go to *Actions \> Download* and a zip file containing the selected
files will be downloaded.
## For developer
\## For developer
You can reuse the `IrAttachmentActionDownloadMixin` on your
favorite models::
You can reuse the IrAttachmentActionDownloadMixin on your favorite
models:
from odoo import models
@@ -13,9 +15,8 @@ favorite models::
_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::
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:
<odoo>
<!--
@@ -54,25 +55,24 @@ Then you can add an action button on list view line or on the action button
</record>
</odoo>
.. 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()
> [!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()