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 ##############################################################################
23 from osv import osv, fields
24 from osv.orm import except_orm
32 class document_directory_content_type(osv.osv):
33 _name = 'document.directory.content.type'
34 _description = 'Directory Content Type'
36 'name': fields.char('Content Type', size=64, required=True),
37 'code': fields.char('Extension', size=4),
38 'active': fields.boolean('Active'),
39 'mimetype': fields.char('Mime Type',size=32)
42 'active': lambda *args: 1
44 document_directory_content_type()
46 class document_directory_content(osv.osv):
47 _name = 'document.directory.content'
48 _description = 'Directory Content'
50 def _extension_get(self, cr, uid, context={}):
51 cr.execute('select code,name from document_directory_content_type where active')
55 'name': fields.char('Content Name', size=64, required=True),
56 'sequence': fields.integer('Sequence', size=16),
57 'prefix': fields.char('Prefix', size=16),
58 'suffix': fields.char('Suffix', size=16),
59 'report_id': fields.many2one('ir.actions.report.xml', 'Report'),
60 'extension': fields.selection(_extension_get, 'Document Type', required=True, size=4),
61 'include_name': fields.boolean('Include Record Name', help="Check this field if you want that the name of the file start by the record name."),
62 'directory_id': fields.many2one('document.directory', 'Directory'),
65 'extension': lambda *args: '.pdf',
66 'sequence': lambda *args: 1,
67 'include_name': lambda *args: 1,
70 def _file_get(self, cr, node, nodename, content, context=None):
71 """ return the nodes of a <node> parent having a <content> content
72 The return value MUST be false or a list of node_class objects.
75 # TODO: respect the context!
76 model = node.res_model
77 if content.include_name and not model:
82 if content.include_name:
83 content_name = node.displayname or ''
84 obj = node.context._dirobj.pool.get(model)
86 tname = (content.prefix or '') + content_name + (content.suffix or '') + (content.extension or '')
88 tname = (content.prefix or '') + (content.suffix or '') + (content.extension or '')
90 tname=tname.replace('/', '_')
92 n = nodes.node_content(tname, node, node.context,content)
96 n = nodes.node_content(tname, node, node.context,content)
101 def process_write(self, cr, uid, node, data, context=None):
102 if node.extension != '.pdf':
103 raise Exception("Invalid content: %s" % node.extension)
106 def process_read(self, cr, uid, node, context=None):
107 if node.extension != '.pdf':
108 raise Exception("Invalid content: %s" % node.extension)
109 report = self.pool.get('ir.actions.report.xml').browse(cr, uid, node.report_id)
110 srv = netsvc.Service._services['report.'+report.report_name]
111 pdf,pdftype = srv.create(cr, uid, [node.context.context['res_id']], {}, {})
113 document_directory_content()