Skip to content

Commit

Permalink
[IMP] attachment_zipped_download: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralmau committed Dec 18, 2024
1 parent aad89e8 commit e5387e2
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 149 deletions.
182 changes: 94 additions & 88 deletions attachment_zipped_download/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ Attachment Zipped Download
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github
:target: https://github.com/OCA/knowledge/tree/16.0/attachment_zipped_download
:target: https://github.com/OCA/knowledge/tree/17.0/attachment_zipped_download
:alt: OCA/knowledge
.. |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
:target: https://translation.odoo-community.org/projects/knowledge-17-0/knowledge-17-0-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/knowledge&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/knowledge&target_branch=17.0
:alt: Try me on Runboat

|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.
This also provide a helper class IrAttachmentActionDownloadMixin to be
used by developer to add action method on models.

**Table of contents**

Expand All @@ -41,117 +41,123 @@ to be used by developer to add action method on models.
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.
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

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

<odoo>
<!--
add a button on list view to download all attachement present
on the given transfert
-->
<record id="vpicktree" model="ir.ui.view">
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="name">stock.picking.tree download attachments</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<field name="json_popover" position="after">
<button name="action_download_attachments"
type="object"
icon="fa-download"
string="Download attachment(s)"
aria-label="Download Proof documents"
class="float-right"/>
</field>
</field>
</record>

<!--
Add "Download attachments" item in the Action menu when
multiple records are selected
-->
<record id="action_download_picking_attachements" model="ir.actions.server">
<field name="name">Download attachments</field>
<field name="model_id" ref="stock.model_stock_picking"/>
<field name="binding_model_id" ref="stock.model_stock_picking"/>
<field name="binding_view_types">list</field>
<field name="state">code</field>
<field name="code">
action = records.action_download_attachments()
</field>
</record>
</odoo>

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:

::

<odoo>
<!--
add a button on list view to download all attachement present
on the given transfert
-->
<record id="vpicktree" model="ir.ui.view">
<field name="inherit_id" ref="stock.vpicktree"/>
<field name="name">stock.picking.tree download attachments</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<field name="json_popover" position="after">
<button name="action_download_attachments"
type="object"
icon="fa-download"
string="Download attachment(s)"
aria-label="Download Proof documents"
class="float-right"/>
</field>
</field>
</record>

<!--
Add "Download attachments" item in the Action menu when
multiple records are selected
-->
<record id="action_download_picking_attachements" model="ir.actions.server">
<field name="name">Download attachments</field>
<field name="model_id" ref="stock.model_stock_picking"/>
<field name="binding_model_id" ref="stock.model_stock_picking"/>
<field name="binding_view_types">list</field>
<field name="state">code</field>
<field name="code">
action = records.action_download_attachments()
</field>
</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()
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 <https://github.com/OCA/knowledge/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 <https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_zipped_download%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/knowledge/issues/new?body=module:%20attachment_zipped_download%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~
-------

* Tecnativa

Contributors
~~~~~~~~~~~~

* César Fernández Domínguez <cesfernandez@outlook.com>
------------

* `Tecnativa <https://www.tecnativa.com>`_:
- César Fernández Domínguez <cesfernandez@outlook.com>
- `Tecnativa <https://www.tecnativa.com>`__:

* Víctor Martínez
* Pedro M. Baeza
- Víctor Martínez
- Pedro M. Baeza

* Pierre Verkest <pierreverkest@gmail.com>
- Pierre Verkest <pierreverkest@gmail.com>

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -163,6 +169,6 @@ 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.

This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/16.0/attachment_zipped_download>`_ project on GitHub.
This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/17.0/attachment_zipped_download>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions attachment_zipped_download/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
5 changes: 5 additions & 0 deletions attachment_zipped_download/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -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>\>
8 changes: 0 additions & 8 deletions attachment_zipped_download/readme/CONTRIBUTORS.rst

This file was deleted.

4 changes: 4 additions & 0 deletions attachment_zipped_download/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 0 additions & 4 deletions attachment_zipped_download/readme/DESCRIPTION.rst

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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>
<!--
Expand Down Expand Up @@ -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()
Loading

0 comments on commit e5387e2

Please sign in to comment.