-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new module to download multiple attachment / changed by FJG for O…
…doo 9 compat
- Loading branch information
root
committed
Jun 5, 2020
1 parent
f6ebc0e
commit e776fc7
Showing
23 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
###################################################################################################### | ||
# | ||
# Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
# including but not limited to the implied warranties | ||
# of merchantability and/or fitness for a particular purpose | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
###################################################################################################### | ||
from . import models | ||
from . import controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
###################################################################################################### | ||
# | ||
# Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
# including but not limited to the implied warranties | ||
# of merchantability and/or fitness for a particular purpose | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
###################################################################################################### | ||
{ | ||
"name": "Download Multiple Attachments", | ||
"version": "11.0", | ||
"depends": ['base'], | ||
"author": "BHC", | ||
'website': 'www.bhc.be', | ||
"description": """""", | ||
'data': [ | ||
'data/ir_actions_server_data.xml', | ||
'views/attachment_views.xml', | ||
], | ||
'images': ['static/description/banner.png'], | ||
'demo': [], | ||
'qweb': [], | ||
'installable': True, | ||
'license': 'LGPL-3', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
###################################################################################################### | ||
# | ||
# Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
# including but not limited to the implied warranties | ||
# of merchantability and/or fitness for a particular purpose | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
###################################################################################################### | ||
{ | ||
"name": "Download Multiple Attachments", | ||
"version": "11.0.1", # FJG change to be compat to Odoo 9 | ||
"depends": ['base'], | ||
"author": "BHC", | ||
'website': 'www.bhc.be', | ||
"description": """""", | ||
'data': [ | ||
'data/ir_actions_server_data.xml', | ||
'views/attachment_views.xml', | ||
], | ||
'images': ['static/description/banner.png'], | ||
'demo': [], | ||
'qweb': [], | ||
'installable': True, | ||
'license': 'LGPL-3', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
###################################################################################################### | ||
# | ||
# Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
# including but not limited to the implied warranties | ||
# of merchantability and/or fitness for a particular purpose | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
###################################################################################################### | ||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
###################################################################################################### | ||
# | ||
# Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
# including but not limited to the implied warranties | ||
# of merchantability and/or fitness for a particular purpose | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
###################################################################################################### | ||
import logging | ||
try: | ||
from BytesIO import BytesIO | ||
except ImportError: | ||
from io import BytesIO | ||
import zipfile | ||
from datetime import datetime | ||
from openerp import http | ||
from openerp.http import request | ||
from openerp.addons.web.controllers.main import content_disposition | ||
import ast | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class Binary(http.Controller): | ||
@http.route('/web/binary/download_document', type='http', auth="public") | ||
def download_document(self, tab_id, **kw): | ||
new_tab = ast.literal_eval(tab_id) | ||
attachment_ids = request.env['ir.attachment'].search([('id', 'in', new_tab)]) | ||
file_dict = {} | ||
for attachment_id in attachment_ids: | ||
file_store = attachment_id.store_fname | ||
if file_store: | ||
file_name = attachment_id.name | ||
file_path = attachment_id._full_path(file_store) | ||
file_dict["%s:%s" % (file_store, file_name)] = dict(path=file_path, name=file_name) | ||
zip_filename = datetime.now() | ||
zip_filename = "%s.zip" % zip_filename | ||
bitIO = BytesIO() | ||
zip_file = zipfile.ZipFile(bitIO, "w", zipfile.ZIP_DEFLATED) | ||
for file_info in file_dict.values(): | ||
zip_file.write(file_info["path"], file_info["name"]) | ||
zip_file.close() | ||
return request.make_response(bitIO.getvalue(), | ||
headers=[('Content-Type', 'application/x-zip-compressed'), | ||
('Content-Disposition', content_disposition(zip_filename))]) | ||
|
24 changes: 24 additions & 0 deletions
24
download_multiple_attachments/data/ir_actions_server_data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<data> | ||
<record id="ir_action_download_attachment" model="ir.actions.server"> | ||
<field name="name">Download</field> | ||
<field name="type">ir.actions.server</field> | ||
<field name="model_id" ref="base.model_ir_attachment"/> | ||
<field name="state">code</field> | ||
<field name="code"> | ||
if env.context.get('active_ids'): | ||
action = model.browse(context['active_ids']).action_download_attachment() | ||
</field> | ||
</record> | ||
|
||
<record id="ir_values_download_attachment" model="ir.values"> | ||
<field name="name">Download</field> | ||
<field name="model_id" ref="base.model_ir_attachment"/> | ||
<field name="model">ir.attachment</field> | ||
<field name="key">action</field> | ||
<field name="key2">client_action_multi</field> | ||
<field name="value" eval="'ir.actions.server,%d'%ir_action_download_attachment"/> | ||
</record> | ||
</data> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * download_multiple_attachments | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2019-04-26 12:04+0000\n" | ||
"PO-Revision-Date: 2019-04-26 12:04+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: download_multiple_attachments | ||
#: model:ir.actions.server,name:download_multiple_attachments.ir_action_download_attachment | ||
msgid "Download" | ||
msgstr "Télécharger" | ||
|
||
#. module: download_multiple_attachments | ||
#: model:ir.ui.view,arch_db:download_multiple_attachments.view_attachment_search | ||
msgid "Invoices" | ||
msgstr "Factures" | ||
|
||
#. module: download_multiple_attachments | ||
#: model:ir.ui.view,arch_db:download_multiple_attachments.view_attachment_search | ||
msgid "Model" | ||
msgstr "Modèle" | ||
|
||
#. module: download_multiple_attachments | ||
#: model:ir.ui.view,arch_db:download_multiple_attachments.view_attachment_search | ||
msgid "Partners" | ||
msgstr "Partenaires" | ||
|
||
#. module: download_multiple_attachments | ||
#: model:ir.ui.view,arch_db:download_multiple_attachments.view_attachment_search | ||
msgid "Sale orders" | ||
msgstr "Devis/Bons de commande" | ||
|
||
#. module: download_multiple_attachments | ||
#: model:ir.model,name:download_multiple_attachments.model_ir_attachment | ||
msgid "ir.attachment" | ||
msgstr "ir.attachment" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
###################################################################################################### | ||
# | ||
# Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
# including but not limited to the implied warranties | ||
# of merchantability and/or fitness for a particular purpose | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
###################################################################################################### | ||
from . import attachment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# -*- coding: utf-8 -*- | ||
###################################################################################################### | ||
# | ||
# Copyright (C) B.H.C. sprl - All Rights Reserved, http://www.bhc.be | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
# including but not limited to the implied warranties | ||
# of merchantability and/or fitness for a particular purpose | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/> | ||
###################################################################################################### | ||
from openerp import api, exceptions, fields, models, _ | ||
|
||
|
||
class IrAttachment(models.Model): | ||
_inherit = 'ir.attachment' | ||
|
||
@api.multi | ||
def action_download_attachment(self): | ||
tab_id = [] | ||
for attachment in self: | ||
tab_id.append(attachment.id) | ||
url = '/web/binary/download_document?tab_id=%s' % tab_id | ||
return { | ||
'type': 'ir.actions.act_url', | ||
'url': url, | ||
'target': 'new', | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.