jasper_reports: Get model and Id without data

Bug #918349 reported by Raimon Esteve (www.zikzakmedia.com)
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
openobject-jasper-reports
New
Undecided
Unassigned

Bug Description

In point_of_sale, we replace rml report default to jrxml.

When click button print, we need to print account.invoice report, but when execute jasper_reports, in data is null

[2012-01-18 20:06:49,363][oerp6_microfusa] ERROR:web-services:[02]: Traceback (most recent call last):
[2012-01-18 20:06:49,364][oerp6_microfusa] ERROR:web-services:[03]: File "/home/resteve/openerp-server6/bin/service/web_services.py", line 724, in go
[2012-01-18 20:06:49,364][oerp6_microfusa] ERROR:web-services:[04]: (result, format) = obj.create(cr, uid, ids, datas, context)
[2012-01-18 20:06:49,364][oerp6_microfusa] ERROR:web-services:[05]: File "/home/resteve/openerp-server6/bin/addons/jasper_reports/jasper_report.py", line 252, in create
[2012-01-18 20:06:49,364][oerp6_microfusa] ERROR:web-services:[06]: r = Report( name, cr, uid, ids, data, context )
[2012-01-18 20:06:49,364][oerp6_microfusa] ERROR:web-services:[07]: File "/home/resteve/openerp-server6/bin/addons/jasper_reports/jasper_report.py", line 60, in __init__
[2012-01-18 20:06:49,364][oerp6_microfusa] ERROR:web-services:[08]: self.model = self.data['model']
[2012-01-18 20:06:49,364][oerp6_microfusa] ERROR:web-services:[09]: KeyError: 'model'

But in context, we have model and id. We can get this information if data is null

Here patch:

--- jasper_report.py (revision 713)
+++ jasper_report.py (working copy)
@@ -248,6 +248,9 @@
    # an empty 'records' parameter while still executing using 'records'
    data['data_source'] = d.get( 'data_source', 'model' )
    data['parameters'] = d.get( 'parameters', {} )
+ if not 'model' in data and 'active_model' in context:
+ data['model'] = context['active_model']
+ data['id'] = context['active_id']
   r = Report( name, cr, uid, ids, data, context )
   #return ( r.execute(), 'pdf' )
   return r.execute()

Here all class create:

 def create(self, cr, uid, ids, data, context):
  name = self.name
  if self.parser:
   d = self.parser( cr, uid, ids, data, context )
   ids = d.get( 'ids', ids )
   name = d.get( 'name', self.name )
   # Use model defined in report_jasper definition. Necesary for menu entries.
   data['model'] = d.get( 'model', self.model )
   data['records'] = d.get( 'records', [] )
   # data_source can be 'model' or 'records' and lets parser to return
   # an empty 'records' parameter while still executing using 'records'
   data['data_source'] = d.get( 'data_source', 'model' )
   data['parameters'] = d.get( 'parameters', {} )
  if not 'model' in data and 'active_model' in context:
   data['model'] = context['active_model']
   data['id'] = context['active_id']
  r = Report( name, cr, uid, ids, data, context )
  #return ( r.execute(), 'pdf' )
  return r.execute()

Feedback?

Revision history for this message
Raimon Esteve (www.zikzakmedia.com) (resteve) wrote :

or more better:

--- jasper_report.py (revision 713)
+++ jasper_report.py (working copy)
@@ -248,6 +248,9 @@
    # an empty 'records' parameter while still executing using 'records'
    data['data_source'] = d.get( 'data_source', 'model' )
    data['parameters'] = d.get( 'parameters', {} )
+ if not data.get('model',False) and context.get('active_model', False):
+ data['model'] = context['active_model']
+ data['id'] = context['active_id']
   r = Report( name, cr, uid, ids, data, context )
   #return ( r.execute(), 'pdf' )
   return r.execute()

affects: openobject-client-kde → openobject-jasper-reports
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.