Skip to content

Commit

Permalink
add new module to download multiple attachment / changed by FJG for O…
Browse files Browse the repository at this point in the history
…doo 9 compat
  • Loading branch information
root committed Jun 5, 2020
1 parent f6ebc0e commit e776fc7
Show file tree
Hide file tree
Showing 23 changed files with 487 additions and 0 deletions.
21 changes: 21 additions & 0 deletions download_multiple_attachments/__init__.py
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
36 changes: 36 additions & 0 deletions download_multiple_attachments/__manifest__.py
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',
}
36 changes: 36 additions & 0 deletions download_multiple_attachments/__openerp__.py
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',
}
20 changes: 20 additions & 0 deletions download_multiple_attachments/controller/__init__.py
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
57 changes: 57 additions & 0 deletions download_multiple_attachments/controller/main.py
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 download_multiple_attachments/data/ir_actions_server_data.xml
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>
47 changes: 47 additions & 0 deletions download_multiple_attachments/i18n/fr_BE.po
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"

20 changes: 20 additions & 0 deletions download_multiple_attachments/models/__init__.py
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
36 changes: 36 additions & 0 deletions download_multiple_attachments/models/attachment.py
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.
Loading

0 comments on commit e776fc7

Please sign in to comment.