1
##############################################################################
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
29
from report.interface import report_int
33
from report import render
35
from xml.dom import minidom
41
class report_printscreen_list(report_int):
42
def __init__(self, name):
43
report_int.__init__(self, name)
45
def _parse_node(self, root_node):
47
for node in root_node.childNodes:
48
if node.localName == 'field':
49
attrsa = node.attributes
51
if not attrsa is None:
52
for i in range(attrsa.length):
53
attrs[attrsa.item(i).localName] = attrsa.item(i).nodeValue
54
result.append(attrs['name'])
56
result.extend(self._parse_node(node))
59
def _parse_string(self, view):
60
dom = minidom.parseString(view)
61
return self._parse_node(dom)
63
def create(self, cr, uid, ids, datas, context={}):
65
model = pooler.get_pool(cr.dbname).get(datas['model'])
66
result = model.fields_view_get(cr, uid, view_type='tree', context=context)
68
fields_order = self._parse_string(result['arch'])
69
rows = model.read(cr, uid, datas['ids'], result['fields'].keys() )
70
res = self._create_table(uid, datas['ids'], result['fields'], fields_order, rows, context, model._description)
71
return (self.obj.get(), 'pdf')
74
def _create_table(self, uid, ids, fields, fields_order, results, context, title=''):
75
pageSize=[297.0,210.0]
77
impl = minidom.getDOMImplementation()
78
new_doc = impl.createDocument(None, "report", None)
81
config = new_doc.createElement("config")
83
def _append_node(name, text):
84
n = new_doc.createElement(name)
85
t = new_doc.createTextNode(text)
89
_append_node('date', time.strftime('%d/%m/%Y'))
90
_append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize))
91
_append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346,))
92
_append_node('PageHeight', '%.2f' %(pageSize[1] * 2.8346,))
94
_append_node('report-header', title)
98
strmax = (pageSize[0]-40) * 2.8346
99
for f in fields_order:
101
if fields[f]['type'] in ('date','time','float','integer'):
105
t += fields[f].get('size', 56) / 28 + 1
107
for pos in range(len(l)):
109
s = fields[fields_order[pos]].get('size', 56) / 28 + 1
110
l[pos] = strmax * s / t
111
_append_node('tableSize', ','.join(map(str,l)) )
112
new_doc.childNodes[0].appendChild(config)
113
header = new_doc.createElement("header")
115
for f in fields_order:
116
field = new_doc.createElement("field")
117
field_txt = new_doc.createTextNode('%s' % (fields[f]['string'],))
118
field.appendChild(field_txt)
119
header.appendChild(field)
121
new_doc.childNodes[0].appendChild(header)
123
lines = new_doc.createElement("lines")
125
node_line = new_doc.createElement("row")
126
for f in fields_order:
127
if fields[f]['type']=='many2one' and line[f]:
129
if fields[f]['type'] in ('one2many','many2many') and line[f]:
130
line[f] = '( '+str(len(line[f])) + ' )'
131
col = new_doc.createElement("col")
132
col.setAttribute('tree','no')
134
txt = new_doc.createTextNode(str(line[f] or ''))
136
txt = new_doc.createTextNode('/')
138
node_line.appendChild(col)
139
lines.appendChild(node_line)
140
new_doc.childNodes[0].appendChild(lines)
142
file('/tmp/terp.xml','w+').write(new_doc.toxml())
144
styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl'))
145
style = libxslt.parseStylesheetDoc(styledoc)
146
doc = libxml2.parseDoc(new_doc.toxml())
147
rml_obj = style.applyStylesheet(doc, None)
148
rml = style.saveResultToString(rml_obj)
150
self.obj = render.rml(rml)
153
report_printscreen_list('report.printscreen.form')