1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import osv, fields
29 class document_directory_content_type(osv.osv):
30 _name = 'document.directory.content.type'
31 _description = 'Directory Content Type'
33 'name': fields.char('Content Type', size=64, required=True),
34 'code': fields.char('Extension', size=4),
35 'active': fields.boolean('Active'),
36 'mimetype': fields.char('Mime Type',size=32)
39 'active': lambda *args: 1
41 document_directory_content_type()
43 class document_directory_content(osv.osv):
44 _name = 'document.directory.content'
45 _description = 'Directory Content'
47 def _extension_get(self, cr, uid, context=None):
48 cr.execute('select code,name from document_directory_content_type where active')
52 'name': fields.char('Content Name', size=64, required=True),
53 'sequence': fields.integer('Sequence', size=16),
54 'prefix': fields.char('Prefix', size=16),
55 'suffix': fields.char('Suffix', size=16),
56 'report_id': fields.many2one('ir.actions.report.xml', 'Report'),
57 'extension': fields.selection(_extension_get, 'Document Type', required=True, size=4),
58 'include_name': fields.boolean('Include Record Name',
59 help="Check this field if you want that the name of the file to contain the record name." \
60 "\nIf set, the directory will have to be a resource one."),
61 'directory_id': fields.many2one('document.directory', 'Directory'),
64 'extension': lambda *args: '.pdf',
65 'sequence': lambda *args: 1,
66 'include_name': lambda *args: 1,
69 def _file_get(self, cr, node, nodename, content, context=None):
70 """ return the nodes of a <node> parent having a <content> content
71 The return value MUST be false or a list of node_class objects.
74 # TODO: respect the context!
75 model = node.res_model
76 if content.include_name and not model:
81 if content.include_name:
82 content_name = node.displayname or ''
83 # obj = node.context._dirobj.pool.get(model)
85 tname = (content.prefix or '') + content_name + (content.suffix or '') + (content.extension or '')
87 tname = (content.prefix or '') + (content.suffix or '') + (content.extension or '')
89 tname=tname.replace('/', '_')
91 if 'dctx_res_id' in node.dctx:
92 act_id = node.dctx['dctx_res_id']
93 elif hasattr(node, 'res_id'):
96 act_id = node.context.context.get('res_id',False)
98 n = nodes.node_content(tname, node, node.context,content, act_id=act_id)
101 if nodename == tname:
102 n = nodes.node_content(tname, node, node.context,content, act_id=act_id)
107 def process_write(self, cr, uid, node, data, context=None):
108 if node.extension != '.pdf':
109 raise Exception("Invalid content: %s" % node.extension)
112 def process_read(self, cr, uid, node, context=None):
113 if node.extension != '.pdf':
114 raise Exception("Invalid content: %s" % node.extension)
115 report = self.pool.get('ir.actions.report.xml').browse(cr, uid, node.report_id, context=context)
116 srv = netsvc.Service._services['report.'+report.report_name]
117 ctx = node.context.context.copy()
118 ctx.update(node.dctx)
119 pdf,pdftype = srv.create(cr, uid, [node.act_id,], {}, context=ctx)
121 document_directory_content()
124 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: