mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-25 01:48:41 -06:00
[ADD] add cmis_write: It allows to create docs from OE in DMS
This commit is contained in:
parent
9be2cbb603
commit
0eef461532
26
cmis_write/__init__.py
Normal file
26
cmis_write/__init__.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# This module copyright (C) 2014 Savoir-faire Linux
|
||||||
|
# (<http://www.savoirfairelinux.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
from . import ir_attachment
|
||||||
|
from . import metadata
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
71
cmis_write/__openerp__.py
Normal file
71
cmis_write/__openerp__.py
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# This module copyright (C) 2014 Savoir-faire Linux
|
||||||
|
# (<http://www.savoirfairelinux.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'CMIS Write',
|
||||||
|
'version': '0.1',
|
||||||
|
'category': 'Knowledge Management',
|
||||||
|
'summary': 'Create Document in DMS from OpenErp',
|
||||||
|
'description': """
|
||||||
|
Add Documents from OpenErp
|
||||||
|
==========================
|
||||||
|
|
||||||
|
This module allows you to store OpenERP document in the DMS repository.
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
=============
|
||||||
|
|
||||||
|
* Create a new CMIS backend with the host, login and password.
|
||||||
|
* Configure the path in the repository where documents will be dropped.
|
||||||
|
By default, it uses the home directory of the user.
|
||||||
|
|
||||||
|
Usage
|
||||||
|
=====
|
||||||
|
|
||||||
|
* On one OpenERP record, click "Add document".
|
||||||
|
* Upload your documents
|
||||||
|
* Uploaded documents will be enqueued for storage in the DMS
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
------------
|
||||||
|
* El Hadji Dem (elhadji.dem@savoirfairelinux.com)
|
||||||
|
""",
|
||||||
|
'author': 'Savoir-faire Linux',
|
||||||
|
'website': 'www.savoirfairelinux.com',
|
||||||
|
'license': 'AGPL-3',
|
||||||
|
'depends': [
|
||||||
|
'document',
|
||||||
|
'cmis',
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
'metadata_view.xml',
|
||||||
|
'security/ir.model.access.csv',
|
||||||
|
],
|
||||||
|
'js': [],
|
||||||
|
'qweb': [],
|
||||||
|
'test': [],
|
||||||
|
'demo': [],
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
89
cmis_write/i18n/cmis_write.pot
Normal file
89
cmis_write/i18n/cmis_write.pot
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
# Translation of OpenERP Server.
|
||||||
|
# This file contains the translation of the following modules:
|
||||||
|
# * cmis_write
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: OpenERP Server 7.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2014-03-21 14:59+0000\n"
|
||||||
|
"PO-Revision-Date: 2014-03-21 10:59-0500\n"
|
||||||
|
"Last-Translator: EL Hadji DEM <elhadji.dem@savoirfairelinux.com>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: \n"
|
||||||
|
"X-Generator: Poedit 1.5.4\n"
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: model:_description:0 model:ir.model,name:cmis_write.model_metadata_list
|
||||||
|
msgid "List of Metadata"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: field:metadata,name:0
|
||||||
|
msgid "Name"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: model:ir.actions.act_window,name:cmis_write.action_metadata
|
||||||
|
#: model:ir.ui.menu,name:cmis_write.menu_action_metadata
|
||||||
|
msgid "Metadata Editing"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: field:metadata,metadata_list_ids:0
|
||||||
|
msgid "List of fields"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: field:metadata,field_ids:0 field:metadata.list,field_id:0
|
||||||
|
msgid "Fields"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: view:metadata:0
|
||||||
|
msgid "Object"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: view:metadata:0
|
||||||
|
msgid "Metadata list fields form"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: help:ir.attachment,id_edm:0
|
||||||
|
msgid "Id of Edm."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: field:ir.attachment,id_edm:0
|
||||||
|
msgid "Id of Dms"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: view:metadata:0
|
||||||
|
msgid "Metadata list fields Tree"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: field:metadata,model_id:0
|
||||||
|
msgid "Model"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: field:metadata,model_ids:0
|
||||||
|
msgid "Model List"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: model:_description:0 model:ir.model,name:cmis_write.model_ir_attachment
|
||||||
|
msgid "ir.attachment"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#. module: cmis_write
|
||||||
|
#: model:_description:0 model:ir.model,name:cmis_write.model_metadata
|
||||||
|
#: field:metadata.list,metadata_id:0
|
||||||
|
msgid "Metadata"
|
||||||
|
msgstr ""
|
106
cmis_write/ir_attachment.py
Normal file
106
cmis_write/ir_attachment.py
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# This module copyright (C) 2014 Savoir-faire Linux
|
||||||
|
# (<http://www.savoirfairelinux.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
from openerp.osv import orm, fields
|
||||||
|
from openerp.addons.connector.session import ConnectorSession
|
||||||
|
from openerp.addons.connector.queue.job import job
|
||||||
|
import base64
|
||||||
|
import logging
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ir_attachment(orm.Model):
|
||||||
|
_inherit = 'ir.attachment'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'id_edm': fields.char('Id of Dms', size=256, help="Id of Edm."),
|
||||||
|
}
|
||||||
|
|
||||||
|
def create(self, cr, uid, values, context=None):
|
||||||
|
metadata_obj = self.pool.get('metadata')
|
||||||
|
user_obj = self.pool.get('res.users')
|
||||||
|
user_login = user_obj.browse(cr, uid, uid, context=context).login
|
||||||
|
session = ConnectorSession(cr, uid, context=context)
|
||||||
|
value = {
|
||||||
|
'datas_fname': values.get('datas_fname'),
|
||||||
|
'file_type': values.get('file_type') or '',
|
||||||
|
'datas': values.get('datas'),
|
||||||
|
'description': values.get('description') or '',
|
||||||
|
|
||||||
|
}
|
||||||
|
metadata_ids = metadata_obj.search(cr, uid, [], context=context)
|
||||||
|
dict_metadata = {}
|
||||||
|
list_fields = []
|
||||||
|
# Get list of metadata
|
||||||
|
if values.get('res_model'):
|
||||||
|
for line in metadata_obj.browse(cr, uid, metadata_ids, context=context):
|
||||||
|
if line.model_id.model == values.get('res_model'):
|
||||||
|
if line.metadata_list_ids:
|
||||||
|
for one_field in line.metadata_list_ids:
|
||||||
|
list_fields.append(one_field.field_id.name)
|
||||||
|
result = self.pool.get(values.get('res_model')).read(cr, uid, [values.get('res_id')],
|
||||||
|
list_fields, context=context)[0]
|
||||||
|
|
||||||
|
for one_field in list_fields:
|
||||||
|
dict_metadata['cmis:' + one_field] = result[one_field]
|
||||||
|
res = super(ir_attachment, self).create(cr, uid, values, context=context)
|
||||||
|
# Create Job
|
||||||
|
create_doc_in_edm.delay(session, 'ir.attachment', value, res, dict_metadata, user_login)
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
@job
|
||||||
|
def create_doc_in_edm(session, model_name, value, res, dict_metadata, user_login, filters=None):
|
||||||
|
ir_attach_obj = session.pool.get('ir.attachment')
|
||||||
|
cmis_backend_obj = session.pool.get('cmis.backend')
|
||||||
|
if session.context is None:
|
||||||
|
session.context = {}
|
||||||
|
#login with the cmis account
|
||||||
|
client = cmis_backend_obj._auth(session.cr, session.uid, context=session.context)
|
||||||
|
repo = client.defaultRepository
|
||||||
|
root = repo.rootFolder
|
||||||
|
ids = cmis_backend_obj.search(session.cr, session.uid, [])
|
||||||
|
folder_path = cmis_backend_obj.read(session.cr, session.uid,
|
||||||
|
ids, ['initial_directory_write'],
|
||||||
|
context=session.context)[0]['initial_directory_write']
|
||||||
|
# Document properties
|
||||||
|
props = {
|
||||||
|
'cmis:name': value['datas_fname'],
|
||||||
|
'cmis:description': value['description'],
|
||||||
|
'cmis:createdBy': user_login,
|
||||||
|
}
|
||||||
|
# Add list of metadata in props
|
||||||
|
if len(dict_metadata):
|
||||||
|
for k, v in dict_metadata.iteritems():
|
||||||
|
props[k] = v
|
||||||
|
if folder_path:
|
||||||
|
sub1 = repo.getObjectByPath(folder_path)
|
||||||
|
else:
|
||||||
|
sub1 = root
|
||||||
|
someDoc = sub1.createDocumentFromString(value['datas_fname'], props,
|
||||||
|
contentString=base64.b64decode(value['datas']),
|
||||||
|
contentType=value['file_type'])
|
||||||
|
# Updating ir.attachment object with the new id of document generated by DMS
|
||||||
|
ir_attach_obj.write(session.cr, session.uid, res, {'id_edm': someDoc.getObjectId()}, session.context)
|
||||||
|
return True
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
62
cmis_write/metadata.py
Normal file
62
cmis_write/metadata.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# This module copyright (C) 2014 Savoir-faire Linux
|
||||||
|
# (<http://www.savoirfairelinux.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
from openerp.osv import orm, fields, osv
|
||||||
|
|
||||||
|
|
||||||
|
class metadata_list(orm.Model):
|
||||||
|
_description = 'List of Metadata'
|
||||||
|
_name = 'metadata.list'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'field_id': fields.many2one('ir.model.fields', 'Fields'),
|
||||||
|
'metadata_id': fields.many2one('metadata', 'Metadata'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class metadata(orm.Model):
|
||||||
|
_name = "metadata"
|
||||||
|
_description = "Metadata"
|
||||||
|
_columns = {
|
||||||
|
'name': fields.char("Name", size=64, required=True, select=1),
|
||||||
|
'model_id': fields.many2one('ir.model', 'Model', required=True, select=1),
|
||||||
|
'field_ids': fields.many2many('ir.model.fields', 'metadata_field_rel',
|
||||||
|
'meta_id', 'field_id', 'Fields'),
|
||||||
|
'metadata_list_ids': fields.one2many('metadata.list', 'metadata_id', 'List of fields'),
|
||||||
|
'model_ids': fields.many2many('ir.model', string='Model List'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def onchange_model(self, cr, uid, ids, model_id, context=None):
|
||||||
|
if context is None:
|
||||||
|
context = {}
|
||||||
|
if not model_id:
|
||||||
|
return {'value': {'model_ids': [(6, 0, [])]}}
|
||||||
|
model_ids = [model_id]
|
||||||
|
model_obj = self.pool.get('ir.model')
|
||||||
|
active_model_obj = self.pool.get(model_obj.browse(cr, uid, model_id).model)
|
||||||
|
if active_model_obj._inherits:
|
||||||
|
for key, val in active_model_obj._inherits.items():
|
||||||
|
found_model_ids = model_obj.search(cr, uid, [('model', '=', key)], context=context)
|
||||||
|
model_ids += found_model_ids
|
||||||
|
return {'value': {'model_ids': [(6, 0, model_ids)]}}
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:toabstop=4:softtabstop=4:shiftwidth=4:
|
54
cmis_write/metadata_view.xml
Normal file
54
cmis_write/metadata_view.xml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="view_mass_object_form">
|
||||||
|
<field name="name">metadata.form</field>
|
||||||
|
<field name="model">metadata</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<form string="Object">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="model_id" on_change="onchange_model(model_id)"/>
|
||||||
|
<field name="model_ids" invisible="1"/>
|
||||||
|
<field name="metadata_list_ids" colspan="4" nolabel="1">
|
||||||
|
<tree string="Metadata list fields Tree" version="7.0" editable="bottom">
|
||||||
|
<field name="field_id"
|
||||||
|
domain="[('ttype', 'not in', ['reference', 'function']),
|
||||||
|
('model_id', 'in', parent.model_ids[0][2])]"/>
|
||||||
|
</tree>
|
||||||
|
<form string="Metadata list fields form">
|
||||||
|
<field name="field_id"/>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="view_metadata_tree">
|
||||||
|
<field name="name">metadata.tree</field>
|
||||||
|
<field name="model">metadata</field>
|
||||||
|
<field name="type">form</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree string="Object">
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="model_id"/>
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="action_metadata" model="ir.actions.act_window">
|
||||||
|
<field name="name">Metadata Editing</field>
|
||||||
|
<field name="view_id" ref="view_metadata_tree"/>
|
||||||
|
<field name="res_model">metadata</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<menuitem name="Metadata Editing"
|
||||||
|
id="menu_action_metadata"
|
||||||
|
sequence="10"
|
||||||
|
parent="document.menu_document_management_configuration"
|
||||||
|
action="action_metadata"/>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
2
cmis_write/security/ir.model.access.csv
Normal file
2
cmis_write/security/ir.model.access.csv
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
access_metadata_list_group_user,metadata.list user,model_metadata_list,base.group_document_user,1,1,1,1
|
|
Loading…
Reference in New Issue
Block a user