set report name as pdf name in reports (ref: bhoomika- sbh)
bzr revid: hda@tinyerp.com-20080811092755-7qknwqfcgrlg8zuk
This commit is contained in:
parent
4ec0643d46
commit
8401c4021f
|
@ -97,11 +97,16 @@ class report_rml(report_int):
|
|||
return xml
|
||||
rml = self.create_rml(cr, xml, uid, context)
|
||||
# file('/tmp/terp.rml','wb+').write(rml)
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
ir_actions_report_xml_obj = pool.get('ir.actions.report.xml')
|
||||
report_xml_ids = ir_actions_report_xml_obj.search(cr, uid,
|
||||
[('report_name', '=', self.name[7:])], context=context)
|
||||
ftitle = ir_actions_report_xml_obj.browse(cr,uid,report_xml_ids)[0].name
|
||||
report_type = datas.get('report_type', 'pdf')
|
||||
create_doc = self.generators[report_type]
|
||||
pdf = create_doc(rml)
|
||||
pdf = create_doc(rml,title=ftitle)
|
||||
return (pdf, report_type)
|
||||
|
||||
|
||||
def create_xml(self, cr, uid, ids, datas, context=None):
|
||||
if not context:
|
||||
context={}
|
||||
|
@ -115,7 +120,7 @@ class report_rml(report_int):
|
|||
def post_process_xml_data(self, cr, uid, xml, context=None):
|
||||
if not context:
|
||||
context={}
|
||||
# find the position of the 3rd tag
|
||||
# find the position of the 3rd tag
|
||||
# (skip the <?xml ...?> and the "root" tag)
|
||||
iter = re.finditer('<[^>]*>', xml)
|
||||
i = iter.next()
|
||||
|
@ -185,31 +190,31 @@ class report_rml(report_int):
|
|||
result = style.applyStylesheet(doc, None)
|
||||
# save result to string
|
||||
xml = style.saveResultToString(result)
|
||||
|
||||
|
||||
style.freeStylesheet()
|
||||
doc.freeDoc()
|
||||
result.freeDoc()
|
||||
return xml
|
||||
|
||||
def create_pdf(self, xml, logo=None):
|
||||
|
||||
def create_pdf(self, xml, logo=None,title=None):
|
||||
if logo:
|
||||
self.bin_datas['logo'] = logo
|
||||
else:
|
||||
if 'logo' in self.bin_datas:
|
||||
del self.bin_datas['logo']
|
||||
obj = render.rml(xml, self.bin_datas, tools.config['root_path'])
|
||||
obj = render.rml(xml, self.bin_datas, tools.config['root_path'],title)
|
||||
obj.render()
|
||||
return obj.get()
|
||||
|
||||
def create_html(self, xml, logo=None):
|
||||
def create_html(self, xml, logo=None,title=None):
|
||||
obj = render.rml2html(xml, self.bin_datas)
|
||||
obj.render()
|
||||
return obj.get()
|
||||
|
||||
def create_raw(self, xml, logo=None):
|
||||
def create_raw(self, xml, logo=None,title=None):
|
||||
return xml
|
||||
|
||||
def create_sxw(self, path, logo=None):
|
||||
def create_sxw(self, path, logo=None,title=None):
|
||||
return path
|
||||
|
||||
from report_sxw import report_sxw
|
||||
|
|
|
@ -39,7 +39,7 @@ import libxml2
|
|||
import libxslt
|
||||
|
||||
import time, os
|
||||
|
||||
ftitle=""
|
||||
class report_printscreen_list(report_int):
|
||||
def __init__(self, name):
|
||||
report_int.__init__(self, name)
|
||||
|
@ -63,6 +63,7 @@ class report_printscreen_list(report_int):
|
|||
return self._parse_node(dom)
|
||||
|
||||
def create(self, cr, uid, ids, datas, context=None):
|
||||
global ftitle
|
||||
if not context:
|
||||
context={}
|
||||
datas['ids'] = ids
|
||||
|
@ -70,8 +71,10 @@ class report_printscreen_list(report_int):
|
|||
model_id = pool.get('ir.model').search(cr, uid, [('model','=',model._name)])
|
||||
if model_id:
|
||||
model_desc = pool.get('ir.model').browse(cr, uid, model_id, context).name
|
||||
ftitle=model_desc
|
||||
else:
|
||||
model_desc = model._description
|
||||
ftitle=model_desc
|
||||
|
||||
model = pool.get(datas['model'])
|
||||
result = model.fields_view_get(cr, uid, view_type='tree', context=context)
|
||||
|
@ -128,7 +131,7 @@ class report_printscreen_list(report_int):
|
|||
field_txt = new_doc.createTextNode(str(fields[f]['string']))
|
||||
field.appendChild(field_txt)
|
||||
header.appendChild(field)
|
||||
|
||||
|
||||
new_doc.childNodes[0].appendChild(header)
|
||||
|
||||
lines = new_doc.createElement("lines")
|
||||
|
@ -154,9 +157,9 @@ class report_printscreen_list(report_int):
|
|||
style = libxslt.parseStylesheetDoc(styledoc)
|
||||
doc = libxml2.parseDoc(new_doc.toxml())
|
||||
rml_obj = style.applyStylesheet(doc, None)
|
||||
rml = style.saveResultToString(rml_obj)
|
||||
|
||||
self.obj = render.rml(rml)
|
||||
rml = style.saveResultToString(rml_obj)
|
||||
global ftitle
|
||||
self.obj = render.rml(rml,ftitle)
|
||||
self.obj.render()
|
||||
return True
|
||||
report_printscreen_list('report.printscreen.form')
|
||||
|
|
|
@ -39,7 +39,7 @@ import libxml2
|
|||
import libxslt
|
||||
|
||||
import time, os
|
||||
|
||||
ftitle=""
|
||||
class report_printscreen_list(report_int):
|
||||
def __init__(self, name):
|
||||
report_int.__init__(self, name)
|
||||
|
@ -63,6 +63,7 @@ class report_printscreen_list(report_int):
|
|||
return self._parse_node(dom)
|
||||
|
||||
def create(self, cr, uid, ids, datas, context=None):
|
||||
global ftitle
|
||||
if not context:
|
||||
context={}
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
@ -70,8 +71,10 @@ class report_printscreen_list(report_int):
|
|||
model_id = pool.get('ir.model').search(cr, uid, [('model','=',model._name)])
|
||||
if model_id:
|
||||
model_desc = pool.get('ir.model').browse(cr, uid, model_id[0], context).name
|
||||
ftitle=model_desc
|
||||
else:
|
||||
model_desc = model._description
|
||||
ftitle=model_desc
|
||||
|
||||
datas['ids'] = ids
|
||||
model = pooler.get_pool(cr.dbname).get(datas['model'])
|
||||
|
@ -199,7 +202,8 @@ class report_printscreen_list(report_int):
|
|||
doc = libxml2.parseDoc(new_doc.toxml())
|
||||
rml_obj = style.applyStylesheet(doc, None)
|
||||
rml = style.saveResultToString(rml_obj)
|
||||
self.obj = render.rml(rml)
|
||||
global ftitle
|
||||
self.obj = render.rml(rml,title=ftitle)
|
||||
self.obj.render()
|
||||
return True
|
||||
report_printscreen_list('report.printscreen.list')
|
||||
|
|
|
@ -33,21 +33,22 @@ import rml2pdf
|
|||
import rml2html as htmlizer
|
||||
|
||||
class rml(render.render):
|
||||
def __init__(self, xml, datas={}, path='.'):
|
||||
def __init__(self, xml, datas={}, path='.',title=None):
|
||||
render.render.__init__(self, datas)
|
||||
self.xml = xml
|
||||
self.output_type = 'pdf'
|
||||
self.path = path
|
||||
self.title=title
|
||||
|
||||
def _render(self):
|
||||
return rml2pdf.parseString(self.xml, images=self.bin_datas, path=self.path)
|
||||
return rml2pdf.parseString(self.xml, images=self.bin_datas, path=self.path,title=self.title)
|
||||
|
||||
class rml2html(render.render):
|
||||
def __init__(self, xml, datas={}):
|
||||
super(rml2html, self).__init__(datas)
|
||||
self.xml = xml
|
||||
self.output_type = 'html'
|
||||
|
||||
|
||||
def _render(self):
|
||||
return htmlizer.parseString(self.xml)
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ from reportlab import platypus
|
|||
import utils
|
||||
import color
|
||||
import os
|
||||
|
||||
ftitle=""
|
||||
#
|
||||
# Change this to UTF-8 if you plan tu use Reportlab's UTF-8 support
|
||||
#
|
||||
|
@ -110,7 +110,7 @@ class _rml_styles(object):
|
|||
for attr in ['fontName', 'bulletFontName', 'bulletText']:
|
||||
if node.hasAttribute(attr):
|
||||
data[attr] = node.getAttribute(attr)
|
||||
for attr in ['fontSize', 'leftIndent', 'rightIndent', 'spaceBefore', 'spaceAfter',
|
||||
for attr in ['fontSize', 'leftIndent', 'rightIndent', 'spaceBefore', 'spaceAfter',
|
||||
'firstLineIndent', 'bulletIndent', 'bulletFontSize', 'leading',
|
||||
'borderWidth','borderPadding','borderRadius']:
|
||||
if node.hasAttribute(attr):
|
||||
|
@ -248,6 +248,9 @@ class _rml_canvas(object):
|
|||
self.doc = doc
|
||||
self.images = images
|
||||
self.path = path
|
||||
global ftitle
|
||||
if ftitle:
|
||||
self.canvas.setTitle(ftitle)
|
||||
|
||||
def _textual(self, node, x=0, y=0):
|
||||
rc = ''
|
||||
|
@ -701,7 +704,7 @@ class _rml_flowable(object):
|
|||
node = node_story.firstChild
|
||||
while node:
|
||||
if node.nodeType == node.ELEMENT_NODE:
|
||||
flow = self._flowable(node)
|
||||
flow = self._flowable(node)
|
||||
if flow:
|
||||
if type(flow) == type([]):
|
||||
story = story + flow
|
||||
|
@ -777,11 +780,13 @@ class _rml_template(object):
|
|||
fis.append(PageCount())
|
||||
|
||||
fis.append(platypus.PageBreak())
|
||||
|
||||
|
||||
self.doc_tmpl.build(fis)
|
||||
|
||||
def parseString(data, fout=None, images={}, path='.'):
|
||||
def parseString(data, fout=None, images={}, path='.',title=None):
|
||||
r = _rml_doc(data, images, path)
|
||||
global ftitle
|
||||
ftitle=title
|
||||
if fout:
|
||||
fp = file(fout,'wb')
|
||||
r.render(fp)
|
||||
|
|
|
@ -197,7 +197,7 @@ class _date_format(str, _format):
|
|||
datedata)
|
||||
except :
|
||||
pass
|
||||
return ''
|
||||
return ''
|
||||
|
||||
_fields_process = {
|
||||
'float': _float_format,
|
||||
|
@ -415,7 +415,7 @@ class rml_parse(object):
|
|||
res = self._regex.findall(text)
|
||||
todo = []
|
||||
# translate the text
|
||||
# the "split [[]] if not match [[]]" is not very nice, but I
|
||||
# the "split [[]] if not match [[]]" is not very nice, but I
|
||||
# don't see how I could do it better...
|
||||
# what I'd like to do is a re.sub(NOT pattern, func, string)
|
||||
# but I don't know how to do that...
|
||||
|
@ -444,7 +444,7 @@ class rml_parse(object):
|
|||
#if not isinstance(newtext, basestring):
|
||||
newtext = str(newtext)
|
||||
# if there are two [[]] blocks the same, it will replace both
|
||||
# but it's ok because it should evaluate to the same thing
|
||||
# but it's ok because it should evaluate to the same thing
|
||||
# anyway
|
||||
text = text.replace('[['+key+']]', newtext.decode('utf8'))
|
||||
self._node.data = text
|
||||
|
@ -485,7 +485,7 @@ class rml_parse(object):
|
|||
self.localcontext.update(self.node_context[self._node])
|
||||
if self._node.nodeType in (self._node.CDATA_SECTION_NODE, self._node.TEXT_NODE):
|
||||
# if self._node in self.already:
|
||||
# self.already[self._node] += 1
|
||||
# self.already[self._node] += 1
|
||||
# print "second pass!", self.already[self._node], '---%s---' % self._node.data
|
||||
# else:
|
||||
# self.already[self._node] = 0
|
||||
|
@ -660,7 +660,8 @@ class report_sxw(report_rml):
|
|||
logo = base64.decodestring(rml_parser.logo)
|
||||
|
||||
create_doc = self.generators[report_type]
|
||||
pdf = create_doc(rml2, logo)
|
||||
title = ir_actions_report_xml_obj.browse(cr,uid,report_xml_ids)[0].name
|
||||
pdf = create_doc(rml2, logo,title)
|
||||
return (pdf, report_type)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue