2009-12-02 05:36:57 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2009-12-02 05:36:57 +00:00
|
|
|
#
|
|
|
|
# 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 osv import osv, fields
|
|
|
|
|
2009-12-08 13:30:41 +00:00
|
|
|
import netsvc
|
2010-08-10 12:29:57 +00:00
|
|
|
# import os
|
2009-12-02 05:36:57 +00:00
|
|
|
import nodes
|
2010-08-10 12:29:57 +00:00
|
|
|
# import StringIO
|
2009-12-02 05:36:57 +00:00
|
|
|
|
|
|
|
class document_directory_content_type(osv.osv):
|
|
|
|
_name = 'document.directory.content.type'
|
|
|
|
_description = 'Directory Content Type'
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Content Type', size=64, required=True),
|
|
|
|
'code': fields.char('Extension', size=4),
|
|
|
|
'active': fields.boolean('Active'),
|
|
|
|
'mimetype': fields.char('Mime Type',size=32)
|
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'active': lambda *args: 1
|
|
|
|
}
|
|
|
|
document_directory_content_type()
|
|
|
|
|
|
|
|
class document_directory_content(osv.osv):
|
|
|
|
_name = 'document.directory.content'
|
|
|
|
_description = 'Directory Content'
|
|
|
|
_order = "sequence"
|
2010-11-19 13:48:01 +00:00
|
|
|
def _extension_get(self, cr, uid, context=None):
|
2009-12-02 05:36:57 +00:00
|
|
|
cr.execute('select code,name from document_directory_content_type where active')
|
|
|
|
res = cr.fetchall()
|
|
|
|
return res
|
|
|
|
_columns = {
|
|
|
|
'name': fields.char('Content Name', size=64, required=True),
|
|
|
|
'sequence': fields.integer('Sequence', size=16),
|
|
|
|
'prefix': fields.char('Prefix', size=16),
|
|
|
|
'suffix': fields.char('Suffix', size=16),
|
|
|
|
'report_id': fields.many2one('ir.actions.report.xml', 'Report'),
|
|
|
|
'extension': fields.selection(_extension_get, 'Document Type', required=True, size=4),
|
2010-07-13 10:30:24 +00:00
|
|
|
'include_name': fields.boolean('Include Record Name',
|
|
|
|
help="Check this field if you want that the name of the file to contain the record name." \
|
|
|
|
"\nIf set, the directory will have to be a resource one."),
|
2009-12-02 05:36:57 +00:00
|
|
|
'directory_id': fields.many2one('document.directory', 'Directory'),
|
|
|
|
}
|
|
|
|
_defaults = {
|
|
|
|
'extension': lambda *args: '.pdf',
|
|
|
|
'sequence': lambda *args: 1,
|
|
|
|
'include_name': lambda *args: 1,
|
|
|
|
}
|
|
|
|
|
2009-12-15 14:02:50 +00:00
|
|
|
def _file_get(self, cr, node, nodename, content, context=None):
|
2009-12-07 13:11:11 +00:00
|
|
|
""" return the nodes of a <node> parent having a <content> content
|
|
|
|
The return value MUST be false or a list of node_class objects.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# TODO: respect the context!
|
2009-12-08 13:30:41 +00:00
|
|
|
model = node.res_model
|
|
|
|
if content.include_name and not model:
|
2009-12-07 13:11:11 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
res2 = []
|
|
|
|
tname = ''
|
|
|
|
if content.include_name:
|
2009-12-08 13:30:41 +00:00
|
|
|
content_name = node.displayname or ''
|
2010-08-10 12:29:57 +00:00
|
|
|
# obj = node.context._dirobj.pool.get(model)
|
2009-12-08 13:30:41 +00:00
|
|
|
if content_name:
|
2009-12-07 13:11:11 +00:00
|
|
|
tname = (content.prefix or '') + content_name + (content.suffix or '') + (content.extension or '')
|
|
|
|
else:
|
|
|
|
tname = (content.prefix or '') + (content.suffix or '') + (content.extension or '')
|
|
|
|
if tname.find('/'):
|
|
|
|
tname=tname.replace('/', '_')
|
2010-07-13 10:30:30 +00:00
|
|
|
act_id = False
|
|
|
|
if 'dctx_res_id' in node.dctx:
|
|
|
|
act_id = node.dctx['dctx_res_id']
|
|
|
|
elif hasattr(node, 'res_id'):
|
|
|
|
act_id = node.res_id
|
|
|
|
else:
|
|
|
|
act_id = node.context.context.get('res_id',False)
|
2009-12-07 13:11:11 +00:00
|
|
|
if not nodename:
|
2010-07-13 10:30:30 +00:00
|
|
|
n = nodes.node_content(tname, node, node.context,content, act_id=act_id)
|
2009-12-07 13:11:11 +00:00
|
|
|
res2.append( n)
|
|
|
|
else:
|
|
|
|
if nodename == tname:
|
2010-07-13 10:30:30 +00:00
|
|
|
n = nodes.node_content(tname, node, node.context,content, act_id=act_id)
|
2009-12-07 13:11:11 +00:00
|
|
|
n.fill_fields(cr)
|
|
|
|
res2.append(n)
|
|
|
|
return res2
|
2009-12-02 05:36:57 +00:00
|
|
|
|
2009-12-17 13:22:31 +00:00
|
|
|
def process_write(self, cr, uid, node, data, context=None):
|
2009-12-07 13:11:11 +00:00
|
|
|
if node.extension != '.pdf':
|
|
|
|
raise Exception("Invalid content: %s" % node.extension)
|
2009-12-02 05:36:57 +00:00
|
|
|
return True
|
2009-12-08 13:30:41 +00:00
|
|
|
|
2009-12-17 13:22:31 +00:00
|
|
|
def process_read(self, cr, uid, node, context=None):
|
2009-12-07 13:11:11 +00:00
|
|
|
if node.extension != '.pdf':
|
|
|
|
raise Exception("Invalid content: %s" % node.extension)
|
2010-11-19 13:48:01 +00:00
|
|
|
report = self.pool.get('ir.actions.report.xml').browse(cr, uid, node.report_id, context=context)
|
2009-12-08 13:30:41 +00:00
|
|
|
srv = netsvc.Service._services['report.'+report.report_name]
|
2010-07-13 10:30:30 +00:00
|
|
|
ctx = node.context.context.copy()
|
|
|
|
ctx.update(node.dctx)
|
|
|
|
pdf,pdftype = srv.create(cr, uid, [node.act_id,], {}, context=ctx)
|
2009-12-17 13:22:31 +00:00
|
|
|
return pdf
|
2009-12-02 05:36:57 +00:00
|
|
|
document_directory_content()
|
2010-07-13 10:30:53 +00:00
|
|
|
|
2011-11-22 08:51:38 +00:00
|
|
|
#eof
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|