mirror of
https://github.com/OCA/knowledge.git
synced 2026-01-05 11:46:56 -06:00
[IMP] attachment_zipped_download: provide ir.attachment.action_download mixin
This helps to download multiple attachments from any models. [UPD] README.rst [UPD] Update attachment_zipped_download.pot [UPD] README.rst attachment_zipped_download 16.0.2.0.0 [UPD] README.rst Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: knowledge-16.0/knowledge-16.0-attachment_zipped_download Translate-URL: https://translation.odoo-community.org/projects/knowledge-16-0/knowledge-16-0-attachment_zipped_download/
This commit is contained in:
committed by
Víctor Martínez
parent
25ceed4377
commit
e267b0b836
@@ -2,10 +2,13 @@
|
||||
Attachment Zipped Download
|
||||
==========================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
..
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:ff7e96407afd1498d4d7a92046727ac078de41e9e3789dcbe61c469b4b13ae67
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
@@ -19,14 +22,17 @@ Attachment Zipped Download
|
||||
.. |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
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/118/16.0
|
||||
:alt: Try me on Runbot
|
||||
.. |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
|
||||
:alt: Try me on Runboat
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|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.
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
@@ -38,12 +44,88 @@ 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
|
||||
===========
|
||||
|
||||
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 smashing it by providing a detailed and welcomed
|
||||
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**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
@@ -66,6 +148,8 @@ Contributors
|
||||
* Víctor Martínez
|
||||
* Pedro M. Baeza
|
||||
|
||||
* Pierre Verkest <pierreverkest@gmail.com>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user