Browse Source
Merge pull request #85 from grap/7.0-document_extract_from_database
Merge pull request #85 from grap/7.0-document_extract_from_database
[7.0] [ADD] 'document extract from database'pull/98/head
Guewen Baconnier
10 years ago
14 changed files with 451 additions and 0 deletions
-
22document_export_from_db/__init__.py
-
50document_export_from_db/__openerp__.py
-
15document_export_from_db/data/ir_values.xml
-
57document_export_from_db/i18n/document_export_from_db.pot
-
57document_export_from_db/i18n/fr.po
-
23document_export_from_db/model/__init__.py
-
36document_export_from_db/model/document_multiple_action.py
-
41document_export_from_db/model/ir_attachment.py
-
BINdocument_export_from_db/static/src/img/icon.png
-
3document_export_from_db/static/src/img/icon_licences.txt
-
28document_export_from_db/tests/__init__.py
-
78document_export_from_db/tests/test_document_extract_from_database.py
-
17document_export_from_db/view/action.xml
-
24document_export_from_db/view/view.xml
@ -0,0 +1,22 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# Copyright (C) 2012 Julius Network Solutions SARL <contact@julius.fr> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
|
||||
|
from . import model |
@ -0,0 +1,50 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# Copyright (C) 2012 Julius Network Solutions SARL <contact@julius.fr> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
|
||||
|
{ |
||||
|
"name": "Export Documents from database", |
||||
|
"summary": "Export Existing Documents from Database to File System", |
||||
|
"version": "1.0", |
||||
|
"author": "Julius Network Solutions", |
||||
|
"website": "http://julius.fr", |
||||
|
"category": "Tools", |
||||
|
"depends": [ |
||||
|
"document", |
||||
|
], |
||||
|
"description": """ |
||||
|
Add a Button to export existing documents from database to File System |
||||
|
====================================================================== |
||||
|
|
||||
|
|
||||
|
* Make sure you've correctly defined the filestore in your database: |
||||
|
* "Settings > Parameters > System Parameters": |
||||
|
* "key": "ir_attachment.location" |
||||
|
* "value": "file:///filestore" |
||||
|
|
||||
|
* Go to your document list, select all the documents you want to extract. |
||||
|
* Click on "More > Documents Export" |
||||
|
""", |
||||
|
"data": [ |
||||
|
'view/view.xml', |
||||
|
'view/action.xml', |
||||
|
'data/ir_values.xml', |
||||
|
], |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record model="ir.values" id="document_multiple_action"> |
||||
|
<field name="model_id" ref="base.model_ir_attachment" /> |
||||
|
<field name="name">Documents Export</field> |
||||
|
<field name="key2">client_action_multi</field> |
||||
|
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_view_document_multiple_action_form'))" /> |
||||
|
<field name="key">action</field> |
||||
|
<field name="model">ir.attachment</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,57 @@ |
|||||
|
# Translation of OpenERP Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * document_export_from_db |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: OpenERP Server 7.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2014-11-19 17:57+0000\n" |
||||
|
"PO-Revision-Date: 2014-11-19 17:57+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: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "Cancel" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
#: model:ir.actions.act_window,name:document_export_from_db.action_view_document_multiple_action_form |
||||
|
msgid "Documents Export" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "Extract documents" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "If you click on 'Write again', the selected document which are stored in the database will be extracted into the filestore location." |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: code:_description:0 |
||||
|
#: model:ir.model,name:document_export_from_db.model_document_multiple_action |
||||
|
#, python-format |
||||
|
msgid "Multiple action on document" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: code:_description:0 |
||||
|
#: model:ir.model,name:document_export_from_db.model_ir_attachment |
||||
|
#, python-format |
||||
|
msgid "ir.attachment" |
||||
|
msgstr "" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "or" |
||||
|
msgstr "" |
||||
|
|
@ -0,0 +1,57 @@ |
|||||
|
# Translation of OpenERP Server. |
||||
|
# This file contains the translation of the following modules: |
||||
|
# * document_export_from_db |
||||
|
# |
||||
|
msgid "" |
||||
|
msgstr "" |
||||
|
"Project-Id-Version: OpenERP Server 7.0\n" |
||||
|
"Report-Msgid-Bugs-To: \n" |
||||
|
"POT-Creation-Date: 2014-11-19 17:58+0000\n" |
||||
|
"PO-Revision-Date: 2014-11-19 17:58+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: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "Cancel" |
||||
|
msgstr "Annuler" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
#: model:ir.actions.act_window,name:document_export_from_db.action_view_document_multiple_action_form |
||||
|
msgid "Documents Export" |
||||
|
msgstr "Export de Documents" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "Extract documents" |
||||
|
msgstr "Exporter les Documents" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "If you click on 'Write again', the selected document which are stored in the database will be extracted into the filestore location." |
||||
|
msgstr "Si vous cliquez sur 'Ecrire de Nouveau', les documents sélectionnés qui sont en base de données seront exportés dans le système de fichiers." |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: code:_description:0 |
||||
|
#: model:ir.model,name:document_export_from_db.model_document_multiple_action |
||||
|
#, python-format |
||||
|
msgid "Multiple action on document" |
||||
|
msgstr "Action Multiple sur des Documents" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: code:_description:0 |
||||
|
#: model:ir.model,name:document_export_from_db.model_ir_attachment |
||||
|
#, python-format |
||||
|
msgid "ir.attachment" |
||||
|
msgstr "ir.attachment" |
||||
|
|
||||
|
#. module: document_export_from_db |
||||
|
#: view:document.multiple.action:0 |
||||
|
msgid "or" |
||||
|
msgstr "ou" |
||||
|
|
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# Copyright (C) 2012 Julius Network Solutions SARL <contact@julius.fr> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
|
||||
|
from . import ir_attachment |
||||
|
from . import document_multiple_action |
@ -0,0 +1,36 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# Copyright (C) 2012 Julius Network Solutions SARL <contact@julius.fr> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
|
||||
|
from openerp.osv.orm import TransientModel |
||||
|
|
||||
|
|
||||
|
class document_multiple_action(TransientModel): |
||||
|
_name = 'document.multiple.action' |
||||
|
_description = 'Multiple action on document' |
||||
|
|
||||
|
def write_again(self, cr, uid, ids, context=None): |
||||
|
if context is None: |
||||
|
context = {} |
||||
|
document_obj = self.pool['ir.attachment'] |
||||
|
document_ids = context.get('active_ids') |
||||
|
if document_ids: |
||||
|
document_obj.write_again(cr, uid, document_ids, context=context) |
||||
|
return True |
@ -0,0 +1,41 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################### |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# Copyright (C) 2012 Julius Network Solutions SARL <contact@julius.fr> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
|
||||
|
from openerp.osv.orm import Model |
||||
|
|
||||
|
|
||||
|
class ir_attachment(Model): |
||||
|
_inherit = 'ir.attachment' |
||||
|
|
||||
|
def write_again(self, cr, uid, ids, context=None): |
||||
|
if context is None: |
||||
|
context = {} |
||||
|
location = self.pool['ir.config_parameter'].get_param( |
||||
|
cr, uid, 'ir_attachment.location') |
||||
|
if not location: |
||||
|
return True |
||||
|
for ia in self.browse(cr, uid, ids, context=context): |
||||
|
if ia.db_datas: |
||||
|
super(ir_attachment, self).write(cr, uid, ia.id, { |
||||
|
'datas': ia.datas, |
||||
|
'db_datas': False, |
||||
|
}, context=context) |
||||
|
return True |
After Width: 213 | Height: 213 | Size: 29 KiB |
@ -0,0 +1,3 @@ |
|||||
|
Icon File is a mix of icons: |
||||
|
* Licence: Creative Common Attribution (by) - Designer: Kevin Muselet <http://pit-tux.deviantart.com/> |
||||
|
* Licence: GNU/GPL - Designer: Alessandro Rei <http://www.mentalrey.it/> |
@ -0,0 +1,28 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# Copyright (C) 2014 GRAP (http://www.grap.coop) |
||||
|
# @author Sylvain LE GAL (https://twitter.com/legalsylvain) |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
|
||||
|
from . import test_document_extract_from_database |
||||
|
|
||||
|
fast_suite = [ |
||||
|
test_document_extract_from_database, |
||||
|
] |
@ -0,0 +1,78 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# Copyright (C) 2014 GRAP (http://www.grap.coop) |
||||
|
# @author Sylvain LE GAL (https://twitter.com/legalsylvain) |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################### |
||||
|
|
||||
|
from openerp.tests.common import TransactionCase |
||||
|
|
||||
|
|
||||
|
class TestDocumentExtractFromDatabase(TransactionCase): |
||||
|
"""Tests for 'Document Extract From Database' Module""" |
||||
|
|
||||
|
def setUp(self): |
||||
|
super(TestDocumentExtractFromDatabase, self).setUp() |
||||
|
self.icp_obj = self.registry('ir.config_parameter') |
||||
|
self.ia_obj = self.registry('ir.attachment') |
||||
|
self.dma_obj = self.registry('document.multiple.action') |
||||
|
|
||||
|
# Test Section |
||||
|
def test_01_document_extract(self): |
||||
|
"""Test the correct extract of an attachment.""" |
||||
|
cr, uid = self.cr, self.uid |
||||
|
# Make sure that Odoo is set to write attachment in Database |
||||
|
self.icp_obj.unlink(cr, uid, self.icp_obj.search( |
||||
|
cr, uid, [('key', '=', 'ir_attachment.location')])) |
||||
|
|
||||
|
# Create a new Attachment |
||||
|
ia_id = self.ia_obj.create(cr, uid, { |
||||
|
'name': 'Attachment Test', |
||||
|
'datas_fname': 'pixel.png', |
||||
|
'type': 'binary', |
||||
|
'datas': """iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABH""" |
||||
|
"""NCSVQICAgIfAhkiAAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAA1JREFUCJljO""" |
||||
|
"""LR/w38AB6kDMQ1kMu8AAAAASUVORK5CYII=""", |
||||
|
}) |
||||
|
|
||||
|
# Get Data Before |
||||
|
data_before = self.ia_obj.browse(cr, uid, ia_id).datas |
||||
|
# Change setting for attachment to save on filesystem |
||||
|
self.icp_obj.create(cr, uid, { |
||||
|
'key': 'ir_attachment.location', |
||||
|
'value': 'file:///filestore', |
||||
|
}) |
||||
|
|
||||
|
# Run Write Again Functionnality |
||||
|
self.dma_obj.write_again(cr, uid, 0, {'active_ids': [ia_id]}) |
||||
|
|
||||
|
data_after = self.ia_obj.browse(cr, uid, ia_id).datas |
||||
|
|
||||
|
# Test if datas have not changed |
||||
|
# Note: Replace \n char by nothing, because datas field are different |
||||
|
# when ir_attachement is in Database or in File System |
||||
|
ia = self.ia_obj.browse(cr, uid, ia_id) |
||||
|
self.assertEqual( |
||||
|
data_before, data_after.replace('\n', ''), |
||||
|
"Datas have changed after exporting into filesystem.") |
||||
|
|
||||
|
# Test if the file is in the file system |
||||
|
ia = self.ia_obj.browse(cr, uid, ia_id) |
||||
|
self.assertNotEqual( |
||||
|
ia.store_fname, None, |
||||
|
"Attachment must be on File System after Write Again Function.") |
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record id="action_view_document_multiple_action_form" model="ir.actions.act_window"> |
||||
|
<field name="name">Documents Export</field> |
||||
|
<field name="res_model">document.multiple.action</field> |
||||
|
<field name="type">ir.actions.act_window</field> |
||||
|
<field name="view_type">form</field> |
||||
|
<field name="view_mode">form</field> |
||||
|
<field name="view_id" ref="view_document_multiple_action_form"/> |
||||
|
<field name="target">new</field> |
||||
|
<field name="multi">True</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,24 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<record id="view_document_multiple_action_form" model="ir.ui.view"> |
||||
|
<field name="name">Document multiple action</field> |
||||
|
<field name="model">document.multiple.action</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Documents Export" version="7.0"> |
||||
|
<div> |
||||
|
<p> |
||||
|
<label string="If you click on 'Write again', the selected document which are stored in the database will be extracted into the filestore location."/> |
||||
|
</p> |
||||
|
</div> |
||||
|
<footer> |
||||
|
<button name="write_again" string="Extract documents" class="oe_highlight" type="object"/> or |
||||
|
<button string="Cancel" class="oe_link" special="cancel"/> |
||||
|
</footer> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue