[IMP] Change the view where we search document from DMS and print the results below the search field

This commit is contained in:
EL HADJI DEM 2014-05-27 15:26:52 -04:00 committed by Sandy Carter
parent 5f34a50299
commit 997ab32e2d
2 changed files with 77 additions and 52 deletions

View File

@ -24,35 +24,18 @@ from openerp.osv import orm, fields
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.addons.connector.session import ConnectorSession from openerp.addons.connector.session import ConnectorSession
from openerp.addons.connector.queue.job import job from openerp.addons.connector.queue.job import job
from openerp import SUPERUSER_ID
import logging import logging
_logger = logging.getLogger(__name__) _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): class ir_attachment_edm_wizard(orm.Model):
_name = 'ir.attachment.dms.wizard' _name = 'ir.attachment.dms.wizard'
_columns = { _columns = {
'name': fields.char('File name', size=150, help="File name"), 'name': fields.char('File name', size=150, help="File name"),
'attachment_ids': fields.many2many('ir.attachment.dms', 'attachment_ids': fields.one2many('ir.attachment.dms',
'document_attachment_dms_rel', 'wizard_id'),
'wizard_id', 'attachment_id',
'Attachments'),
} }
# Search documents from dms. # Search documents from dms.
@ -71,7 +54,7 @@ class ir_attachment_edm_wizard(orm.Model):
file_name = data['name'] file_name = data['name']
for backend_id in ids: for backend_id in ids:
search_doc_from_dms(session, 'ir.attachment', search_doc_from_dms(session, 'ir.attachment',
backend_id, file_name) backend_id, file_name, this.id)
return { return {
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'res_model': 'ir.attachment.dms.wizard', '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. # Adding documents from Document Management (EDM) to OE.
def action_apply(self, cr, uid, ids, context=None): def action_apply(self, cr, uid, ids, context=None):
ir_attachment_dms_obj = self.pool.get('ir.attachment.dms')
if context is None: if context is None:
context = {} context = {}
model = context['model'] model = context['model']
@ -92,13 +76,20 @@ class ir_attachment_edm_wizard(orm.Model):
name = ir_model_obj.browse(cr, uid, context['ids'], name = ir_model_obj.browse(cr, uid, context['ids'],
context=context)[0]['name'] context=context)[0]['name']
data = self.read(cr, uid, ids, [], context=context)[0] 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']: if not data['attachment_ids']:
raise orm.except_orm(_('Error'), raise orm.except_orm(_('Error'),
_('You have to select at least 1 Document.' + _('You have to select at least 1 Document.' +
'And try again')) 'And try again'))
if not hasattr(ids, '__iter__'):
ids = [ids]
session = ConnectorSession(cr, uid, context=context)
for backend_id in ids: for backend_id in ids:
# Create doc in OE from DMS. # Create doc in OE from DMS.
create_doc_from_dms.delay(session, 'ir.attachment', backend_id, 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'} 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): def sanitize_input_filename_field(file_name):
# Escape the name for characters not supported in filenames # Escape the name for characters not supported in filenames
# for avoiding SQL Injection # for avoiding SQL Injection
@ -115,7 +126,7 @@ def sanitize_input_filename_field(file_name):
return 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') ir_attach_dms_obj = session.pool.get('ir.attachment.dms')
cmis_backend_obj = session.pool.get('cmis.backend') cmis_backend_obj = session.pool.get('cmis.backend')
if session.context is None: 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'], 'name': info['cmis:name'],
'owner': info['cmis:createdBy'], 'owner': info['cmis:createdBy'],
'file_id': info['cmis:objectId'], 'file_id': info['cmis:objectId'],
'wizard_id': wizard_id,
} }
ir_attach_dms_obj.create(session.cr, session.uid, data_attach, ir_attach_dms_obj.create(session.cr, session.uid, data_attach,
context=session.context) context=session.context)
@ -175,7 +187,7 @@ def create_doc_from_dms(session, model_name, backend_id, data, name,
'res_id': res_id, 'res_id': res_id,
'user_id': uid, 'user_id': uid,
} }
session.context['bool_read_doc'] = True session.context['bool_testdoc'] = True
ir_attach_obj.create(session.cr, session.uid, ir_attach_obj.create(session.cr, session.uid,
data_attach, context=session.context) data_attach, context=session.context)
return True return True

View File

@ -2,32 +2,45 @@
<openerp> <openerp>
<data> <data>
<record id="document_from_dms_form_view" model="ir.ui.view"> <!-- wizard view -->
<field name="name">Search Document</field> <record id="wizard_view" model="ir.ui.view">
<field name="model">ir.attachment.dms.wizard</field> <field name="name">Search Document</field>
<field name="arch" type="xml"> <field name="model">ir.attachment.dms.wizard</field>
<form string="Search Document" version="7.0"> <field name="arch" type="xml">
<label string="This action allows you to search by file name and to add the document you select"/> <form string="Search Document" version="7.0">
<group string="Search Document"> <div>
<div width="100%%"> This action allows you to search by file name and to add the document you select
<field name="name" </div>
width="70%%" <group>
class="oe_inline"/> <div width="100%%">
<button name="search_doc" <field name="name" width="70%%" class="oe_inline"/>
string="Search" <button name="search_doc" string="Search" type="object"
type="object" width="15%%" class="oe_inline oe_highlight" />
width="15%%" </div>
class="oe_inline oe_highlight" /> </group>
</div> <field name="attachment_ids"/>
<field name="attachment_ids" colspan="4" nolabel="1"/> <footer>
</group> <button name="action_apply" string="Apply" type="object"
<footer> class="oe_highlight"/>
<button name="action_apply" string="Apply" type="object" class="oe_highlight"/> or
or <button special="cancel" string="Cancel" type="object"
<button special="cancel" string="Cancel" type="object" class="oe_link"/> class="oe_link"/>
</footer> </footer>
</form> </form>
</field> </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> </record>
</data> </data>