[IMP]: Solve the cursor problem in report

bzr revid: ksa@tinyerp.co.in-20110419061953-sdn1drm3wufa47tm
This commit is contained in:
ksa (Open ERP)
2011-04-19 11:49:53 +05:30
parent 9d1a9795f1
commit 4ab3faacb5
+7 -8
View File
@@ -284,16 +284,15 @@ class res_company(osv.osv):
]
def createReport(self, cr, uid, ids, context=None):
# Used new cursor as it was closed explicitly somewhere and because of this partner data was not printed
# Tocheck: its not closed
cr = pooler.get_db(cr.dbname).cursor()
company = self.browse(cr, uid, ids, context=context)[0]
# partner, address, country, phone, email = company.partner_id.name, company.partner_id.address and company.partner_id.address[0].street or '',\
# company.partner_id.address and company.partner_id.address[0].country_id and company.partner_id.address[0].country_id.name or '',\
# company.partner_id.address and company.partner_id.address[0].phone or '',\
# company.partner_id.address and company.partner_id.address[0].email or '',
class company_parser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(company_parser, self).__init__(cr, uid, name, context=context)
self.setCompany(company)
rml = etree.XML(company.rml_header)
rml = rml.getchildren()[0]
header_xml = """<document filename="Preview Report.pdf">
@@ -301,13 +300,13 @@ class res_company(osv.osv):
</template>
</document>
"""
tmppath= '/tmp/previews.rml'
fp = open(tmppath, 'wb+')
tempfilename= os.tempnam()
fp = open(tempfilename, 'wb+')
fp.write(header_xml)
fp.close()
if netsvc.Service._services.get('report.company.report'):
netsvc.Service._services.pop('report.company.report')
myreport = report_sxw.report_sxw('report.company.report', 'res.company', tmppath, parser=company_parser)
myreport = report_sxw.report_sxw('report.company.report', 'res.company', tempfilename, parser=company_parser)
return {
'type': 'ir.actions.report.xml',
'report_name': 'company.report',