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
=== added directory 'cmis_write'
=== added file 'cmis_write/__init__.py'
--- cmis_write/__init__.py 1970-01-01 00:00:00 +0000
+++ cmis_write/__init__.py 2014-05-29 22:13:35 +0000
@@ -0,0 +1,26 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import ir_attachment
24from . import metadata
25
26# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
027
=== added file 'cmis_write/__openerp__.py'
--- cmis_write/__openerp__.py 1970-01-01 00:00:00 +0000
+++ cmis_write/__openerp__.py 2014-05-29 22:13:35 +0000
@@ -0,0 +1,88 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23{
24 'name': 'CMIS Write',
25 'version': '0.1',
26 'category': 'Knowledge Management',
27 'summary': 'Create Document in DMS from OpenERP',
28 'description': """
29Add Documents from OpenERP
30==========================
31
32This module allows you to store OpenERP document in the DMS repository.
33
34Configuration
35=============
36
37* Create a new CMIS backend with the host, login and password.
38* Configure the path in the repository where documents will be dropped.
39 By default, it uses the home directory of the user.
40
41Usage
42=====
43
44* On one OpenERP record, click "Add document".
45* Upload your documents
46* Uploaded documents will be enqueued for storage in the DMS
47
48Add Metadata
49============
50
51To manage a custom aspect using CMIS (and all the other supported ways)
52you have to:
53
54* Define a new custom model configuring Alfresco. To do this I suggest you
55http://wiki.alfresco.com/wiki/Step-By-Step:_Creating_A_Custom_Model.
56
57* Add the custom aspect to the document you upload or create in Alfresco.
58Using CMIS I suggest you:
59http://docs.alfresco.com/4.1/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Fconcepts%2Fopencmis-ext-adding.html.
60
61* Set the custom property in the way you probably know using CMIS.
62
63Contributors
64------------
65* El Hadji Dem (elhadji.dem@savoirfairelinux.com)
66""",
67 'author': 'Savoir-faire Linux',
68 'website': 'www.savoirfairelinux.com',
69 'license': 'AGPL-3',
70 'depends': [
71 'document',
72 'cmis',
73 ],
74 'data': [
75 'metadata_view.xml',
76 'security/ir.model.access.csv',
77 ],
78 'js': [
79 'static/src/js/document.js'
80 ],
81 'qweb': [],
82 'test': [],
83 'demo': [],
84 'installable': True,
85 'auto_install': False,
86}
87
88# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
089
=== added directory 'cmis_write/i18n'
=== added file 'cmis_write/i18n/cmis_write.pot'
--- cmis_write/i18n/cmis_write.pot 1970-01-01 00:00:00 +0000
+++ cmis_write/i18n/cmis_write.pot 2014-05-29 22:13:35 +0000
@@ -0,0 +1,89 @@
1# Translation of OpenERP Server.
2# This file contains the translation of the following modules:
3# * cmis_write
4#
5msgid ""
6msgstr ""
7"Project-Id-Version: OpenERP Server 7.0\n"
8"Report-Msgid-Bugs-To: \n"
9"POT-Creation-Date: 2014-03-21 14:59+0000\n"
10"PO-Revision-Date: 2014-03-21 10:59-0500\n"
11"Last-Translator: EL Hadji DEM <elhadji.dem@savoirfairelinux.com>\n"
12"Language-Team: \n"
13"MIME-Version: 1.0\n"
14"Content-Type: text/plain; charset=UTF-8\n"
15"Content-Transfer-Encoding: 8bit\n"
16"Plural-Forms: \n"
17"X-Generator: Poedit 1.5.4\n"
18
19#. module: cmis_write
20#: model:_description:0 model:ir.model,name:cmis_write.model_metadata_list
21msgid "List of Metadata"
22msgstr ""
23
24#. module: cmis_write
25#: field:metadata,name:0
26msgid "Name"
27msgstr ""
28
29#. module: cmis_write
30#: model:ir.actions.act_window,name:cmis_write.action_metadata
31#: model:ir.ui.menu,name:cmis_write.menu_action_metadata
32msgid "Metadata Editing"
33msgstr ""
34
35#. module: cmis_write
36#: field:metadata,metadata_list_ids:0
37msgid "List of fields"
38msgstr ""
39
40#. module: cmis_write
41#: field:metadata,field_ids:0 field:metadata.list,field_id:0
42msgid "Fields"
43msgstr ""
44
45#. module: cmis_write
46#: view:metadata:0
47msgid "Object"
48msgstr ""
49
50#. module: cmis_write
51#: view:metadata:0
52msgid "Metadata list fields form"
53msgstr ""
54
55#. module: cmis_write
56#: help:ir.attachment,id_edm:0
57msgid "Id of Edm."
58msgstr ""
59
60#. module: cmis_write
61#: field:ir.attachment,id_edm:0
62msgid "Id of Dms"
63msgstr ""
64
65#. module: cmis_write
66#: view:metadata:0
67msgid "Metadata list fields Tree"
68msgstr ""
69
70#. module: cmis_write
71#: field:metadata,model_id:0
72msgid "Model"
73msgstr ""
74
75#. module: cmis_write
76#: field:metadata,model_ids:0
77msgid "Model List"
78msgstr ""
79
80#. module: cmis_write
81#: model:_description:0 model:ir.model,name:cmis_write.model_ir_attachment
82msgid "ir.attachment"
83msgstr ""
84
85#. module: cmis_write
86#: model:_description:0 model:ir.model,name:cmis_write.model_metadata
87#: field:metadata.list,metadata_id:0
88msgid "Metadata"
89msgstr ""
090
=== added file 'cmis_write/ir_attachment.py'
--- cmis_write/ir_attachment.py 1970-01-01 00:00:00 +0000
+++ cmis_write/ir_attachment.py 2014-05-29 22:13:35 +0000
@@ -0,0 +1,223 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from openerp.osv import orm, fields
24from openerp.addons.connector.session import ConnectorSession
25from openerp.addons.connector.queue.job import job
26import base64
27from openerp import SUPERUSER_ID
28from openerp.tools.translate import _
29import logging
30_logger = logging.getLogger(__name__)
31
32
33class ir_attachment_download(orm.TransientModel):
34 _name = 'ir.attachment.download'
35
36 _columns = {
37 'name': fields.char('Attachment Name', size=256, required=True,
38 help='Attachment Name'),
39 'datas': fields.binary('File', readonly=True),
40 'type': fields.char('Type', size=256, help='Type'),
41 'file_type': fields.char('Content Type', help='Content Type'),
42 'attachment_id': fields.many2one('ir.attachment', 'Attachment'),
43 }
44 _defaults = {
45 'type': 'binary',
46 }
47
48
49class ir_attachment(orm.Model):
50 _inherit = 'ir.attachment'
51
52 def create(self, cr, uid, values, context=None):
53 metadata_obj = self.pool.get('metadata')
54 user_obj = self.pool.get('res.users')
55 user_login = user_obj.browse(cr, uid, uid, context=context).login
56 session = ConnectorSession(cr, uid, context=context)
57 value = {
58 'name': values.get('name'),
59 'datas_fname': values.get('datas_fname'),
60 'file_type': values.get('file_type') or '',
61 'datas': values.get('datas'),
62 'description': values.get('description') or '',
63
64 }
65
66 metadata_ids = metadata_obj.search(cr, uid, [], context=context)
67 dict_metadata = {}
68 list_fields = []
69 # Get list of metadata
70 if values.get('res_model'):
71 for line in metadata_obj.browse(cr, uid, metadata_ids,
72 context=context):
73 if line.model_id.model == values.get('res_model'):
74 if line.metadata_list_ids:
75 for one_field in line.metadata_list_ids:
76 list_fields.append(one_field.field_id.name)
77 result = self.pool.get(values.get('res_model')).read(cr, uid, [
78 values.get('res_id')], list_fields, context=context)[0]
79
80 for one_field in list_fields:
81 dict_metadata['cmis:' + one_field] = result[one_field]
82 values['datas'] = None
83 res = super(ir_attachment, self).create(cr, uid, values,
84 context=context)
85 # Create Job
86 # if bool_testdoc in context, we don't need to create
87 # the doc in the DMS
88 if not context.get('bool_testdoc'):
89 create_doc_in_edm.delay(
90 session, 'ir.attachment', value, res, dict_metadata,
91 user_login)
92 return res
93
94 def action_download(self, cr, uid, ids, context=None):
95 if context is None:
96 context = {}
97 cmis_backend_obj = self.pool.get('cmis.backend')
98 # login with the cmis account
99 repo = cmis_backend_obj._auth(cr, uid, context=context)
100 cmis_backend_rec = self.read(
101 cr, uid, ids, ['id_dms'], context=context)[0]
102 id_dms = cmis_backend_rec['id_dms']
103 # Get results from id of document
104 results = repo.query(" SELECT * FROM cmis:document WHERE \
105 cmis:objectId ='" + id_dms + "'")
106 datas = results[0].getContentStream().read().encode('base64')
107 return datas
108
109 def _data_set(self, cr, uid, id, name, value, arg, context=None):
110 # We dont handle setting data to null
111 if not value:
112 return True
113 if context is None:
114 context = {}
115 location = self.pool.get('ir.config_parameter').get_param(
116 cr, uid, 'ir_attachment.location')
117 file_size = len(value.decode('base64'))
118 if location:
119 attach = self.browse(cr, uid, id, context=context)
120 if attach.store_fname:
121 self._file_delete(cr, uid, location, attach.store_fname)
122 fname = self._file_write(cr, uid, location, value)
123 # SUPERUSER_ID as probably don't have write access,
124 # trigger during create
125 super(ir_attachment, self).write(
126 cr, SUPERUSER_ID, [id],
127 {'store_fname': fname, 'file_size': file_size},
128 context=context)
129 else:
130 super(ir_attachment, self).write(
131 cr, SUPERUSER_ID, [id],
132 {'db_datas': value, 'file_size': file_size}, context=context)
133 return True
134
135 def _data_get(self, cr, uid, ids, name, arg, context=None):
136 if context is None:
137 context = {}
138 result = {}
139 location = self.pool.get('ir.config_parameter').get_param(
140 cr, uid, 'ir_attachment.location')
141 bin_size = context.get('bin_size')
142 for attach in self.browse(cr, uid, ids, context=context):
143 if location and attach.store_fname:
144 result[attach.id] = self._file_read(
145 cr, uid, location, attach.store_fname, bin_size)
146 elif attach.id_dms:
147 datas = self.action_download(
148 cr, uid, attach.id, context=context)
149 result[attach.id] = datas
150 file_type, index_content = self._index(
151 cr, uid, datas.decode('base64'), attach.datas_fname, None)
152 self.write(
153 cr, uid, [attach.id],
154 {'file_type': file_type, 'index_content': index_content},
155 context=context)
156 else:
157 raise orm.except_orm(_('Access error of document'),
158 _("Document is not available in DMS; "
159 "Please try again"))
160 return result
161
162 _columns = {
163 'id_dms': fields.char('Id of Dms', size=256, help="Id of Dms."),
164 'download_id': fields.one2many('ir.attachment.download',
165 'attachment_id',
166 'Attachment download'),
167 'datas': fields.function(_data_get, fnct_inv=_data_set,
168 string='File Content',
169 type="binary", nodrop=True),
170 }
171
172
173@job
174def create_doc_in_edm(session, model_name, value, res,
175 dict_metadata, user_login, filters=None):
176 ir_attach_obj = session.pool.get('ir.attachment')
177 cmis_backend_obj = session.pool.get('cmis.backend')
178 if session.context is None:
179 session.context = {}
180 # login with the cmis account
181 repo = cmis_backend_obj._auth(session.cr, session.uid,
182 context=session.context)
183 root = repo.rootFolder
184 ids = cmis_backend_obj.search(session.cr, session.uid, [], session.context)
185
186 folder_path = cmis_backend_obj.read(
187 session.cr, session.uid,
188 ids,
189 ['initial_directory_write'],
190 context=session.context)[0]['initial_directory_write']
191 # Document properties
192 if value['name']:
193 file_name = value['name']
194 elif value['datas_fname']:
195 file_name = value['datas_fname']
196 else:
197 file_name = value['datas_fname']
198 props = {
199 'cmis:name': file_name,
200 'cmis:description': value['description'],
201 'cmis:createdBy': user_login,
202 }
203 # Add list of metadata in props
204 if len(dict_metadata):
205 for k, v in dict_metadata.iteritems():
206 props[k] = v
207 if folder_path:
208 sub1 = repo.getObjectByPath(folder_path)
209 else:
210 sub1 = root
211 someDoc = sub1.createDocumentFromString(file_name,
212 contentString=base64.b64decode(
213 value['datas']),
214 contentType=value['file_type'])
215 # TODO: create custom properties on a document (Alfresco)
216 # someDoc.getProperties().update(props)
217 # Updating ir.attachment object with the new id
218 # of document generated by DMS
219 ir_attach_obj.write(session.cr, session.uid, res, {
220 'id_dms': someDoc.getObjectId()}, session.context)
221 return True
222
223# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
0224
=== added file 'cmis_write/metadata.py'
--- cmis_write/metadata.py 1970-01-01 00:00:00 +0000
+++ cmis_write/metadata.py 2014-05-29 22:13:35 +0000
@@ -0,0 +1,67 @@
1# -*- encoding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from openerp.osv import orm, fields
24
25
26class metadata_list(orm.Model):
27 _description = 'List of Metadata'
28 _name = 'metadata.list'
29
30 _columns = {
31 'field_id': fields.many2one('ir.model.fields', 'Fields'),
32 'metadata_id': fields.many2one('metadata', 'Metadata'),
33 }
34
35
36class metadata(orm.Model):
37 _name = "metadata"
38 _description = "Metadata"
39 _columns = {
40 'name': fields.char("Name", size=64, required=True, select=1),
41 'model_id': fields.many2one('ir.model', 'Model',
42 required=True, select=1),
43 'field_ids': fields.many2many('ir.model.fields', 'metadata_field_rel',
44 'meta_id', 'field_id', 'Fields'),
45 'metadata_list_ids': fields.one2many('metadata.list', 'metadata_id',
46 'List of fields'),
47 'model_ids': fields.many2many('ir.model', string='Model List'),
48 }
49
50 def onchange_model(self, cr, uid, ids, model_id, context=None):
51 if context is None:
52 context = {}
53 if not model_id:
54 return {'value': {'model_ids': [(6, 0, [])]}}
55 model_ids = [model_id]
56 model_obj = self.pool.get('ir.model')
57 active_model_obj = self.pool.get(model_obj.browse(
58 cr, uid, model_id, context=context).model)
59 if active_model_obj._inherits:
60 for key, val in active_model_obj._inherits.items():
61 found_model_ids = model_obj.search(cr,
62 uid, [('model', '=', key)],
63 context=context)
64 model_ids += found_model_ids
65 return {'value': {'model_ids': [(6, 0, model_ids)]}}
66
67# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
068
=== added file 'cmis_write/metadata_view.xml'
--- cmis_write/metadata_view.xml 1970-01-01 00:00:00 +0000
+++ cmis_write/metadata_view.xml 2014-05-29 22:13:35 +0000
@@ -0,0 +1,54 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<openerp>
3 <data>
4
5 <record model="ir.ui.view" id="view_mass_object_form">
6 <field name="name">metadata.form</field>
7 <field name="model">metadata</field>
8 <field name="type">form</field>
9 <field name="arch" type="xml">
10 <form string="Object">
11 <field name="name"/>
12 <field name="model_id" on_change="onchange_model(model_id)"/>
13 <field name="model_ids" invisible="1"/>
14 <field name="metadata_list_ids" colspan="4" nolabel="1">
15 <tree string="Metadata list fields Tree" version="7.0" editable="bottom">
16 <field name="field_id"
17 domain="[('ttype', 'not in', ['reference', 'function']),
18 ('model_id', 'in', parent.model_ids[0][2])]"/>
19 </tree>
20 <form string="Metadata list fields form">
21 <field name="field_id"/>
22 </form>
23 </field>
24 </form>
25 </field>
26 </record>
27
28 <record model="ir.ui.view" id="view_metadata_tree">
29 <field name="name">metadata.tree</field>
30 <field name="model">metadata</field>
31 <field name="type">form</field>
32 <field name="arch" type="xml">
33 <tree string="Object">
34 <field name="name"/>
35 <field name="model_id"/>
36 </tree>
37 </field>
38 </record>
39
40 <record id="action_metadata" model="ir.actions.act_window">
41 <field name="name">Metadata Editing</field>
42 <field name="view_id" ref="view_metadata_tree"/>
43 <field name="res_model">metadata</field>
44 <field name="view_mode">tree,form</field>
45 </record>
46
47 <menuitem name="Metadata Editing"
48 id="menu_action_metadata"
49 sequence="10"
50 parent="document.menu_document_management_configuration"
51 action="action_metadata"/>
52
53 </data>
54</openerp>
055
=== added directory 'cmis_write/security'
=== added file 'cmis_write/security/ir.model.access.csv'
--- cmis_write/security/ir.model.access.csv 1970-01-01 00:00:00 +0000
+++ cmis_write/security/ir.model.access.csv 2014-05-29 22:13:35 +0000
@@ -0,0 +1,3 @@
1id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2access_metadata_list_group_user,metadata.list user,model_metadata_list,base.group_document_user,1,1,1,1
3access_metadata,access_metadata,model_metadata,base.group_document_user,1,1,1,1
04
=== added directory 'cmis_write/static'
=== added directory 'cmis_write/static/src'
=== added directory 'cmis_write/static/src/js'
=== added file 'cmis_write/static/src/js/document.js'
--- cmis_write/static/src/js/document.js 1970-01-01 00:00:00 +0000
+++ cmis_write/static/src/js/document.js 2014-05-29 22:13:35 +0000
@@ -0,0 +1,42 @@
1openerp.cmis_write = function(instance, m) {
2var _t = instance.web._t,
3 QWeb = instance.web.qweb;
4
5 instance.web.Sidebar.include({
6 start: function() {
7 var self = this;
8 this._super(this);
9 this.redraw();
10 this.$el.on('click','.oe_dropdown_menu li a', function(event) {
11 var section = $(this).data('section');
12 var index = $(this).data('index');
13 var item = self.items[section][index];
14 if (item.callback) {
15 item.callback.apply(self, [item]);
16 } else if (item.action) {
17 self.on_item_action_clicked(item);
18 } else if (!item.id_dms) {
19 alert(_t("Document is not available in DMS.Please try again !!!"));
20 } else if (item.url) {
21 return true;
22 }
23 event.preventDefault();
24 });
25 },
26 do_attachement_update: function(dataset, model_id, args) {
27 var self = this;
28 this.dataset = dataset;
29 this.model_id = model_id;
30 if (args && args[0].error) {
31 this.do_warn(_t('Uploading Error'), args[0].error);
32 }
33 if (!model_id) {
34 this.on_attachments_loaded([]);
35 } else {
36 var dom = [ ['res_model', '=', dataset.model], ['res_id', '=', model_id], ['type', 'in', ['binary', 'url']] ];
37 var ds = new instance.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom);
38 ds.read_slice(['name', 'url', 'id_dms','type', 'create_uid', 'create_date', 'write_uid', 'write_date'], {}).done(this.on_attachments_loaded);
39 }
40 },
41 });
42};
043
=== added directory 'cmis_write/tests'
=== added file 'cmis_write/tests/__init__.py'
--- cmis_write/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ cmis_write/tests/__init__.py 2014-05-29 22:13:35 +0000
@@ -0,0 +1,29 @@
1# -*- coding: utf-8 -*-
2
3##############################################################################
4#
5# OpenERP, Open Source Management Solution
6# Copyright (C) 2014 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23from . import (
24 test_attachment,
25)
26
27checks = [
28 test_attachment,
29]
030
=== added file 'cmis_write/tests/test_attachment.py'
--- cmis_write/tests/test_attachment.py 1970-01-01 00:00:00 +0000
+++ cmis_write/tests/test_attachment.py 2014-05-29 22:13:35 +0000
@@ -0,0 +1,71 @@
1# -*- encoding: utf-8 -*-
2###############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2010 - 2014 Savoir-faire Linux
6# (<http://www.savoirfairelinux.com>).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21###############################################################################
22
23from openerp.tests.common import TransactionCase
24from openerp.addons.connector.session import ConnectorSession
25
26
27class test_attachment(TransactionCase):
28
29 def setUp(self):
30 super(test_attachment, self).setUp()
31 # Clean up registries
32 self.registry('ir.model').clear_caches()
33 self.registry('ir.model.data').clear_caches()
34 # Get registries
35 self.user_model = self.registry("res.users")
36 self.ir_attachment_model = self.registry("ir.attachment")
37 self.partner_model = self.registry('res.partner')
38 self.metadata_model = self.registry('metadata')
39 # Get context
40 self.context = self.user_model.context_get(self.cr, self.uid)
41
42 partner_id = self.partner_model.create(
43 self.cr, self.uid,
44 {'name': 'Test Partner',
45 'email': 'test@localhost',
46 'is_company': True,
47 }, context=None)
48
49 blob1 = 'blob1'
50 blob1_b64 = blob1.encode('base64')
51
52 self.vals = {
53 'name': 'a1',
54 'datas': blob1_b64,
55 'attachment_document_ids': [(0, 0, {
56 'res_model': "res.partner",
57 'res_id': partner_id,
58 'res_name': 'Test Partner',
59 })],
60 }
61
62 def test_create_test_attachment(self):
63 cr, uid, vals, context = self.cr, self.uid, self.vals, self.context
64 vals['datas'] = None
65 context['bool_testdoc'] = True
66 ir_attachment_id = self.ir_attachment_model.create(
67 cr, uid, vals, context=context)
68 ir_attachment_pool = self.ir_attachment_model.browse(
69 cr, uid, ir_attachment_id, context=context)
70
71 self.assertEqual(ir_attachment_pool.name, vals['name'])

Subscribers

People subscribed via source and target branches

to status/vote changes: