2009-10-20 10:52:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2010-09-01 11:53:10 +00:00
|
|
|
#
|
2009-04-28 10:24:21 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2009-10-14 12:32:15 +00:00
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 12:32:15 +00:00
|
|
|
# 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.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 18:27:16 +00:00
|
|
|
# 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
|
2009-10-14 12:32:15 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 12:32:15 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2010-09-01 11:53:10 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2013-03-27 11:10:14 +00:00
|
|
|
import openerp
|
2011-02-07 12:57:23 +00:00
|
|
|
from openerp.report.interface import report_int
|
|
|
|
import openerp.tools as tools
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2011-02-07 12:57:23 +00:00
|
|
|
from openerp.report import render
|
2009-04-28 10:24:21 +00:00
|
|
|
from lxml import etree
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
import time, os
|
2008-09-24 15:34:10 +00:00
|
|
|
|
2011-06-23 09:04:57 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
class report_printscreen_list(report_int):
|
2008-07-22 14:24:36 +00:00
|
|
|
def __init__(self, name):
|
|
|
|
report_int.__init__(self, name)
|
|
|
|
|
|
|
|
def _parse_node(self, root_node):
|
|
|
|
result = []
|
2009-06-12 11:05:11 +00:00
|
|
|
for node in root_node:
|
2009-04-28 10:24:21 +00:00
|
|
|
if node.tag == 'field':
|
|
|
|
attrsa = node.attrib
|
2008-07-22 14:24:36 +00:00
|
|
|
attrs = {}
|
|
|
|
if not attrsa is None:
|
2009-06-12 11:05:11 +00:00
|
|
|
for key,val in attrsa.items():
|
2009-04-28 10:24:21 +00:00
|
|
|
attrs[key] = val
|
2008-07-22 14:24:36 +00:00
|
|
|
result.append(attrs['name'])
|
|
|
|
else:
|
|
|
|
result.extend(self._parse_node(node))
|
|
|
|
return result
|
|
|
|
|
|
|
|
def _parse_string(self, view):
|
2009-04-28 10:24:21 +00:00
|
|
|
dom = etree.XML(view)
|
2008-07-22 14:24:36 +00:00
|
|
|
return self._parse_node(dom)
|
|
|
|
|
|
|
|
def create(self, cr, uid, ids, datas, context=None):
|
|
|
|
if not context:
|
|
|
|
context={}
|
|
|
|
datas['ids'] = ids
|
2013-03-27 11:10:14 +00:00
|
|
|
registry = openerp.registry(cr.dbname)
|
|
|
|
model = registry[datas['model']]
|
2010-09-06 08:11:04 +00:00
|
|
|
# title come from description of model which are specified in py file.
|
2010-09-01 11:53:10 +00:00
|
|
|
self.title = model._description
|
|
|
|
result = model.fields_view_get(cr, uid, view_type='form', context=context)
|
2008-07-22 14:24:36 +00:00
|
|
|
|
|
|
|
fields_order = self._parse_string(result['arch'])
|
|
|
|
rows = model.read(cr, uid, datas['ids'], result['fields'].keys() )
|
2011-06-17 15:18:07 +00:00
|
|
|
self._create_table(uid, datas['ids'], result['fields'], fields_order, rows, context, model._description)
|
2012-12-14 12:38:03 +00:00
|
|
|
return self.obj.get(), 'pdf'
|
2008-07-22 14:24:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _create_table(self, uid, ids, fields, fields_order, results, context, title=''):
|
|
|
|
pageSize=[297.0,210.0]
|
|
|
|
|
2009-06-12 11:05:11 +00:00
|
|
|
new_doc = etree.Element("report")
|
2009-11-28 10:48:10 +00:00
|
|
|
config = etree.SubElement(new_doc, 'config')
|
2008-07-22 14:24:36 +00:00
|
|
|
|
|
|
|
# build header
|
|
|
|
def _append_node(name, text):
|
2009-11-28 10:48:10 +00:00
|
|
|
n = etree.SubElement(config, name)
|
2009-06-12 11:05:11 +00:00
|
|
|
n.text = text
|
2008-07-22 14:24:36 +00:00
|
|
|
|
|
|
|
_append_node('date', time.strftime('%d/%m/%Y'))
|
|
|
|
_append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize))
|
|
|
|
_append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346,))
|
|
|
|
_append_node('PageHeight', '%.2f' %(pageSize[1] * 2.8346,))
|
|
|
|
_append_node('report-header', title)
|
|
|
|
|
|
|
|
l = []
|
|
|
|
t = 0
|
|
|
|
strmax = (pageSize[0]-40) * 2.8346
|
|
|
|
for f in fields_order:
|
|
|
|
s = 0
|
|
|
|
if fields[f]['type'] in ('date','time','float','integer'):
|
|
|
|
s = 60
|
|
|
|
strmax -= s
|
|
|
|
else:
|
|
|
|
t += fields[f].get('size', 56) / 28 + 1
|
|
|
|
l.append(s)
|
|
|
|
for pos in range(len(l)):
|
|
|
|
if not l[pos]:
|
|
|
|
s = fields[fields_order[pos]].get('size', 56) / 28 + 1
|
|
|
|
l[pos] = strmax * s / t
|
|
|
|
_append_node('tableSize', ','.join(map(str,l)) )
|
|
|
|
|
2009-11-28 10:48:10 +00:00
|
|
|
header = etree.SubElement(new_doc, 'header')
|
2008-07-22 14:24:36 +00:00
|
|
|
for f in fields_order:
|
2009-11-28 10:48:10 +00:00
|
|
|
field = etree.SubElement(header, 'field')
|
2009-06-12 11:05:11 +00:00
|
|
|
field.text = fields[f]['string'] or ''
|
2009-11-28 10:48:10 +00:00
|
|
|
|
|
|
|
lines = etree.SubElement(new_doc, 'lines')
|
2008-07-22 14:24:36 +00:00
|
|
|
for line in results:
|
2009-11-28 10:48:10 +00:00
|
|
|
node_line = etree.SubElement(lines, 'row')
|
2008-07-22 14:24:36 +00:00
|
|
|
for f in fields_order:
|
|
|
|
if fields[f]['type']=='many2one' and line[f]:
|
|
|
|
line[f] = line[f][1]
|
|
|
|
if fields[f]['type'] in ('one2many','many2many') and line[f]:
|
|
|
|
line[f] = '( '+str(len(line[f])) + ' )'
|
2008-09-26 06:19:57 +00:00
|
|
|
if fields[f]['type'] == 'float':
|
|
|
|
precision=(('digits' in fields[f]) and fields[f]['digits'][1]) or 2
|
|
|
|
line[f]=round(line[f],precision)
|
2009-11-28 10:48:10 +00:00
|
|
|
col = etree.SubElement(node_line, 'col', tree='no')
|
2012-12-14 12:16:38 +00:00
|
|
|
if line[f] is not None:
|
2012-02-08 17:04:56 +00:00
|
|
|
col.text = tools.ustr(line[f] or '')
|
2008-07-22 14:24:36 +00:00
|
|
|
else:
|
2009-06-12 11:05:11 +00:00
|
|
|
col.text = '/'
|
2008-07-22 14:24:36 +00:00
|
|
|
|
2009-11-28 10:01:04 +00:00
|
|
|
transform = etree.XSLT(
|
|
|
|
etree.parse(os.path.join(tools.config['root_path'],
|
|
|
|
'addons/base/report/custom_new.xsl')))
|
|
|
|
rml = etree.tostring(transform(new_doc))
|
|
|
|
|
2008-09-24 15:34:10 +00:00
|
|
|
self.obj = render.rml(rml, self.title)
|
2008-07-22 14:24:36 +00:00
|
|
|
self.obj.render()
|
|
|
|
return True
|
2006-12-07 13:41:40 +00:00
|
|
|
report_printscreen_list('report.printscreen.form')
|
|
|
|
|
2008-07-23 15:01:27 +00:00
|
|
|
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|