[UPD] README.rst

This commit is contained in:
OCA-git-bot 2023-09-06 18:15:24 +00:00
parent 8469f7227c
commit f05d60dac2
2 changed files with 160 additions and 2 deletions

View File

@ -7,7 +7,7 @@ Attachment Zipped Download
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f05914d14f12522617d342075832a7a6f58dcbd0f845cd6059d8ff3f0f231866
!! source digest: sha256:5ba1f89bdbf346f050f066b394d1b1105be0fb9a54e77b147110037697890f6f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@ -30,6 +30,9 @@ Attachment Zipped Download
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::
@ -41,6 +44,82 @@ 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::
<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()
Bug Tracker
===========
@ -69,6 +148,8 @@ Contributors
* Víctor Martínez
* Pedro M. Baeza
* Pierre Verkest <pierreverkest@gmail.com>
Maintainers
~~~~~~~~~~~

View File

@ -367,10 +367,12 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f05914d14f12522617d342075832a7a6f58dcbd0f845cd6059d8ff3f0f231866
!! source digest: sha256:5ba1f89bdbf346f050f066b394d1b1105be0fb9a54e77b147110037697890f6f
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/knowledge/tree/16.0/attachment_zipped_download"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/knowledge-16-0/knowledge-16-0-attachment_zipped_download"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/knowledge&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows downloading multiple attachments as a zip file.</p>
<p>This also provide a helper class <cite>IrAttachmentActionDownloadMixin</cite>
to be used by developer to add action method on models.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
@ -390,6 +392,80 @@ ul.auto-toc {
<li>Go to <em>Settings &gt; Technical &gt; Database Structure &gt; Attachments</em> and select some files.</li>
<li>Go to <em>Actions &gt; Download</em> and a zip file containing the selected files will be downloaded.</li>
</ol>
<p>## For developer</p>
<p>You can reuse the <cite>IrAttachmentActionDownloadMixin</cite> on your
favorite models:</p>
<pre class="literal-block">
from odoo import models
class StockPicking(models.Model):
_name = &quot;stock.picking&quot;
_inherit = [&quot;stock.picking&quot;, &quot;ir.attachment.action_download&quot;]
</pre>
<p>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:</p>
<pre class="literal-block">
&lt;odoo&gt;
&lt;!--
add a button on list view to download all attachement present
on the given transfert
--&gt;
&lt;record id=&quot;vpicktree&quot; model=&quot;ir.ui.view&quot;&gt;
&lt;field name=&quot;inherit_id&quot; ref=&quot;stock.vpicktree&quot;/&gt;
&lt;field name=&quot;name&quot;&gt;stock.picking.tree download attachments&lt;/field&gt;
&lt;field name=&quot;model&quot;&gt;stock.picking&lt;/field&gt;
&lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;
&lt;field name=&quot;json_popover&quot; position=&quot;after&quot;&gt;
&lt;button name=&quot;action_download_attachments&quot;
type=&quot;object&quot;
icon=&quot;fa-download&quot;
string=&quot;Download attachment(s)&quot;
aria-label=&quot;Download Proof documents&quot;
class=&quot;float-right&quot;/&gt;
&lt;/field&gt;
&lt;/field&gt;
&lt;/record&gt;
&lt;!--
Add &quot;Download attachments&quot; item in the Action menu when
multiple records are selected
--&gt;
&lt;record id=&quot;action_download_picking_attachements&quot; model=&quot;ir.actions.server&quot;&gt;
&lt;field name=&quot;name&quot;&gt;Download attachments&lt;/field&gt;
&lt;field name=&quot;model_id&quot; ref=&quot;stock.model_stock_picking&quot;/&gt;
&lt;field name=&quot;binding_model_id&quot; ref=&quot;stock.model_stock_picking&quot;/&gt;
&lt;field name=&quot;binding_view_types&quot;&gt;list&lt;/field&gt;
&lt;field name=&quot;state&quot;&gt;code&lt;/field&gt;
&lt;field name=&quot;code&quot;&gt;
action = records.action_download_attachments()
&lt;/field&gt;
&lt;/record&gt;
&lt;/odoo&gt;
</pre>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p>Even you will be able to generate a zip file with multiple document with the
same name its advice to overwrite <cite>_compute_zip_file_name</cite> to improve the
name. When a slash (<cite>/</cite>) is present in the path it will create a directory.
This example will create a directory per stock.picking using its name:</p>
<pre class="last literal-block">
class IrAttachment(models.Model):
_inherit = &quot;ir.attachment&quot;
def _compute_zip_file_name(self):
self.ensure_one()
if self.res_model and self.res_model == &quot;stock.picking&quot;:
return (
self.env[self.res_model]
.browse(self.res_id)
.display_name.replace(&quot;/&quot;, &quot;-&quot;)
+ &quot;/&quot;
+ self.name
)
return super()._compute_zip_file_name()
</pre>
</div>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
@ -416,6 +492,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Pedro M. Baeza</li>
</ul>
</li>
<li>Pierre Verkest &lt;<a class="reference external" href="mailto:pierreverkest&#64;gmail.com">pierreverkest&#64;gmail.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">