mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-23 17:08:46 -06:00
[UPD] README.rst
This commit is contained in:
parent
14dc53d93e
commit
bd83b93d08
@ -27,6 +27,9 @@ Attachment Zipped Download
|
|||||||
|
|
||||||
This module allows downloading multiple attachments as a zip file.
|
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**
|
**Table of contents**
|
||||||
|
|
||||||
.. contents::
|
.. contents::
|
||||||
@ -38,6 +41,82 @@ Usage
|
|||||||
#. Go to *Settings > Technical > Database Structure > Attachments* and select some files.
|
#. 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.
|
#. 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
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
||||||
@ -66,6 +145,8 @@ Contributors
|
|||||||
* Víctor Martínez
|
* Víctor Martínez
|
||||||
* Pedro M. Baeza
|
* Pedro M. Baeza
|
||||||
|
|
||||||
|
* Pierre Verkest <pierreverkest@gmail.com>
|
||||||
|
|
||||||
Maintainers
|
Maintainers
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -369,6 +369,8 @@ ul.auto-toc {
|
|||||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||||
<p><a class="reference external" 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" 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" href="https://github.com/OCA/knowledge/tree/14.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" href="https://translation.odoo-community.org/projects/knowledge-14-0/knowledge-14-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" href="https://runbot.odoo-community.org/runbot/118/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
<p><a class="reference external" 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" 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" href="https://github.com/OCA/knowledge/tree/14.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" href="https://translation.odoo-community.org/projects/knowledge-14-0/knowledge-14-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" href="https://runbot.odoo-community.org/runbot/118/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||||
<p>This module allows downloading multiple attachments as a zip file.</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>
|
<p><strong>Table of contents</strong></p>
|
||||||
<div class="contents local topic" id="contents">
|
<div class="contents local topic" id="contents">
|
||||||
<ul class="simple">
|
<ul class="simple">
|
||||||
@ -388,6 +390,80 @@ ul.auto-toc {
|
|||||||
<li>Go to <em>Settings > Technical > Database Structure > Attachments</em> and select some files.</li>
|
<li>Go to <em>Settings > Technical > Database Structure > Attachments</em> and select some files.</li>
|
||||||
<li>Go to <em>Actions > Download</em> and a zip file containing the selected files will be downloaded.</li>
|
<li>Go to <em>Actions > Download</em> and a zip file containing the selected files will be downloaded.</li>
|
||||||
</ol>
|
</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 = "stock.picking"
|
||||||
|
_inherit = ["stock.picking", "ir.attachment.action_download"]
|
||||||
|
</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">
|
||||||
|
<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>
|
||||||
|
</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 it’s 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 = "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()
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="bug-tracker">
|
<div class="section" id="bug-tracker">
|
||||||
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
||||||
@ -414,6 +490,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
|
|||||||
<li>Pedro M. Baeza</li>
|
<li>Pedro M. Baeza</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
<li>Pierre Verkest <<a class="reference external" href="mailto:pierreverkest@gmail.com">pierreverkest@gmail.com</a>></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="maintainers">
|
<div class="section" id="maintainers">
|
||||||
|
Loading…
Reference in New Issue
Block a user