Merge lp:~savoirfairelinux-openerp/knowledge-addons/cmis_write into lp:knowledge-addons/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
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

Description of the change

Add cmis_write: It allows to create docs from OE in DMS

To post a comment you must log in.
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

Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) :
review: Approve
Revision history for this message
Maxime Chambreuil (http://www.savoirfairelinux.com) (max3903) wrote :

test

Revision history for this message
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/ir_attachment.py:73:45: W291 trailing whitespace
cmis_write/ir_attachment.py:74:53: W291 trailing whitespace
cmis_write/ir_attachment.py:75:43: W291 trailing whitespace
cmis_write/ir_attachment.py:76:41: W291 trailing whitespace
cmis_write/ir_attachment.py:77:51: W291 trailing whitespace
cmis_write/ir_attachment.py:89:5: E265 block comment should start with '# '
cmis_write/metadata.py:23:1: F401 'osv' imported but unused

review: Needs Fixing
Revision history for this message
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

Revision history for this message
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/__openerp__.py:58:26: W291 trailing whitespace
cmis_write/ir_attachment.py:125:5: E265 block comment should start with '# '

review: Needs Fixing
Revision history for this message
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

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) :
Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

This MP have been moved to MP to https://github.com/OCA/knowledge/pull/8

review: Needs Resubmitting

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

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

Subscribers

People subscribed via source and target branches

to status/vote changes: