Skip to content

Commit b5eb594

Browse files
committed
Merge PR #512 into 17.0
Signed-off-by pedrobaeza
2 parents 63f389d + 9bb905a commit b5eb594

27 files changed

+1491
-0
lines changed

attachment_zipped_download/README.rst

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
==========================
2+
Attachment Zipped Download
3+
==========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:4163544eb16787f39f46edcd97305586594a6f708c1e489908d344467c82483e
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github
20+
:target: https://github.com/OCA/knowledge/tree/17.0/attachment_zipped_download
21+
:alt: OCA/knowledge
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/knowledge-17-0/knowledge-17-0-attachment_zipped_download
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/knowledge&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows downloading multiple attachments as a zip file.
32+
33+
This also provide a helper class IrAttachmentActionDownloadMixin to be
34+
used by developer to add action method on models.
35+
36+
**Table of contents**
37+
38+
.. contents::
39+
:local:
40+
41+
Usage
42+
=====
43+
44+
1. Go to *Settings > Technical > Database Structure > Attachments* and
45+
select some files.
46+
2. Go to *Actions > Download* and a zip file containing the selected
47+
files will be downloaded.
48+
49+
## For developer
50+
51+
You can reuse the IrAttachmentActionDownloadMixin on your favorite
52+
models:
53+
54+
::
55+
56+
from odoo import models
57+
58+
59+
class StockPicking(models.Model):
60+
_name = "stock.picking"
61+
_inherit = ["stock.picking", "ir.attachment.action_download"]
62+
63+
Then you can add an action button on list view line or on the action
64+
button (when multiple lines are selected) to download all files:
65+
66+
::
67+
68+
<odoo>
69+
<!--
70+
add a button on list view to download all attachement present
71+
on the given transfert
72+
-->
73+
<record id="vpicktree" model="ir.ui.view">
74+
<field name="inherit_id" ref="stock.vpicktree"/>
75+
<field name="name">stock.picking.tree download attachments</field>
76+
<field name="model">stock.picking</field>
77+
<field name="arch" type="xml">
78+
<field name="json_popover" position="after">
79+
<button name="action_download_attachments"
80+
type="object"
81+
icon="fa-download"
82+
string="Download attachment(s)"
83+
aria-label="Download Proof documents"
84+
class="float-right"/>
85+
</field>
86+
</field>
87+
</record>
88+
89+
<!--
90+
Add "Download attachments" item in the Action menu when
91+
multiple records are selected
92+
-->
93+
<record id="action_download_picking_attachements" model="ir.actions.server">
94+
<field name="name">Download attachments</field>
95+
<field name="model_id" ref="stock.model_stock_picking"/>
96+
<field name="binding_model_id" ref="stock.model_stock_picking"/>
97+
<field name="binding_view_types">list</field>
98+
<field name="state">code</field>
99+
<field name="code">
100+
action = records.action_download_attachments()
101+
</field>
102+
</record>
103+
</odoo>
104+
105+
.. note::
106+
107+
Even you will be able to generate a zip file with multiple document
108+
with the same name it's advice to overwrite \_compute_zip_file_name
109+
to improve the name. When a slash (/) is present in the path it will
110+
create a directory. This example will create a directory per
111+
stock.picking using its name:
112+
113+
::
114+
115+
class IrAttachment(models.Model):
116+
_inherit = "ir.attachment"
117+
118+
def _compute_zip_file_name(self):
119+
self.ensure_one()
120+
if self.res_model and self.res_model == "stock.picking":
121+
return (
122+
self.env[self.res_model]
123+
.browse(self.res_id)
124+
.display_name.replace("/", "-")
125+
+ "/"
126+
+ self.name
127+
)
128+
return super()._compute_zip_file_name()
129+
130+
Bug Tracker
131+
===========
132+
133+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/knowledge/issues>`_.
134+
In case of trouble, please check there if your issue has already been reported.
135+
If you spotted it first, help us to smash it by providing a detailed and welcomed
136+
`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**>`_.
137+
138+
Do not contact contributors directly about support or help with technical issues.
139+
140+
Credits
141+
=======
142+
143+
Authors
144+
-------
145+
146+
* Tecnativa
147+
148+
Contributors
149+
------------
150+
151+
- César Fernández Domínguez <cesfernandez@outlook.com>
152+
- `Tecnativa <https://www.tecnativa.com>`__:
153+
154+
- Víctor Martínez
155+
- Pedro M. Baeza
156+
157+
- Pierre Verkest <pierreverkest@gmail.com>
158+
159+
Maintainers
160+
-----------
161+
162+
This module is maintained by the OCA.
163+
164+
.. image:: https://odoo-community.org/logo.png
165+
:alt: Odoo Community Association
166+
:target: https://odoo-community.org
167+
168+
OCA, or the Odoo Community Association, is a nonprofit organization whose
169+
mission is to support the collaborative development of Odoo features and
170+
promote its widespread use.
171+
172+
This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/17.0/attachment_zipped_download>`_ project on GitHub.
173+
174+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import controllers
2+
from . import models
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2022 Tecnativa - Víctor Martínez
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Attachment Zipped Download",
5+
"version": "17.0.1.0.0",
6+
"category": "Tools",
7+
"website": "https://github.com/OCA/knowledge",
8+
"author": "Tecnativa, Odoo Community Association (OCA)",
9+
"license": "AGPL-3",
10+
"depends": ["base"],
11+
"data": [
12+
"views/ir_attachment_view.xml",
13+
],
14+
"installable": True,
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2019 César Fernández Domínguez <cesfernandez@outlook.com>
2+
# Copyright 2022 Tecnativa - Víctor Martínez
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
4+
from odoo import _, http
5+
from odoo.http import request
6+
7+
8+
class AttachmentZippedDownloadController(http.Controller):
9+
@http.route("/web/attachment/download_zip", type="http", auth="user")
10+
def download_zip(self, ids=None, debug=0):
11+
ids = [] if not ids else ids
12+
if len(ids) == 0:
13+
return
14+
list_ids = map(int, ids.split(","))
15+
out_file = request.env["ir.attachment"].browse(list_ids)._create_temp_zip()
16+
stream = http.Stream(
17+
type="data",
18+
data=out_file.getvalue(),
19+
mimetype="application/zip",
20+
as_attachment=True,
21+
download_name=_("attachments.zip"),
22+
)
23+
return stream.get_response()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * attachment_zipped_download
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: attachment_zipped_download
17+
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment_action_download
18+
msgid ""
19+
"\n"
20+
" Mixin to help download attachments linked to record(s).\n"
21+
" "
22+
msgstr ""
23+
24+
#. module: attachment_zipped_download
25+
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment
26+
msgid "Attachment"
27+
msgstr ""
28+
29+
#. module: attachment_zipped_download
30+
#: model:ir.actions.server,name:attachment_zipped_download.action_attachments_download
31+
msgid "Download"
32+
msgstr ""
33+
34+
#. module: attachment_zipped_download
35+
#. odoo-python
36+
#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
37+
#, python-format
38+
msgid "No attachment!"
39+
msgstr ""
40+
41+
#. module: attachment_zipped_download
42+
#. odoo-python
43+
#: code:addons/attachment_zipped_download/models/ir_attachment.py:0
44+
#, python-format
45+
msgid "None attachment selected. Only binary attachments allowed."
46+
msgstr ""
47+
48+
#. module: attachment_zipped_download
49+
#. odoo-python
50+
#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
51+
#, python-format
52+
msgid "There is no document found to download."
53+
msgstr ""
54+
55+
#. module: attachment_zipped_download
56+
#. odoo-python
57+
#: code:addons/attachment_zipped_download/controllers/main.py:0
58+
#, python-format
59+
msgid "attachments.zip"
60+
msgstr ""

attachment_zipped_download/i18n/es.po

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * attachment_zipped_download
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 14.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2022-03-15 14:04+0000\n"
10+
"PO-Revision-Date: 2023-09-07 16:37+0000\n"
11+
"Last-Translator: Ivorra78 <informatica@totmaterial.es>\n"
12+
"Language-Team: \n"
13+
"Language: es\n"
14+
"MIME-Version: 1.0\n"
15+
"Content-Type: text/plain; charset=UTF-8\n"
16+
"Content-Transfer-Encoding: 8bit\n"
17+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
18+
"X-Generator: Weblate 4.17\n"
19+
20+
#. module: attachment_zipped_download
21+
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment_action_download
22+
msgid ""
23+
"\n"
24+
" Mixin to help download attachments linked to record(s).\n"
25+
" "
26+
msgstr ""
27+
"\n"
28+
" Mixin para ayudar a descargar archivos adjuntos vinculados a "
29+
"registros.\n"
30+
" "
31+
32+
#. module: attachment_zipped_download
33+
#: model:ir.model,name:attachment_zipped_download.model_ir_attachment
34+
msgid "Attachment"
35+
msgstr "Adjunto"
36+
37+
#. module: attachment_zipped_download
38+
#: model:ir.actions.server,name:attachment_zipped_download.action_attachments_download
39+
msgid "Download"
40+
msgstr "Descargar"
41+
42+
#. module: attachment_zipped_download
43+
#. odoo-python
44+
#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
45+
#, python-format
46+
msgid "No attachment!"
47+
msgstr "¡No hay adjuntos!"
48+
49+
#. module: attachment_zipped_download
50+
#. odoo-python
51+
#: code:addons/attachment_zipped_download/models/ir_attachment.py:0
52+
#, python-format
53+
msgid "None attachment selected. Only binary attachments allowed."
54+
msgstr ""
55+
"No se seleccionó ningún archivo adjunto. Solo se permiten archivos adjuntos "
56+
"binarios."
57+
58+
#. module: attachment_zipped_download
59+
#. odoo-python
60+
#: code:addons/attachment_zipped_download/models/ir_attachment_action_download.py:0
61+
#, python-format
62+
msgid "There is no document found to download."
63+
msgstr "No se encontró ningún documento para descargar."
64+
65+
#. module: attachment_zipped_download
66+
#. odoo-python
67+
#: code:addons/attachment_zipped_download/controllers/main.py:0
68+
#, python-format
69+
msgid "attachments.zip"
70+
msgstr "adjuntos.zip"

0 commit comments

Comments
 (0)