Skip to content

Commit 68f3483

Browse files
committed
[ADD] port document_choose_directory
1 parent 0a42df9 commit 68f3483

16 files changed

+528
-0
lines changed

document_choose_directory/README.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Choose document directories
2+
===========================
3+
4+
This addon enables users to choose a directory while uploading a file. In
5+
combination with access permissions on directories, this can be used to
6+
restrict access on certain records' attachments or simply for a better
7+
overview.
8+
9+
Configuration
10+
=============
11+
12+
Create a static directory and choose the resource model you want to use this
13+
directory on. Assign groups to whom this directory should be accessible. When
14+
uploading a files, users can select one of the directories they have access to,
15+
or no directory which is the default setting.
16+
17+
Keep in mind that if a directory has a owner, it's only visible for this user,
18+
that's probably not what you want.
19+
20+
Credits
21+
=======
22+
23+
Contributors
24+
------------
25+
26+
* Holger Brunn <[email protected]>
27+
28+
Maintainer
29+
----------
30+
31+
.. image:: http://odoo-community.org/logo.png
32+
:alt: Odoo Community Association
33+
:target: http://odoo-community.org
34+
35+
This module is maintained by the OCA.
36+
37+
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
38+
39+
To contribute to this module, please visit http://odoo-community.org.

document_choose_directory/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
from . import model
22+
from . import controllers
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
{
22+
"name": "Choose document's directory",
23+
"summary": "Choose a document's directory during upload",
24+
"version": "1.0",
25+
"author": "Therp BV",
26+
"license": "AGPL-3",
27+
"complexity": "normal",
28+
"category": "Knowledge",
29+
"depends": [
30+
'document',
31+
'web',
32+
],
33+
"data": [
34+
"view/qweb.xml",
35+
"view/document_directory.xml",
36+
],
37+
"js": [
38+
'static/src/js/document_choose_directory.js',
39+
],
40+
"css": [
41+
'static/src/css/document_choose_directory.css',
42+
],
43+
"qweb": [
44+
'static/src/xml/document_choose_directory.xml',
45+
],
46+
"test": [
47+
],
48+
"auto_install": False,
49+
"installable": True,
50+
"application": False,
51+
"external_dependencies": {
52+
'python': [],
53+
},
54+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
from . import binary
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2015 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
from openerp import http
22+
from openerp.addons.web.controllers.main import Binary
23+
24+
25+
class Binary(Binary):
26+
@http.route('/web/binary/upload_attachment', type='http', auth="user")
27+
def upload_attachment(self, callback, model, id, ufile, directory_id=None):
28+
if directory_id:
29+
# we can't use default_parent_id because of
30+
# the ir_attachment.create overwrite in document
31+
http.request.context['parent_id'] = int(directory_id)
32+
# fallback if the above is ever fixed
33+
http.request.context['default_parent_id'] = int(directory_id)
34+
return super(Binary, self).upload_attachment(
35+
callback, model, id, ufile)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Translation of OpenERP Server.
2+
# This file contains the translation of the following modules:
3+
# * document_choose_directory
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: OpenERP Server 7.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2014-07-30 11:27+0000\n"
10+
"PO-Revision-Date: 2014-07-30 11:27+0000\n"
11+
"Last-Translator: <>\n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: document_choose_directory
19+
#. openerp-web
20+
#: code:addons/document_choose_directory/static/src/xml/document_choose_directory.xml:6
21+
#, python-format
22+
msgid "Choose directory"
23+
msgstr ""
24+
25+
#. module: document_choose_directory
26+
#: model:ir.model,name:document_choose_directory.model_document_directory
27+
msgid "Directory"
28+
msgstr ""
29+
30+
#. module: document_choose_directory
31+
#. openerp-web
32+
#: code:addons/document_choose_directory/static/src/js/document_choose_directory.js:64
33+
#, python-format
34+
msgid "No directory"
35+
msgstr ""
36+
37+
#. module: document_choose_directory
38+
#: model:ir.model,name:document_choose_directory.model_ir_attachment
39+
msgid "ir.attachment"
40+
msgstr ""
41+

document_choose_directory/i18n/nl.po

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Translation of OpenERP Server.
2+
# This file contains the translation of the following modules:
3+
# * document_choose_directory
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: OpenERP Server 7.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2014-07-30 11:27+0000\n"
10+
"PO-Revision-Date: 2014-07-30 11:27+0000\n"
11+
"Last-Translator: <>\n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: document_choose_directory
19+
#. openerp-web
20+
#: code:addons/document_choose_directory/static/src/xml/document_choose_directory.xml:6
21+
#, python-format
22+
msgid "Choose directory"
23+
msgstr "Kies map"
24+
25+
#. module: document_choose_directory
26+
#: model:ir.model,name:document_choose_directory.model_document_directory
27+
msgid "Directory"
28+
msgstr "Map"
29+
30+
#. module: document_choose_directory
31+
#. openerp-web
32+
#: code:addons/document_choose_directory/static/src/js/document_choose_directory.js:64
33+
#, python-format
34+
msgid "No directory"
35+
msgstr "Geen map"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
from . import document_directory
22+
from . import ir_attachment
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
from openerp.osv.orm import Model
22+
23+
24+
class DocumentDirectory(Model):
25+
_inherit = 'document.directory'
26+
27+
def _get_candidates_for_resource(self, cr, uid, res_model, res_id,
28+
context=None):
29+
'''return directories that can be chosen for a certain record of a
30+
certain model - called by js api, override as needed'''
31+
result = []
32+
for this in self.browse(
33+
cr, uid,
34+
self.search(
35+
cr, uid,
36+
[
37+
('type', '=', 'directory'),
38+
('ressource_type_id.model', '=', res_model),
39+
],
40+
context=context),
41+
context=context):
42+
result.append(this)
43+
return result
44+
45+
def get_candidates_for_resource(self, cr, uid, res_model, res_id,
46+
context=None):
47+
'''return directories that can be chosen for a certain record of a
48+
certain model - js api'''
49+
result = []
50+
for this in self._get_candidates_for_resource(
51+
cr, uid, res_model, res_id, context=context):
52+
result.append({
53+
'id': this.id,
54+
'name': this.name_get()[0][1],
55+
})
56+
return result
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# This module copyright (C) 2014 Therp BV (<http://therp.nl>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
from openerp.osv.orm import Model
22+
23+
24+
class IrAttachment(Model):
25+
_inherit = 'ir.attachment'
26+
27+
def read(self, cr, uid, ids, fields_to_read=None, context=None,
28+
load='_classic_read'):
29+
'''inject the extra field we need in the web client. This saves us a
30+
couple of extra client side calls'''
31+
if fields_to_read == ['name', 'url', 'type', 'create_uid',
32+
'create_date', 'write_uid', 'write_date']:
33+
fields_to_read = fields_to_read + ['parent_id']
34+
result = super(IrAttachment, self).read(
35+
cr, uid, ids, fields_to_read=fields_to_read, context=context,
36+
load=load)
37+
return result

0 commit comments

Comments
 (0)