[REM, ADD]: res.company: Removed preview_report function,
* Added new blank report to print company header/footer bzr revid: rpa@tinyerp.com-20110706125541-1uk17x39458nwonl
This commit is contained in:
parent
d83d2cefa0
commit
e1472fa807
|
@ -23,6 +23,7 @@ import ir
|
|||
import module
|
||||
import res
|
||||
import publisher_warranty
|
||||
import report
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -186,6 +186,10 @@
|
|||
Company
|
||||
======================
|
||||
-->
|
||||
|
||||
<report id="preview_report" model="res.company" name="preview.report" multi="True"
|
||||
rml="base/report/preview_report.rml" string="Preview Report"/>
|
||||
|
||||
<record id="view_company_form" model="ir.ui.view">
|
||||
<field name="name">res.company.form</field>
|
||||
<field name="model">res.company</field>
|
||||
|
@ -219,7 +223,7 @@
|
|||
<field name="rml_footer2" colspan="4"/>
|
||||
<group colspan="4" col="8">
|
||||
<label string="" colspan="7"/>
|
||||
<button name="preview_report" string="Preview Report" type="object" icon="gtk-print"/>
|
||||
<button name="%(preview_report)d" string="Preview Report" type="action" icon="gtk-print"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Header/Footer" groups="base.group_extended">
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
import preview_report
|
|
@ -0,0 +1,35 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# 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.
|
||||
#
|
||||
# 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
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
from report import report_sxw
|
||||
|
||||
|
||||
class preview_report_company(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(preview_report_company, self).__init__(cr, uid, name, context)
|
||||
self.localcontext.update({
|
||||
'time': time,
|
||||
})
|
||||
|
||||
report_sxw.report_sxw('report.preview.report', 'res.company',
|
||||
'addons/base/report/preview_report.rml', parser=preview_report_company, header='external')
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0"?>
|
||||
<document filename="test.pdf">
|
||||
<template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
|
||||
<pageTemplate id="first">
|
||||
<frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
|
||||
</pageTemplate>
|
||||
</template>
|
||||
<stylesheet>
|
||||
<blockTableStyle id="Standard_Outline">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<initialize>
|
||||
<paraStyle name="all" alignment="justify"/>
|
||||
</initialize>
|
||||
<paraStyle name="Standard" fontName="Helvetica"/>
|
||||
<images/>
|
||||
</stylesheet>
|
||||
<story>
|
||||
<para style="Standard">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</story>
|
||||
</document>
|
|
@ -306,47 +306,6 @@ class res_company(osv.osv):
|
|||
(osv.osv._check_recursion, 'Error! You can not create recursive companies.', ['parent_id'])
|
||||
]
|
||||
|
||||
def preview_report(self, cr, uid, ids, context=None):
|
||||
#TODO: we should be able to create a report dynamically without using the filesystem (without using the trick with tempfilename)
|
||||
if not ids:
|
||||
return False
|
||||
# we need to pass the company_id in order to make a new browse record for the rml parser, because the cursor was previously closed and because of this partner data was not printed
|
||||
company_id = ids[0]
|
||||
company = self.browse(cr, uid, company_id, context=context)
|
||||
|
||||
class company_parser(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(company_parser, self).__init__(cr, uid, name, context=context)
|
||||
import openerp
|
||||
company = openerp.pooler.get_pool(cr.dbname).get('res.company').browse(cr, uid, company_id, context=context)
|
||||
self.setCompany(company)
|
||||
|
||||
rml = etree.XML(company.rml_header)
|
||||
rml = rml.getchildren()[0]
|
||||
header_xml = """<document filename="Preview Report.pdf">
|
||||
<template pageSize="(595.0,842.0)" title="Preview Report" author="OpenERP S.A.(sales@openerp.com)" allowSplitting="20">"""
|
||||
footer_xml = """
|
||||
</template>
|
||||
</document>
|
||||
"""
|
||||
tempfileid, tempfilename= tempfile.mkstemp('.rml', 'openerp_')
|
||||
fp = open(tempfilename, 'wb+')
|
||||
fp.write(header_xml)
|
||||
fp.write(etree.tostring(rml))
|
||||
fp.write(footer_xml)
|
||||
fp.close()
|
||||
|
||||
#we need to remove the eventual instances of this report, as we can't have 2 services with the same name
|
||||
netsvc.Service._services.pop('report.company.report', False)
|
||||
#the report service is created on the fly because there is no rml given
|
||||
report_sxw.report_sxw('report.company.report', 'res.company', tempfilename, parser=company_parser)
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'company.report',
|
||||
'datas': {'ids': ids, 'model': 'res.company'},
|
||||
'nodestroy': True,
|
||||
'context': context #pass the context in order to use it in the browse of the company_parser
|
||||
}
|
||||
|
||||
res_company()
|
||||
|
||||
|
|
Loading…
Reference in New Issue