mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 20:12:04 -06:00
[IMP] Change the view where we search document from DMS and print the results below the search field
This commit is contained in:
parent
5f34a50299
commit
997ab32e2d
@ -24,35 +24,18 @@ from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.connector.session import ConnectorSession
|
||||
from openerp.addons.connector.queue.job import job
|
||||
from openerp import SUPERUSER_ID
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ir_attachment_dms(orm.TransientModel):
|
||||
_name = 'ir.attachment.dms'
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('File name', size=150,
|
||||
readonly=True,
|
||||
help="File name"),
|
||||
'owner': fields.char('Owner', size=150,
|
||||
readonly=True,
|
||||
help="Owner"),
|
||||
'file_id': fields.char('File ID', size=150,
|
||||
readonly=True,
|
||||
help="File Id"),
|
||||
}
|
||||
|
||||
|
||||
class ir_attachment_edm_wizard(orm.Model):
|
||||
_name = 'ir.attachment.dms.wizard'
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('File name', size=150, help="File name"),
|
||||
'attachment_ids': fields.many2many('ir.attachment.dms',
|
||||
'document_attachment_dms_rel',
|
||||
'wizard_id', 'attachment_id',
|
||||
'Attachments'),
|
||||
'attachment_ids': fields.one2many('ir.attachment.dms',
|
||||
'wizard_id'),
|
||||
}
|
||||
|
||||
# Search documents from dms.
|
||||
@ -71,7 +54,7 @@ class ir_attachment_edm_wizard(orm.Model):
|
||||
file_name = data['name']
|
||||
for backend_id in ids:
|
||||
search_doc_from_dms(session, 'ir.attachment',
|
||||
backend_id, file_name)
|
||||
backend_id, file_name, this.id)
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'ir.attachment.dms.wizard',
|
||||
@ -84,6 +67,7 @@ class ir_attachment_edm_wizard(orm.Model):
|
||||
|
||||
# Adding documents from Document Management (EDM) to OE.
|
||||
def action_apply(self, cr, uid, ids, context=None):
|
||||
ir_attachment_dms_obj = self.pool.get('ir.attachment.dms')
|
||||
if context is None:
|
||||
context = {}
|
||||
model = context['model']
|
||||
@ -92,13 +76,20 @@ class ir_attachment_edm_wizard(orm.Model):
|
||||
name = ir_model_obj.browse(cr, uid, context['ids'],
|
||||
context=context)[0]['name']
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
|
||||
if not hasattr(ids, '__iter__'):
|
||||
ids = [ids]
|
||||
session = ConnectorSession(cr, uid, context=context)
|
||||
# Just take the lines we select in the tree view
|
||||
selected_data = [one_attachment.id for one_attachment in
|
||||
ir_attachment_dms_obj.browse(
|
||||
cr, uid, data['attachment_ids'], context)
|
||||
if one_attachment.selectable_ok]
|
||||
data['attachment_ids'] = selected_data
|
||||
if not data['attachment_ids']:
|
||||
raise orm.except_orm(_('Error'),
|
||||
_('You have to select at least 1 Document.' +
|
||||
'And try again'))
|
||||
if not hasattr(ids, '__iter__'):
|
||||
ids = [ids]
|
||||
session = ConnectorSession(cr, uid, context=context)
|
||||
for backend_id in ids:
|
||||
# Create doc in OE from DMS.
|
||||
create_doc_from_dms.delay(session, 'ir.attachment', backend_id,
|
||||
@ -106,6 +97,26 @@ class ir_attachment_edm_wizard(orm.Model):
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
|
||||
class ir_attachment_dms(orm.TransientModel):
|
||||
_name = 'ir.attachment.dms'
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('File name', size=150,
|
||||
readonly=True,
|
||||
help="File name"),
|
||||
'owner': fields.char('Owner', size=150,
|
||||
readonly=True,
|
||||
help="Owner"),
|
||||
'file_id': fields.char('File ID', size=150,
|
||||
readonly=True,
|
||||
help="File Id"),
|
||||
'wizard_id': fields.many2one('ir.attachment.dms.wizard',
|
||||
string='Wizard',
|
||||
required=True),
|
||||
'selectable_ok': fields.boolean('Selected', help="Selected."),
|
||||
}
|
||||
|
||||
|
||||
def sanitize_input_filename_field(file_name):
|
||||
# Escape the name for characters not supported in filenames
|
||||
# for avoiding SQL Injection
|
||||
@ -115,7 +126,7 @@ def sanitize_input_filename_field(file_name):
|
||||
return file_name
|
||||
|
||||
|
||||
def search_doc_from_dms(session, model_name, backend_id, file_name):
|
||||
def search_doc_from_dms(session, model_name, backend_id, file_name, wizard_id):
|
||||
ir_attach_dms_obj = session.pool.get('ir.attachment.dms')
|
||||
cmis_backend_obj = session.pool.get('cmis.backend')
|
||||
if session.context is None:
|
||||
@ -141,6 +152,7 @@ def search_doc_from_dms(session, model_name, backend_id, file_name):
|
||||
'name': info['cmis:name'],
|
||||
'owner': info['cmis:createdBy'],
|
||||
'file_id': info['cmis:objectId'],
|
||||
'wizard_id': wizard_id,
|
||||
}
|
||||
ir_attach_dms_obj.create(session.cr, session.uid, data_attach,
|
||||
context=session.context)
|
||||
@ -175,7 +187,7 @@ def create_doc_from_dms(session, model_name, backend_id, data, name,
|
||||
'res_id': res_id,
|
||||
'user_id': uid,
|
||||
}
|
||||
session.context['bool_read_doc'] = True
|
||||
session.context['bool_testdoc'] = True
|
||||
ir_attach_obj.create(session.cr, session.uid,
|
||||
data_attach, context=session.context)
|
||||
return True
|
||||
|
@ -2,32 +2,45 @@
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="document_from_dms_form_view" model="ir.ui.view">
|
||||
<field name="name">Search Document</field>
|
||||
<field name="model">ir.attachment.dms.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Search Document" version="7.0">
|
||||
<label string="This action allows you to search by file name and to add the document you select"/>
|
||||
<group string="Search Document">
|
||||
<div width="100%%">
|
||||
<field name="name"
|
||||
width="70%%"
|
||||
class="oe_inline"/>
|
||||
<button name="search_doc"
|
||||
string="Search"
|
||||
type="object"
|
||||
width="15%%"
|
||||
class="oe_inline oe_highlight" />
|
||||
</div>
|
||||
<field name="attachment_ids" colspan="4" nolabel="1"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="action_apply" string="Apply" type="object" class="oe_highlight"/>
|
||||
or
|
||||
<button special="cancel" string="Cancel" type="object" class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
<!-- wizard view -->
|
||||
<record id="wizard_view" model="ir.ui.view">
|
||||
<field name="name">Search Document</field>
|
||||
<field name="model">ir.attachment.dms.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Search Document" version="7.0">
|
||||
<div>
|
||||
This action allows you to search by file name and to add the document you select
|
||||
</div>
|
||||
<group>
|
||||
<div width="100%%">
|
||||
<field name="name" width="70%%" class="oe_inline"/>
|
||||
<button name="search_doc" string="Search" type="object"
|
||||
width="15%%" class="oe_inline oe_highlight" />
|
||||
</div>
|
||||
</group>
|
||||
<field name="attachment_ids"/>
|
||||
<footer>
|
||||
<button name="action_apply" string="Apply" type="object"
|
||||
class="oe_highlight"/>
|
||||
or
|
||||
<button special="cancel" string="Cancel" type="object"
|
||||
class="oe_link"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="wizard_attachment_tree_view" model="ir.ui.view">
|
||||
<field name="name">Ir Attachment Dms</field>
|
||||
<field name="model">ir.attachment.dms</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Attachment" editable="bottom" create="false" delete="false">
|
||||
<field name="selectable_ok"/>
|
||||
<field name="name"/>
|
||||
<field name="owner"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user