Modifs for logo and multiple-header

bzr revid: fp@tinyerp.com-f40939b7bd24b27497ead8daa85335ef727cef47
This commit is contained in:
Fabien Pinckaers 2008-04-21 13:04:49 +00:00
parent 1e256fd373
commit 4a567f3e7a
6 changed files with 81 additions and 18 deletions

View File

@ -16,7 +16,7 @@
<menuitem name="Administration/Configuration/Base" sequence="1"/>
<record model="ir.actions.act_window" id="open_module_tree_company">
<field name="name">res.company</field>
<field name="name">Your Companies</field>
<field name="res_model">res.company</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>

View File

@ -171,13 +171,22 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Company">
<field name="name" colspan="4" select="1"/>
<field name="partner_id" select="1"/>
<field name="parent_id" select="1"/>
<field name="rml_header1"/>
<field name="rml_footer1"/>
<field name="rml_footer2"/>
<field name="currency_id"/>
<notebook>
<page string="General Information">
<field name="name" colspan="4" select="1"/>
<field name="partner_id" select="1"/>
<field name="parent_id" select="1"/>
<field name="rml_header1"/>
<field name="rml_footer1"/>
<field name="rml_footer2"/>
<field name="currency_id"/>
<separator string="Your Logo - User a size of about 450x150 pixels." colspan="4"/>
<field name="logo" widget="image" colspan="4"/>
</page>
<page string="Header/Footer">
<field name="rml_header" colspan="4" nolabel="1"/>
</page>
</notebook>
</form>
</field>
</record>

View File

@ -1,7 +1,7 @@
##############################################################################
#
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
# Fabien Pinckaers <fp@tiny.Be>
# Fabien Pinckaers <fp@tiny.Be>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
@ -40,6 +40,8 @@ class res_company(osv.osv):
'rml_header1': fields.char('Report Header', size=200),
'rml_footer1': fields.char('Report Footer 1', size=200),
'rml_footer2': fields.char('Report Footer 2', size=200),
'rml_header' : fields.text('Rml Header'),
'logo' : fields.binary('Logo'),
'currency_id': fields.many2one('res.currency', 'Currency', required=True),
}
@ -106,8 +108,44 @@ class res_company(osv.osv):
level -= 1
return True
def _get_header(self,cr,uid,ids):
try :
return tools.file_open('custom/corporate_rml_header.rml').read()
except:
return """<header>
<pageTemplate>
<frame id="first" x1="1cm" y1="2.5cm" width="19.0cm" height="23.0cm"/>
<pageGraphics>
<!--logo-->
<setFont name="Helvetica" size="30"/>
<fill color="black"/>
<stroke color="black"/>
<image x="13cm" y="25.4cm" height="2.4cm" name="logo"/>
<drawString x="1cm" y="27.8cm">[[ company.partner_id.name ]]</drawString>
<lines>1cm 27.7cm 20cm 27.7cm</lines>
<setFont name="Helvetica" size="10"/>
<drawRightString x="20cm" y="27.8cm">[[ company.rml_header1 ]]</drawRightString>
<drawString x="1cm" y="27.2cm">[[ company.partner_id.address and company.partner_id.address[0].street ]]</drawString>
<drawString x="1cm" y="26.8cm">[[ company.partner_id.address and company.partner_id.address[0].zip ]] [[ company.partner_id.address and company.partner_id.address[0].city ]] - [[ company.partner_id.address and company.partner_id.address[0].country_id and company.partner_id.address[0].country_id.name ]]</drawString>
<drawString x="1cm" y="26.4cm">Phone:</drawString>
<drawRightString x="7cm" y="26.4cm">[[ company.partner_id.address and company.partner_id.address[0].phone ]]</drawRightString>
<drawString x="1cm" y="26.0cm">Mail:</drawString>
<drawRightString x="7cm" y="26.0cm">[[ company.partner_id.address and company.partner_id.address[0].email ]]</drawRightString>
<lines>1cm 25.9cm 7cm 25.9cm</lines>
<!--page bottom-->
<lines>1.5cm 2.15cm 19.9cm 2.15cm</lines>
<drawCentredString x="10.5cm" y="1.7cm">[[ company.rml_footer1 ]]</drawCentredString>
<drawCentredString x="10.5cm" y="1.25cm">[[ company.rml_footer2 ]]</drawCentredString>
<drawCentredString x="10.5cm" y="0.8cm">Contact : [[ user.name ]]</drawCentredString>
</pageGraphics>
</pageTemplate>
</header>"""
_defaults = {
'currency_id': _get_euro,
'rml_header':_get_header
}
_constraints = [

View File

@ -104,7 +104,7 @@ class report_rml(report_int):
if not context:
context={}
doc = print_xml.document(cr, uid, datas, {})
self.bin_datas = doc.bin_datas
self.bin_datas.update( doc.bin_datas or {})
doc.parse(self.tmpl, ids, self.table, context)
xml = doc.xml_get()
doc.close()
@ -191,20 +191,25 @@ class report_rml(report_int):
result.freeDoc()
return xml
def create_pdf(self, xml):
def create_pdf(self, xml, logo=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()
return obj.get()
def create_html(self, xml):
def create_html(self, xml, logo=None):
obj = render.rml2html(xml, self.bin_datas)
obj.render()
return obj.get()
def create_raw(self, xml):
def create_raw(self, xml, logo=None):
return xml
def create_sxw(self, path):
def create_sxw(self, path, logo=None):
return path
from report_sxw import report_sxw

View File

@ -301,7 +301,11 @@ class _rml_canvas(object):
from reportlab.lib.utils import ImageReader
if not node.hasAttribute('file'):
s = self.images[node.getAttribute('name')]
if node.getAttribute('name') in self.images:
scontent = self.images[node.getAttribute('name')]
s = StringIO.StringIO(scontent)
else:
return True
else:
if node.getAttribute('file') in self.images:
s = StringIO.StringIO(self.images[node.getAttribute('file')])

View File

@ -46,6 +46,8 @@ DT_FORMAT = '%Y-%m-%d'
DHM_FORMAT = '%Y-%m-%d %H:%M:%S'
HM_FORMAT = '%H:%M:%S'
import base64
if not hasattr(locale, 'nl_langinfo'):
locale.nl_langinfo = lambda *a: '%x'
@ -200,6 +202,8 @@ class rml_parse(object):
'formatLang': self.formatLang,
}
self.localcontext.update(context)
self.rml_header = user.company_id.rml_header
self.logo = user.company_id.logo
self.name = name
self._regex = re.compile('\[\[(.+?)\]\]')
self._transl_regex = re.compile('(\[\[.+?\]\])')
@ -432,7 +436,7 @@ class rml_parse(object):
return False
def _add_header(self, node):
rml_head = tools.file_open('custom/corporate_rml_header.rml').read()
rml_head = self.rml_header
head_dom = xml.dom.minidom.parseString(rml_head)
#for frame in head_dom.getElementsByTagName('frame'):
# frame.parentNode.removeChild(frame)
@ -479,6 +483,7 @@ class report_sxw(report_rml):
return table_obj.browse(cr, uid, ids, list_class=browse_record_list, context=context)
def create(self, cr, uid, ids, data, context=None):
logo = None
if not context:
context={}
context = context.copy()
@ -547,7 +552,6 @@ class report_sxw(report_rml):
if self.header:
#Add corporate header/footer
rml_head = tools.file_open('custom/corporate_rml_header.rml').read()
rml = tools.file_open('custom/corporate_sxw_header.xml').read()
rml_parser = self.parser(cr, uid, self.name2, context)
rml_parser.parents = sxw_parents
@ -574,8 +578,11 @@ class report_sxw(report_rml):
# f = file("/tmp/debug.rml", "w")
# f.write(rml2)
# f.close()
if rml_parser.logo:
logo = base64.decodestring(rml_parser.logo)
create_doc = self.generators[report_type]
pdf = create_doc(rml2)
pdf = create_doc(rml2, logo)
return (pdf, report_type)