Merge lp:~savoirfairelinux-openerp/knowledge-addons/cmis_write into lp:knowledge-addons/7.0
- cmis_write
- Merge into 7.0
Status: | Rejected |
---|---|
Rejected by: | Sandy Carter (http://www.savoirfairelinux.com) |
Proposed branch: | lp:~savoirfairelinux-openerp/knowledge-addons/cmis_write |
Merge into: | lp:knowledge-addons/7.0 |
Diff against target: |
748 lines (+692/-0) 10 files modified
cmis_write/__init__.py (+26/-0) cmis_write/__openerp__.py (+88/-0) cmis_write/i18n/cmis_write.pot (+89/-0) cmis_write/ir_attachment.py (+223/-0) cmis_write/metadata.py (+67/-0) cmis_write/metadata_view.xml (+54/-0) cmis_write/security/ir.model.access.csv (+3/-0) cmis_write/static/src/js/document.js (+42/-0) cmis_write/tests/__init__.py (+29/-0) cmis_write/tests/test_attachment.py (+71/-0) |
To merge this branch: | bzr merge lp:~savoirfairelinux-openerp/knowledge-addons/cmis_write |
Related bugs: | |
Related blueprints: |
Store document file in a remote cmis server
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sandy Carter (http://www.savoirfairelinux.com) | Needs Resubmitting | ||
Maxime Chambreuil (http://www.savoirfairelinux.com) | Approve | ||
Review via email: mp+213940@code.launchpad.net |
Commit message
Description of the change
Add cmis_write: It allows to create docs from OE in DMS
- 17. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] fix pep8 error, add control when writting from OE
- 18. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] fix bug when we create job with session
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) : | # |
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote : | # |
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote : | # |
This MP should have a prerequisite branch: lp:~savoirfairelinux-openerp/knowledge-addons/cmis
l.301 missing context propagation
No unittests
Flake8
cmis_write/
cmis_write/
cmis_write/
cmis_write/
cmis_write/
cmis_write/
cmis_write/
El Hadji Dem (http://www.savoirfairelinux.com) (eh-dem) wrote : | # |
@scarter: thanks for comments
- 19. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] Take comments from LP
- 20. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] Change the module description
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote : | # |
l.416 Missing context propagation
Spelling:
You wrote OpenErp a few times. This should be OpenERP.
The description is oddly formulated, you may want it proofread.
Flake8:
cmis_write/
cmis_write/
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote : | # |
Still no unittests
- 21. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] FIxed comments from LP, added unittests,fix pep8 errors
- 22. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] update test file
- 23. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] update the create_doc_in_edm function
- 24. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] Download document from DMS
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) : | # |
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote : | # |
This MP have been moved to MP to https:/
Unmerged revisions
- 24. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] Download document from DMS
- 23. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] update the create_doc_in_edm function
- 22. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] update test file
- 21. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] FIxed comments from LP, added unittests,fix pep8 errors
- 20. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] Change the module description
- 19. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] Take comments from LP
- 18. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] fix bug when we create job with session
- 17. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[IMP] fix pep8 error, add control when writting from OE
- 16. By El Hadji Dem (http://www.savoirfairelinux.com)
-
[ADD] add cmis_write: It allows to create docs from OE in DMS
Preview Diff
1 | === added directory 'cmis_write' | |||
2 | === added file 'cmis_write/__init__.py' | |||
3 | --- cmis_write/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ cmis_write/__init__.py 2014-05-29 22:13:35 +0000 | |||
5 | @@ -0,0 +1,26 @@ | |||
6 | 1 | # -*- encoding: utf-8 -*- | ||
7 | 2 | ############################################################################## | ||
8 | 3 | # | ||
9 | 4 | # OpenERP, Open Source Management Solution | ||
10 | 5 | # This module copyright (C) 2014 Savoir-faire Linux | ||
11 | 6 | # (<http://www.savoirfairelinux.com>). | ||
12 | 7 | # | ||
13 | 8 | # This program is free software: you can redistribute it and/or modify | ||
14 | 9 | # it under the terms of the GNU Affero General Public License as | ||
15 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
16 | 11 | # License, or (at your option) any later version. | ||
17 | 12 | # | ||
18 | 13 | # This program is distributed in the hope that it will be useful, | ||
19 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | 16 | # GNU Affero General Public License for more details. | ||
22 | 17 | # | ||
23 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
24 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
25 | 20 | # | ||
26 | 21 | ############################################################################## | ||
27 | 22 | |||
28 | 23 | from . import ir_attachment | ||
29 | 24 | from . import metadata | ||
30 | 25 | |||
31 | 26 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | ||
32 | 0 | 27 | ||
33 | === added file 'cmis_write/__openerp__.py' | |||
34 | --- cmis_write/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
35 | +++ cmis_write/__openerp__.py 2014-05-29 22:13:35 +0000 | |||
36 | @@ -0,0 +1,88 @@ | |||
37 | 1 | # -*- encoding: utf-8 -*- | ||
38 | 2 | ############################################################################## | ||
39 | 3 | # | ||
40 | 4 | # OpenERP, Open Source Management Solution | ||
41 | 5 | # This module copyright (C) 2014 Savoir-faire Linux | ||
42 | 6 | # (<http://www.savoirfairelinux.com>). | ||
43 | 7 | # | ||
44 | 8 | # This program is free software: you can redistribute it and/or modify | ||
45 | 9 | # it under the terms of the GNU Affero General Public License as | ||
46 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
47 | 11 | # License, or (at your option) any later version. | ||
48 | 12 | # | ||
49 | 13 | # This program is distributed in the hope that it will be useful, | ||
50 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
51 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
52 | 16 | # GNU Affero General Public License for more details. | ||
53 | 17 | # | ||
54 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
55 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
56 | 20 | # | ||
57 | 21 | ############################################################################## | ||
58 | 22 | |||
59 | 23 | { | ||
60 | 24 | 'name': 'CMIS Write', | ||
61 | 25 | 'version': '0.1', | ||
62 | 26 | 'category': 'Knowledge Management', | ||
63 | 27 | 'summary': 'Create Document in DMS from OpenERP', | ||
64 | 28 | 'description': """ | ||
65 | 29 | Add Documents from OpenERP | ||
66 | 30 | ========================== | ||
67 | 31 | |||
68 | 32 | This module allows you to store OpenERP document in the DMS repository. | ||
69 | 33 | |||
70 | 34 | Configuration | ||
71 | 35 | ============= | ||
72 | 36 | |||
73 | 37 | * Create a new CMIS backend with the host, login and password. | ||
74 | 38 | * Configure the path in the repository where documents will be dropped. | ||
75 | 39 | By default, it uses the home directory of the user. | ||
76 | 40 | |||
77 | 41 | Usage | ||
78 | 42 | ===== | ||
79 | 43 | |||
80 | 44 | * On one OpenERP record, click "Add document". | ||
81 | 45 | * Upload your documents | ||
82 | 46 | * Uploaded documents will be enqueued for storage in the DMS | ||
83 | 47 | |||
84 | 48 | Add Metadata | ||
85 | 49 | ============ | ||
86 | 50 | |||
87 | 51 | To manage a custom aspect using CMIS (and all the other supported ways) | ||
88 | 52 | you have to: | ||
89 | 53 | |||
90 | 54 | * Define a new custom model configuring Alfresco. To do this I suggest you | ||
91 | 55 | http://wiki.alfresco.com/wiki/Step-By-Step:_Creating_A_Custom_Model. | ||
92 | 56 | |||
93 | 57 | * Add the custom aspect to the document you upload or create in Alfresco. | ||
94 | 58 | Using CMIS I suggest you: | ||
95 | 59 | http://docs.alfresco.com/4.1/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Fopencmis-ext-adding.html. | ||
96 | 60 | |||
97 | 61 | * Set the custom property in the way you probably know using CMIS. | ||
98 | 62 | |||
99 | 63 | Contributors | ||
100 | 64 | ------------ | ||
101 | 65 | * El Hadji Dem (elhadji.dem@savoirfairelinux.com) | ||
102 | 66 | """, | ||
103 | 67 | 'author': 'Savoir-faire Linux', | ||
104 | 68 | 'website': 'www.savoirfairelinux.com', | ||
105 | 69 | 'license': 'AGPL-3', | ||
106 | 70 | 'depends': [ | ||
107 | 71 | 'document', | ||
108 | 72 | 'cmis', | ||
109 | 73 | ], | ||
110 | 74 | 'data': [ | ||
111 | 75 | 'metadata_view.xml', | ||
112 | 76 | 'security/ir.model.access.csv', | ||
113 | 77 | ], | ||
114 | 78 | 'js': [ | ||
115 | 79 | 'static/src/js/document.js' | ||
116 | 80 | ], | ||
117 | 81 | 'qweb': [], | ||
118 | 82 | 'test': [], | ||
119 | 83 | 'demo': [], | ||
120 | 84 | 'installable': True, | ||
121 | 85 | 'auto_install': False, | ||
122 | 86 | } | ||
123 | 87 | |||
124 | 88 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | ||
125 | 0 | 89 | ||
126 | === added directory 'cmis_write/i18n' | |||
127 | === added file 'cmis_write/i18n/cmis_write.pot' | |||
128 | --- cmis_write/i18n/cmis_write.pot 1970-01-01 00:00:00 +0000 | |||
129 | +++ cmis_write/i18n/cmis_write.pot 2014-05-29 22:13:35 +0000 | |||
130 | @@ -0,0 +1,89 @@ | |||
131 | 1 | # Translation of OpenERP Server. | ||
132 | 2 | # This file contains the translation of the following modules: | ||
133 | 3 | # * cmis_write | ||
134 | 4 | # | ||
135 | 5 | msgid "" | ||
136 | 6 | msgstr "" | ||
137 | 7 | "Project-Id-Version: OpenERP Server 7.0\n" | ||
138 | 8 | "Report-Msgid-Bugs-To: \n" | ||
139 | 9 | "POT-Creation-Date: 2014-03-21 14:59+0000\n" | ||
140 | 10 | "PO-Revision-Date: 2014-03-21 10:59-0500\n" | ||
141 | 11 | "Last-Translator: EL Hadji DEM <elhadji.dem@savoirfairelinux.com>\n" | ||
142 | 12 | "Language-Team: \n" | ||
143 | 13 | "MIME-Version: 1.0\n" | ||
144 | 14 | "Content-Type: text/plain; charset=UTF-8\n" | ||
145 | 15 | "Content-Transfer-Encoding: 8bit\n" | ||
146 | 16 | "Plural-Forms: \n" | ||
147 | 17 | "X-Generator: Poedit 1.5.4\n" | ||
148 | 18 | |||
149 | 19 | #. module: cmis_write | ||
150 | 20 | #: model:_description:0 model:ir.model,name:cmis_write.model_metadata_list | ||
151 | 21 | msgid "List of Metadata" | ||
152 | 22 | msgstr "" | ||
153 | 23 | |||
154 | 24 | #. module: cmis_write | ||
155 | 25 | #: field:metadata,name:0 | ||
156 | 26 | msgid "Name" | ||
157 | 27 | msgstr "" | ||
158 | 28 | |||
159 | 29 | #. module: cmis_write | ||
160 | 30 | #: model:ir.actions.act_window,name:cmis_write.action_metadata | ||
161 | 31 | #: model:ir.ui.menu,name:cmis_write.menu_action_metadata | ||
162 | 32 | msgid "Metadata Editing" | ||
163 | 33 | msgstr "" | ||
164 | 34 | |||
165 | 35 | #. module: cmis_write | ||
166 | 36 | #: field:metadata,metadata_list_ids:0 | ||
167 | 37 | msgid "List of fields" | ||
168 | 38 | msgstr "" | ||
169 | 39 | |||
170 | 40 | #. module: cmis_write | ||
171 | 41 | #: field:metadata,field_ids:0 field:metadata.list,field_id:0 | ||
172 | 42 | msgid "Fields" | ||
173 | 43 | msgstr "" | ||
174 | 44 | |||
175 | 45 | #. module: cmis_write | ||
176 | 46 | #: view:metadata:0 | ||
177 | 47 | msgid "Object" | ||
178 | 48 | msgstr "" | ||
179 | 49 | |||
180 | 50 | #. module: cmis_write | ||
181 | 51 | #: view:metadata:0 | ||
182 | 52 | msgid "Metadata list fields form" | ||
183 | 53 | msgstr "" | ||
184 | 54 | |||
185 | 55 | #. module: cmis_write | ||
186 | 56 | #: help:ir.attachment,id_edm:0 | ||
187 | 57 | msgid "Id of Edm." | ||
188 | 58 | msgstr "" | ||
189 | 59 | |||
190 | 60 | #. module: cmis_write | ||
191 | 61 | #: field:ir.attachment,id_edm:0 | ||
192 | 62 | msgid "Id of Dms" | ||
193 | 63 | msgstr "" | ||
194 | 64 | |||
195 | 65 | #. module: cmis_write | ||
196 | 66 | #: view:metadata:0 | ||
197 | 67 | msgid "Metadata list fields Tree" | ||
198 | 68 | msgstr "" | ||
199 | 69 | |||
200 | 70 | #. module: cmis_write | ||
201 | 71 | #: field:metadata,model_id:0 | ||
202 | 72 | msgid "Model" | ||
203 | 73 | msgstr "" | ||
204 | 74 | |||
205 | 75 | #. module: cmis_write | ||
206 | 76 | #: field:metadata,model_ids:0 | ||
207 | 77 | msgid "Model List" | ||
208 | 78 | msgstr "" | ||
209 | 79 | |||
210 | 80 | #. module: cmis_write | ||
211 | 81 | #: model:_description:0 model:ir.model,name:cmis_write.model_ir_attachment | ||
212 | 82 | msgid "ir.attachment" | ||
213 | 83 | msgstr "" | ||
214 | 84 | |||
215 | 85 | #. module: cmis_write | ||
216 | 86 | #: model:_description:0 model:ir.model,name:cmis_write.model_metadata | ||
217 | 87 | #: field:metadata.list,metadata_id:0 | ||
218 | 88 | msgid "Metadata" | ||
219 | 89 | msgstr "" | ||
220 | 0 | 90 | ||
221 | === added file 'cmis_write/ir_attachment.py' | |||
222 | --- cmis_write/ir_attachment.py 1970-01-01 00:00:00 +0000 | |||
223 | +++ cmis_write/ir_attachment.py 2014-05-29 22:13:35 +0000 | |||
224 | @@ -0,0 +1,223 @@ | |||
225 | 1 | # -*- encoding: utf-8 -*- | ||
226 | 2 | ############################################################################## | ||
227 | 3 | # | ||
228 | 4 | # OpenERP, Open Source Management Solution | ||
229 | 5 | # This module copyright (C) 2014 Savoir-faire Linux | ||
230 | 6 | # (<http://www.savoirfairelinux.com>). | ||
231 | 7 | # | ||
232 | 8 | # This program is free software: you can redistribute it and/or modify | ||
233 | 9 | # it under the terms of the GNU Affero General Public License as | ||
234 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
235 | 11 | # License, or (at your option) any later version. | ||
236 | 12 | # | ||
237 | 13 | # This program is distributed in the hope that it will be useful, | ||
238 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
239 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
240 | 16 | # GNU Affero General Public License for more details. | ||
241 | 17 | # | ||
242 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
243 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
244 | 20 | # | ||
245 | 21 | ############################################################################## | ||
246 | 22 | |||
247 | 23 | from openerp.osv import orm, fields | ||
248 | 24 | from openerp.addons.connector.session import ConnectorSession | ||
249 | 25 | from openerp.addons.connector.queue.job import job | ||
250 | 26 | import base64 | ||
251 | 27 | from openerp import SUPERUSER_ID | ||
252 | 28 | from openerp.tools.translate import _ | ||
253 | 29 | import logging | ||
254 | 30 | _logger = logging.getLogger(__name__) | ||
255 | 31 | |||
256 | 32 | |||
257 | 33 | class ir_attachment_download(orm.TransientModel): | ||
258 | 34 | _name = 'ir.attachment.download' | ||
259 | 35 | |||
260 | 36 | _columns = { | ||
261 | 37 | 'name': fields.char('Attachment Name', size=256, required=True, | ||
262 | 38 | help='Attachment Name'), | ||
263 | 39 | 'datas': fields.binary('File', readonly=True), | ||
264 | 40 | 'type': fields.char('Type', size=256, help='Type'), | ||
265 | 41 | 'file_type': fields.char('Content Type', help='Content Type'), | ||
266 | 42 | 'attachment_id': fields.many2one('ir.attachment', 'Attachment'), | ||
267 | 43 | } | ||
268 | 44 | _defaults = { | ||
269 | 45 | 'type': 'binary', | ||
270 | 46 | } | ||
271 | 47 | |||
272 | 48 | |||
273 | 49 | class ir_attachment(orm.Model): | ||
274 | 50 | _inherit = 'ir.attachment' | ||
275 | 51 | |||
276 | 52 | def create(self, cr, uid, values, context=None): | ||
277 | 53 | metadata_obj = self.pool.get('metadata') | ||
278 | 54 | user_obj = self.pool.get('res.users') | ||
279 | 55 | user_login = user_obj.browse(cr, uid, uid, context=context).login | ||
280 | 56 | session = ConnectorSession(cr, uid, context=context) | ||
281 | 57 | value = { | ||
282 | 58 | 'name': values.get('name'), | ||
283 | 59 | 'datas_fname': values.get('datas_fname'), | ||
284 | 60 | 'file_type': values.get('file_type') or '', | ||
285 | 61 | 'datas': values.get('datas'), | ||
286 | 62 | 'description': values.get('description') or '', | ||
287 | 63 | |||
288 | 64 | } | ||
289 | 65 | |||
290 | 66 | metadata_ids = metadata_obj.search(cr, uid, [], context=context) | ||
291 | 67 | dict_metadata = {} | ||
292 | 68 | list_fields = [] | ||
293 | 69 | # Get list of metadata | ||
294 | 70 | if values.get('res_model'): | ||
295 | 71 | for line in metadata_obj.browse(cr, uid, metadata_ids, | ||
296 | 72 | context=context): | ||
297 | 73 | if line.model_id.model == values.get('res_model'): | ||
298 | 74 | if line.metadata_list_ids: | ||
299 | 75 | for one_field in line.metadata_list_ids: | ||
300 | 76 | list_fields.append(one_field.field_id.name) | ||
301 | 77 | result = self.pool.get(values.get('res_model')).read(cr, uid, [ | ||
302 | 78 | values.get('res_id')], list_fields, context=context)[0] | ||
303 | 79 | |||
304 | 80 | for one_field in list_fields: | ||
305 | 81 | dict_metadata['cmis:' + one_field] = result[one_field] | ||
306 | 82 | values['datas'] = None | ||
307 | 83 | res = super(ir_attachment, self).create(cr, uid, values, | ||
308 | 84 | context=context) | ||
309 | 85 | # Create Job | ||
310 | 86 | # if bool_testdoc in context, we don't need to create | ||
311 | 87 | # the doc in the DMS | ||
312 | 88 | if not context.get('bool_testdoc'): | ||
313 | 89 | create_doc_in_edm.delay( | ||
314 | 90 | session, 'ir.attachment', value, res, dict_metadata, | ||
315 | 91 | user_login) | ||
316 | 92 | return res | ||
317 | 93 | |||
318 | 94 | def action_download(self, cr, uid, ids, context=None): | ||
319 | 95 | if context is None: | ||
320 | 96 | context = {} | ||
321 | 97 | cmis_backend_obj = self.pool.get('cmis.backend') | ||
322 | 98 | # login with the cmis account | ||
323 | 99 | repo = cmis_backend_obj._auth(cr, uid, context=context) | ||
324 | 100 | cmis_backend_rec = self.read( | ||
325 | 101 | cr, uid, ids, ['id_dms'], context=context)[0] | ||
326 | 102 | id_dms = cmis_backend_rec['id_dms'] | ||
327 | 103 | # Get results from id of document | ||
328 | 104 | results = repo.query(" SELECT * FROM cmis:document WHERE \ | ||
329 | 105 | cmis:objectId ='" + id_dms + "'") | ||
330 | 106 | datas = results[0].getContentStream().read().encode('base64') | ||
331 | 107 | return datas | ||
332 | 108 | |||
333 | 109 | def _data_set(self, cr, uid, id, name, value, arg, context=None): | ||
334 | 110 | # We dont handle setting data to null | ||
335 | 111 | if not value: | ||
336 | 112 | return True | ||
337 | 113 | if context is None: | ||
338 | 114 | context = {} | ||
339 | 115 | location = self.pool.get('ir.config_parameter').get_param( | ||
340 | 116 | cr, uid, 'ir_attachment.location') | ||
341 | 117 | file_size = len(value.decode('base64')) | ||
342 | 118 | if location: | ||
343 | 119 | attach = self.browse(cr, uid, id, context=context) | ||
344 | 120 | if attach.store_fname: | ||
345 | 121 | self._file_delete(cr, uid, location, attach.store_fname) | ||
346 | 122 | fname = self._file_write(cr, uid, location, value) | ||
347 | 123 | # SUPERUSER_ID as probably don't have write access, | ||
348 | 124 | # trigger during create | ||
349 | 125 | super(ir_attachment, self).write( | ||
350 | 126 | cr, SUPERUSER_ID, [id], | ||
351 | 127 | {'store_fname': fname, 'file_size': file_size}, | ||
352 | 128 | context=context) | ||
353 | 129 | else: | ||
354 | 130 | super(ir_attachment, self).write( | ||
355 | 131 | cr, SUPERUSER_ID, [id], | ||
356 | 132 | {'db_datas': value, 'file_size': file_size}, context=context) | ||
357 | 133 | return True | ||
358 | 134 | |||
359 | 135 | def _data_get(self, cr, uid, ids, name, arg, context=None): | ||
360 | 136 | if context is None: | ||
361 | 137 | context = {} | ||
362 | 138 | result = {} | ||
363 | 139 | location = self.pool.get('ir.config_parameter').get_param( | ||
364 | 140 | cr, uid, 'ir_attachment.location') | ||
365 | 141 | bin_size = context.get('bin_size') | ||
366 | 142 | for attach in self.browse(cr, uid, ids, context=context): | ||
367 | 143 | if location and attach.store_fname: | ||
368 | 144 | result[attach.id] = self._file_read( | ||
369 | 145 | cr, uid, location, attach.store_fname, bin_size) | ||
370 | 146 | elif attach.id_dms: | ||
371 | 147 | datas = self.action_download( | ||
372 | 148 | cr, uid, attach.id, context=context) | ||
373 | 149 | result[attach.id] = datas | ||
374 | 150 | file_type, index_content = self._index( | ||
375 | 151 | cr, uid, datas.decode('base64'), attach.datas_fname, None) | ||
376 | 152 | self.write( | ||
377 | 153 | cr, uid, [attach.id], | ||
378 | 154 | {'file_type': file_type, 'index_content': index_content}, | ||
379 | 155 | context=context) | ||
380 | 156 | else: | ||
381 | 157 | raise orm.except_orm(_('Access error of document'), | ||
382 | 158 | _("Document is not available in DMS; " | ||
383 | 159 | "Please try again")) | ||
384 | 160 | return result | ||
385 | 161 | |||
386 | 162 | _columns = { | ||
387 | 163 | 'id_dms': fields.char('Id of Dms', size=256, help="Id of Dms."), | ||
388 | 164 | 'download_id': fields.one2many('ir.attachment.download', | ||
389 | 165 | 'attachment_id', | ||
390 | 166 | 'Attachment download'), | ||
391 | 167 | 'datas': fields.function(_data_get, fnct_inv=_data_set, | ||
392 | 168 | string='File Content', | ||
393 | 169 | type="binary", nodrop=True), | ||
394 | 170 | } | ||
395 | 171 | |||
396 | 172 | |||
397 | 173 | @job | ||
398 | 174 | def create_doc_in_edm(session, model_name, value, res, | ||
399 | 175 | dict_metadata, user_login, filters=None): | ||
400 | 176 | ir_attach_obj = session.pool.get('ir.attachment') | ||
401 | 177 | cmis_backend_obj = session.pool.get('cmis.backend') | ||
402 | 178 | if session.context is None: | ||
403 | 179 | session.context = {} | ||
404 | 180 | # login with the cmis account | ||
405 | 181 | repo = cmis_backend_obj._auth(session.cr, session.uid, | ||
406 | 182 | context=session.context) | ||
407 | 183 | root = repo.rootFolder | ||
408 | 184 | ids = cmis_backend_obj.search(session.cr, session.uid, [], session.context) | ||
409 | 185 | |||
410 | 186 | folder_path = cmis_backend_obj.read( | ||
411 | 187 | session.cr, session.uid, | ||
412 | 188 | ids, | ||
413 | 189 | ['initial_directory_write'], | ||
414 | 190 | context=session.context)[0]['initial_directory_write'] | ||
415 | 191 | # Document properties | ||
416 | 192 | if value['name']: | ||
417 | 193 | file_name = value['name'] | ||
418 | 194 | elif value['datas_fname']: | ||
419 | 195 | file_name = value['datas_fname'] | ||
420 | 196 | else: | ||
421 | 197 | file_name = value['datas_fname'] | ||
422 | 198 | props = { | ||
423 | 199 | 'cmis:name': file_name, | ||
424 | 200 | 'cmis:description': value['description'], | ||
425 | 201 | 'cmis:createdBy': user_login, | ||
426 | 202 | } | ||
427 | 203 | # Add list of metadata in props | ||
428 | 204 | if len(dict_metadata): | ||
429 | 205 | for k, v in dict_metadata.iteritems(): | ||
430 | 206 | props[k] = v | ||
431 | 207 | if folder_path: | ||
432 | 208 | sub1 = repo.getObjectByPath(folder_path) | ||
433 | 209 | else: | ||
434 | 210 | sub1 = root | ||
435 | 211 | someDoc = sub1.createDocumentFromString(file_name, | ||
436 | 212 | contentString=base64.b64decode( | ||
437 | 213 | value['datas']), | ||
438 | 214 | contentType=value['file_type']) | ||
439 | 215 | # TODO: create custom properties on a document (Alfresco) | ||
440 | 216 | # someDoc.getProperties().update(props) | ||
441 | 217 | # Updating ir.attachment object with the new id | ||
442 | 218 | # of document generated by DMS | ||
443 | 219 | ir_attach_obj.write(session.cr, session.uid, res, { | ||
444 | 220 | 'id_dms': someDoc.getObjectId()}, session.context) | ||
445 | 221 | return True | ||
446 | 222 | |||
447 | 223 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | ||
448 | 0 | 224 | ||
449 | === added file 'cmis_write/metadata.py' | |||
450 | --- cmis_write/metadata.py 1970-01-01 00:00:00 +0000 | |||
451 | +++ cmis_write/metadata.py 2014-05-29 22:13:35 +0000 | |||
452 | @@ -0,0 +1,67 @@ | |||
453 | 1 | # -*- encoding: utf-8 -*- | ||
454 | 2 | ############################################################################## | ||
455 | 3 | # | ||
456 | 4 | # OpenERP, Open Source Management Solution | ||
457 | 5 | # This module copyright (C) 2014 Savoir-faire Linux | ||
458 | 6 | # (<http://www.savoirfairelinux.com>). | ||
459 | 7 | # | ||
460 | 8 | # This program is free software: you can redistribute it and/or modify | ||
461 | 9 | # it under the terms of the GNU Affero General Public License as | ||
462 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
463 | 11 | # License, or (at your option) any later version. | ||
464 | 12 | # | ||
465 | 13 | # This program is distributed in the hope that it will be useful, | ||
466 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
467 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
468 | 16 | # GNU Affero General Public License for more details. | ||
469 | 17 | # | ||
470 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
471 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
472 | 20 | # | ||
473 | 21 | ############################################################################## | ||
474 | 22 | |||
475 | 23 | from openerp.osv import orm, fields | ||
476 | 24 | |||
477 | 25 | |||
478 | 26 | class metadata_list(orm.Model): | ||
479 | 27 | _description = 'List of Metadata' | ||
480 | 28 | _name = 'metadata.list' | ||
481 | 29 | |||
482 | 30 | _columns = { | ||
483 | 31 | 'field_id': fields.many2one('ir.model.fields', 'Fields'), | ||
484 | 32 | 'metadata_id': fields.many2one('metadata', 'Metadata'), | ||
485 | 33 | } | ||
486 | 34 | |||
487 | 35 | |||
488 | 36 | class metadata(orm.Model): | ||
489 | 37 | _name = "metadata" | ||
490 | 38 | _description = "Metadata" | ||
491 | 39 | _columns = { | ||
492 | 40 | 'name': fields.char("Name", size=64, required=True, select=1), | ||
493 | 41 | 'model_id': fields.many2one('ir.model', 'Model', | ||
494 | 42 | required=True, select=1), | ||
495 | 43 | 'field_ids': fields.many2many('ir.model.fields', 'metadata_field_rel', | ||
496 | 44 | 'meta_id', 'field_id', 'Fields'), | ||
497 | 45 | 'metadata_list_ids': fields.one2many('metadata.list', 'metadata_id', | ||
498 | 46 | 'List of fields'), | ||
499 | 47 | 'model_ids': fields.many2many('ir.model', string='Model List'), | ||
500 | 48 | } | ||
501 | 49 | |||
502 | 50 | def onchange_model(self, cr, uid, ids, model_id, context=None): | ||
503 | 51 | if context is None: | ||
504 | 52 | context = {} | ||
505 | 53 | if not model_id: | ||
506 | 54 | return {'value': {'model_ids': [(6, 0, [])]}} | ||
507 | 55 | model_ids = [model_id] | ||
508 | 56 | model_obj = self.pool.get('ir.model') | ||
509 | 57 | active_model_obj = self.pool.get(model_obj.browse( | ||
510 | 58 | cr, uid, model_id, context=context).model) | ||
511 | 59 | if active_model_obj._inherits: | ||
512 | 60 | for key, val in active_model_obj._inherits.items(): | ||
513 | 61 | found_model_ids = model_obj.search(cr, | ||
514 | 62 | uid, [('model', '=', key)], | ||
515 | 63 | context=context) | ||
516 | 64 | model_ids += found_model_ids | ||
517 | 65 | return {'value': {'model_ids': [(6, 0, model_ids)]}} | ||
518 | 66 | |||
519 | 67 | # vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4: | ||
520 | 0 | 68 | ||
521 | === added file 'cmis_write/metadata_view.xml' | |||
522 | --- cmis_write/metadata_view.xml 1970-01-01 00:00:00 +0000 | |||
523 | +++ cmis_write/metadata_view.xml 2014-05-29 22:13:35 +0000 | |||
524 | @@ -0,0 +1,54 @@ | |||
525 | 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
526 | 2 | <openerp> | ||
527 | 3 | <data> | ||
528 | 4 | |||
529 | 5 | <record model="ir.ui.view" id="view_mass_object_form"> | ||
530 | 6 | <field name="name">metadata.form</field> | ||
531 | 7 | <field name="model">metadata</field> | ||
532 | 8 | <field name="type">form</field> | ||
533 | 9 | <field name="arch" type="xml"> | ||
534 | 10 | <form string="Object"> | ||
535 | 11 | <field name="name"/> | ||
536 | 12 | <field name="model_id" on_change="onchange_model(model_id)"/> | ||
537 | 13 | <field name="model_ids" invisible="1"/> | ||
538 | 14 | <field name="metadata_list_ids" colspan="4" nolabel="1"> | ||
539 | 15 | <tree string="Metadata list fields Tree" version="7.0" editable="bottom"> | ||
540 | 16 | <field name="field_id" | ||
541 | 17 | domain="[('ttype', 'not in', ['reference', 'function']), | ||
542 | 18 | ('model_id', 'in', parent.model_ids[0][2])]"/> | ||
543 | 19 | </tree> | ||
544 | 20 | <form string="Metadata list fields form"> | ||
545 | 21 | <field name="field_id"/> | ||
546 | 22 | </form> | ||
547 | 23 | </field> | ||
548 | 24 | </form> | ||
549 | 25 | </field> | ||
550 | 26 | </record> | ||
551 | 27 | |||
552 | 28 | <record model="ir.ui.view" id="view_metadata_tree"> | ||
553 | 29 | <field name="name">metadata.tree</field> | ||
554 | 30 | <field name="model">metadata</field> | ||
555 | 31 | <field name="type">form</field> | ||
556 | 32 | <field name="arch" type="xml"> | ||
557 | 33 | <tree string="Object"> | ||
558 | 34 | <field name="name"/> | ||
559 | 35 | <field name="model_id"/> | ||
560 | 36 | </tree> | ||
561 | 37 | </field> | ||
562 | 38 | </record> | ||
563 | 39 | |||
564 | 40 | <record id="action_metadata" model="ir.actions.act_window"> | ||
565 | 41 | <field name="name">Metadata Editing</field> | ||
566 | 42 | <field name="view_id" ref="view_metadata_tree"/> | ||
567 | 43 | <field name="res_model">metadata</field> | ||
568 | 44 | <field name="view_mode">tree,form</field> | ||
569 | 45 | </record> | ||
570 | 46 | |||
571 | 47 | <menuitem name="Metadata Editing" | ||
572 | 48 | id="menu_action_metadata" | ||
573 | 49 | sequence="10" | ||
574 | 50 | parent="document.menu_document_management_configuration" | ||
575 | 51 | action="action_metadata"/> | ||
576 | 52 | |||
577 | 53 | </data> | ||
578 | 54 | </openerp> | ||
579 | 0 | 55 | ||
580 | === added directory 'cmis_write/security' | |||
581 | === added file 'cmis_write/security/ir.model.access.csv' | |||
582 | --- cmis_write/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 | |||
583 | +++ cmis_write/security/ir.model.access.csv 2014-05-29 22:13:35 +0000 | |||
584 | @@ -0,0 +1,3 @@ | |||
585 | 1 | id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
586 | 2 | access_metadata_list_group_user,metadata.list user,model_metadata_list,base.group_document_user,1,1,1,1 | ||
587 | 3 | access_metadata,access_metadata,model_metadata,base.group_document_user,1,1,1,1 | ||
588 | 0 | 4 | ||
589 | === added directory 'cmis_write/static' | |||
590 | === added directory 'cmis_write/static/src' | |||
591 | === added directory 'cmis_write/static/src/js' | |||
592 | === added file 'cmis_write/static/src/js/document.js' | |||
593 | --- cmis_write/static/src/js/document.js 1970-01-01 00:00:00 +0000 | |||
594 | +++ cmis_write/static/src/js/document.js 2014-05-29 22:13:35 +0000 | |||
595 | @@ -0,0 +1,42 @@ | |||
596 | 1 | openerp.cmis_write = function(instance, m) { | ||
597 | 2 | var _t = instance.web._t, | ||
598 | 3 | QWeb = instance.web.qweb; | ||
599 | 4 | |||
600 | 5 | instance.web.Sidebar.include({ | ||
601 | 6 | start: function() { | ||
602 | 7 | var self = this; | ||
603 | 8 | this._super(this); | ||
604 | 9 | this.redraw(); | ||
605 | 10 | this.$el.on('click','.oe_dropdown_menu li a', function(event) { | ||
606 | 11 | var section = $(this).data('section'); | ||
607 | 12 | var index = $(this).data('index'); | ||
608 | 13 | var item = self.items[section][index]; | ||
609 | 14 | if (item.callback) { | ||
610 | 15 | item.callback.apply(self, [item]); | ||
611 | 16 | } else if (item.action) { | ||
612 | 17 | self.on_item_action_clicked(item); | ||
613 | 18 | } else if (!item.id_dms) { | ||
614 | 19 | alert(_t("Document is not available in DMS.Please try again !!!")); | ||
615 | 20 | } else if (item.url) { | ||
616 | 21 | return true; | ||
617 | 22 | } | ||
618 | 23 | event.preventDefault(); | ||
619 | 24 | }); | ||
620 | 25 | }, | ||
621 | 26 | do_attachement_update: function(dataset, model_id, args) { | ||
622 | 27 | var self = this; | ||
623 | 28 | this.dataset = dataset; | ||
624 | 29 | this.model_id = model_id; | ||
625 | 30 | if (args && args[0].error) { | ||
626 | 31 | this.do_warn(_t('Uploading Error'), args[0].error); | ||
627 | 32 | } | ||
628 | 33 | if (!model_id) { | ||
629 | 34 | this.on_attachments_loaded([]); | ||
630 | 35 | } else { | ||
631 | 36 | var dom = [ ['res_model', '=', dataset.model], ['res_id', '=', model_id], ['type', 'in', ['binary', 'url']] ]; | ||
632 | 37 | var ds = new instance.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom); | ||
633 | 38 | ds.read_slice(['name', 'url', 'id_dms','type', 'create_uid', 'create_date', 'write_uid', 'write_date'], {}).done(this.on_attachments_loaded); | ||
634 | 39 | } | ||
635 | 40 | }, | ||
636 | 41 | }); | ||
637 | 42 | }; | ||
638 | 0 | 43 | ||
639 | === added directory 'cmis_write/tests' | |||
640 | === added file 'cmis_write/tests/__init__.py' | |||
641 | --- cmis_write/tests/__init__.py 1970-01-01 00:00:00 +0000 | |||
642 | +++ cmis_write/tests/__init__.py 2014-05-29 22:13:35 +0000 | |||
643 | @@ -0,0 +1,29 @@ | |||
644 | 1 | # -*- coding: utf-8 -*- | ||
645 | 2 | |||
646 | 3 | ############################################################################## | ||
647 | 4 | # | ||
648 | 5 | # OpenERP, Open Source Management Solution | ||
649 | 6 | # Copyright (C) 2014 Savoir-faire Linux (<http://www.savoirfairelinux.com>). | ||
650 | 7 | # | ||
651 | 8 | # This program is free software: you can redistribute it and/or modify | ||
652 | 9 | # it under the terms of the GNU Affero General Public License as | ||
653 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
654 | 11 | # License, or (at your option) any later version. | ||
655 | 12 | # | ||
656 | 13 | # This program is distributed in the hope that it will be useful, | ||
657 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
658 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
659 | 16 | # GNU Affero General Public License for more details. | ||
660 | 17 | # | ||
661 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
662 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
663 | 20 | # | ||
664 | 21 | ############################################################################## | ||
665 | 22 | |||
666 | 23 | from . import ( | ||
667 | 24 | test_attachment, | ||
668 | 25 | ) | ||
669 | 26 | |||
670 | 27 | checks = [ | ||
671 | 28 | test_attachment, | ||
672 | 29 | ] | ||
673 | 0 | 30 | ||
674 | === added file 'cmis_write/tests/test_attachment.py' | |||
675 | --- cmis_write/tests/test_attachment.py 1970-01-01 00:00:00 +0000 | |||
676 | +++ cmis_write/tests/test_attachment.py 2014-05-29 22:13:35 +0000 | |||
677 | @@ -0,0 +1,71 @@ | |||
678 | 1 | # -*- encoding: utf-8 -*- | ||
679 | 2 | ############################################################################### | ||
680 | 3 | # | ||
681 | 4 | # OpenERP, Open Source Management Solution | ||
682 | 5 | # This module copyright (C) 2010 - 2014 Savoir-faire Linux | ||
683 | 6 | # (<http://www.savoirfairelinux.com>). | ||
684 | 7 | # | ||
685 | 8 | # This program is free software: you can redistribute it and/or modify | ||
686 | 9 | # it under the terms of the GNU Affero General Public License as | ||
687 | 10 | # published by the Free Software Foundation, either version 3 of the | ||
688 | 11 | # License, or (at your option) any later version. | ||
689 | 12 | # | ||
690 | 13 | # This program is distributed in the hope that it will be useful, | ||
691 | 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
692 | 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
693 | 16 | # GNU Affero General Public License for more details. | ||
694 | 17 | # | ||
695 | 18 | # You should have received a copy of the GNU Affero General Public License | ||
696 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
697 | 20 | # | ||
698 | 21 | ############################################################################### | ||
699 | 22 | |||
700 | 23 | from openerp.tests.common import TransactionCase | ||
701 | 24 | from openerp.addons.connector.session import ConnectorSession | ||
702 | 25 | |||
703 | 26 | |||
704 | 27 | class test_attachment(TransactionCase): | ||
705 | 28 | |||
706 | 29 | def setUp(self): | ||
707 | 30 | super(test_attachment, self).setUp() | ||
708 | 31 | # Clean up registries | ||
709 | 32 | self.registry('ir.model').clear_caches() | ||
710 | 33 | self.registry('ir.model.data').clear_caches() | ||
711 | 34 | # Get registries | ||
712 | 35 | self.user_model = self.registry("res.users") | ||
713 | 36 | self.ir_attachment_model = self.registry("ir.attachment") | ||
714 | 37 | self.partner_model = self.registry('res.partner') | ||
715 | 38 | self.metadata_model = self.registry('metadata') | ||
716 | 39 | # Get context | ||
717 | 40 | self.context = self.user_model.context_get(self.cr, self.uid) | ||
718 | 41 | |||
719 | 42 | partner_id = self.partner_model.create( | ||
720 | 43 | self.cr, self.uid, | ||
721 | 44 | {'name': 'Test Partner', | ||
722 | 45 | 'email': 'test@localhost', | ||
723 | 46 | 'is_company': True, | ||
724 | 47 | }, context=None) | ||
725 | 48 | |||
726 | 49 | blob1 = 'blob1' | ||
727 | 50 | blob1_b64 = blob1.encode('base64') | ||
728 | 51 | |||
729 | 52 | self.vals = { | ||
730 | 53 | 'name': 'a1', | ||
731 | 54 | 'datas': blob1_b64, | ||
732 | 55 | 'attachment_document_ids': [(0, 0, { | ||
733 | 56 | 'res_model': "res.partner", | ||
734 | 57 | 'res_id': partner_id, | ||
735 | 58 | 'res_name': 'Test Partner', | ||
736 | 59 | })], | ||
737 | 60 | } | ||
738 | 61 | |||
739 | 62 | def test_create_test_attachment(self): | ||
740 | 63 | cr, uid, vals, context = self.cr, self.uid, self.vals, self.context | ||
741 | 64 | vals['datas'] = None | ||
742 | 65 | context['bool_testdoc'] = True | ||
743 | 66 | ir_attachment_id = self.ir_attachment_model.create( | ||
744 | 67 | cr, uid, vals, context=context) | ||
745 | 68 | ir_attachment_pool = self.ir_attachment_model.browse( | ||
746 | 69 | cr, uid, ir_attachment_id, context=context) | ||
747 | 70 | |||
748 | 71 | self.assertEqual(ir_attachment_pool.name, vals['name']) |
test