Error while calling customized report

Asked by Deven Moga on 2009-08-31

Hello,

I am trying to Call customized report which i have generated but when i am calling it, i am getting below error.

-------------------------------------------------------------------------------------
Environment Information :
System : Linux-2.6.27-14-generic-i686-with-debian-lenny-sid
OS Name : posix
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid
Operating System Release : 2.6.27-14-generic
Operating System Version : #1 SMP Tue Aug 18 16:25:45 UTC 2009
Operating System Architecture : 32bit
Operating System Locale : en_IN.ISO8859-1
Python Version : 2.5.2
OpenERP-Client Version : 5.0.3
Last revision No. & ID : 984 <email address hidden>
Traceback (most recent call last):
  File "/home/deven/workspace/server/bin/service/web_services.py", line 687, in go
    (result, format) = obj.create(cr, uid, ids, datas, context)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 364, in create
    return fnct(cr, uid, ids, data, report_xml, context)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 421, in create_source_pdf
    return self.create_single_pdf(cr, uid, ids, data, report_xml, context)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 432, in create_single_pdf
    rml_parser.set_context(objs, data, ids, report_xml.report_type)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 316, in set_context
    self.localcontext['data'] = data
AttributeError: 'purchase_by_product' object has no attribute 'localcontext'
---------------------------------------------------------------------------------------------------------

Server Trace :

No LSB modules are available.
[2009-08-31 19:41:05,370] ERROR:web-services:[01]:
[2009-08-31 19:41:05,371] ERROR:web-services:[02]: Environment Information :
[2009-08-31 19:41:05,371] ERROR:web-services:[03]: System : Linux-2.6.27-14-generic-i686-with-debian-lenny-sid
[2009-08-31 19:41:05,371] ERROR:web-services:[04]: OS Name : posix
[2009-08-31 19:41:05,371] ERROR:web-services:[05]: Distributor ID: Ubuntu
[2009-08-31 19:41:05,371] ERROR:web-services:[06]: Description: Ubuntu 8.10
[2009-08-31 19:41:05,371] ERROR:web-services:[07]: Release: 8.10
[2009-08-31 19:41:05,371] ERROR:web-services:[08]: Codename: intrepid
[2009-08-31 19:41:05,371] ERROR:web-services:[09]: Operating System Release : 2.6.27-14-generic
[2009-08-31 19:41:05,371] ERROR:web-services:[10]: Operating System Version : #1 SMP Tue Aug 18 16:25:45 UTC 2009
[2009-08-31 19:41:05,371] ERROR:web-services:[11]: Operating System Architecture : 32bit
[2009-08-31 19:41:05,372] ERROR:web-services:[12]: Operating System Locale : en_IN.ISO8859-1
[2009-08-31 19:41:05,372] ERROR:web-services:[13]: Python Version : 2.5.2
[2009-08-31 19:41:05,372] ERROR:web-services:[14]: OpenERP-Server Version : 5.0.3
[2009-08-31 19:41:05,372] ERROR:web-services:[15]: Last revision No. & ID : 1839 <email address hidden>
[2009-08-31 19:41:05,372] ERROR:web-services:[16]: Exception: 'purchase_by_product' object has no attribute 'localcontext'
[2009-08-31 19:41:05,372] ERROR:web-services:[17]: Traceback (most recent call last):
[2009-08-31 19:41:05,372] ERROR:web-services:[18]: File "/home/deven/workspace/server/bin/service/web_services.py", line 687, in go
[2009-08-31 19:41:05,372] ERROR:web-services:[19]: (result, format) = obj.create(cr, uid, ids, datas, context)
[2009-08-31 19:41:05,372] ERROR:web-services:[20]: File "/home/deven/workspace/server/bin/report/report_sxw.py", line 364, in create
[2009-08-31 19:41:05,372] ERROR:web-services:[21]: return fnct(cr, uid, ids, data, report_xml, context)
[2009-08-31 19:41:05,373] ERROR:web-services:[22]: File "/home/deven/workspace/server/bin/report/report_sxw.py", line 421, in create_source_pdf
[2009-08-31 19:41:05,373] ERROR:web-services:[23]: return self.create_single_pdf(cr, uid, ids, data, report_xml, context)
[2009-08-31 19:41:05,373] ERROR:web-services:[24]: File "/home/deven/workspace/server/bin/report/report_sxw.py", line 432, in create_single_pdf
[2009-08-31 19:41:05,373] ERROR:web-services:[25]: rml_parser.set_context(objs, data, ids, report_xml.report_type)
[2009-08-31 19:41:05,373] ERROR:web-services:[26]: File "/home/deven/workspace/server/bin/report/report_sxw.py", line 316, in set_context
[2009-08-31 19:41:05,373] ERROR:web-services:[27]: self.localcontext['data'] = data
[2009-08-31 19:41:05,373] ERROR:web-services:[28]: AttributeError: 'purchase_by_product' object has no attribute 'localcontext'
---------------------------------------------------------------------------------------------------------------------------

Can anyone please kindly help me to solve this error?
Waiting for the valuable reply.

Sincerely,
Deven

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
Jay Vora (Serpent Consulting Services)
Solved:
2009-10-13
Last query:
2009-10-13
Last reply:
2009-10-13

This question was originally filed as bug #421969.

Hello Deven,

I would like to request you that you must first follow the existing code/example available in the system.
This will speed up your work.

Your error seems coming due to you did not follow convention of openerp.

1. on the __init__.py, Add 'import report'
2. on the __init__.py of report, add the py file name of report.
3.Add py file where you will have this code.

class purchase_by_product(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(purchase_by_product, self).__init__(cr, uid, name, context)
        self.localcontext.update({
            'time': time,
           })
report_sxw.report_sxw('report.report.name','your opbject','addons/purchase/reportpath to rmll',parser=purchase_by_product)

Example will be at :
addons/purchase/report/request_quotation.py

Thank you.
Good Luck.

Deven Moga (erpsupport) said : #3

Hello Jay,

Appriciate your help. But i have already done the steps which you have told me then also i am getting below error now ,
---------------------------------------------------------------------------------------
Environment Information :
System : Linux-2.6.27-14-generic-i686-with-debian-lenny-sid
OS Name : posix
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid
Operating System Release : 2.6.27-14-generic
Operating System Version : #1 SMP Tue Aug 18 16:25:45 UTC 2009
Operating System Architecture : 32bit
Operating System Locale : en_IN.ISO8859-1
Python Version : 2.5.2
OpenERP-Client Version : 5.0.3
Last revision No. & ID : 984 <email address hidden>
Traceback (most recent call last):
  File "/home/deven/workspace/server/bin/service/web_services.py", line 687, in go
    (result, format) = obj.create(cr, uid, ids, datas, context)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 364, in create
    return fnct(cr, uid, ids, data, report_xml, context)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 421, in create_source_pdf
    return self.create_single_pdf(cr, uid, ids, data, report_xml, context)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 431, in create_single_pdf
    objs = self.getObjects(cr, uid, ids, context)
  File "/home/deven/workspace/server/bin/report/report_sxw.py", line 337, in getObjects
    return table_obj.browse(cr, uid, ids, list_class=browse_record_list, context=context, fields_process=_fields_process)
AttributeError: 'NoneType' object has no attribute 'browse'
-------------------------------------------------------------------------------------------------------

Here i am pasting my code,

main __init__.py file :
import arihant_stage1
import wizard
import report

report __init__.py file:
import purchase_by_product

purchase_by_product file:
import time
from report import report_sxw
from osv import osv
import pooler

class purchase_by_product(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(purchase_by_product, self).__init__(cr, uid, name, context)
        self.localcontext.update({
            'time': time,
            'user': self.pool.get('res.users').browse(cr, uid, uid, context)
           })
report_sxw.report_sxw('report.purchase.by.product','arihant_stage1.arihant_stage1','addons/arihant_stage1/report/purchase_by_product.rml',parser=purchase_by_product)

arihant_stage1_report.xml file:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

  <report auto="False"
   id="purchase_by_product_rep"
   menu="False" model="arihant_stage1.arihant_stage1"
   name="purchase.by.product.report"
   rml="arihant_stage1/report/purchase_by_product.rml"
   string="Purchase by Product"/>

 </data>
</openerp>

arihant_stage1_wizard.xml file:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

  <menuitem id="next_id_4c_1" name="Reports" parent="purchase.menu_purchase_root"/>

  <!-- For Purchase wise Product report -->
  <wizard id="wizard_purchase_by_product" menu="False" model="arihant_stage1" name="arihant_stage1.purchase.by.product.report" string="Purchase by Product"/>
  <menuitem icon="STOCK_PRINT" action="wizard_purchase_by_product" id="menu_purchase_by_product" parent="arihant_stage1.next_id_4c_1" type="wizard"/>

</data>
</openerp>

Please kindly review all the things and kindly provide solution for my error.
Waiting for your reply.
Thanks in advance.

Deven

Hello Deven,

report_sxw.report_sxw('report.purchase.by.product','arihant_stage1.arihant_stage1','addons/arihant_stage1/report/purchase_by_product.rml',parser=purchase_by_product)

First Arguement should be report.purchase.by.product.report.

Is the model name right ?

Rest is ok.

Thanks.

Deven Moga (erpsupport) said : #5

Thanks Jay,

I have given model name [arihant_stage1.arihant_stage1] based on my module name which is [arihant_stage1].

Is it ok?

Deven Moga (erpsupport) said : #6

Hello Jay,

Now giving me another error,
----------------------------------------------------------------------------------
Environment Information :
System : Linux-2.6.27-14-generic-i686-with-debian-lenny-sid
OS Name : posix
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid
Operating System Release : 2.6.27-14-generic
Operating System Version : #1 SMP Tue Aug 18 16:25:45 UTC 2009
Operating System Architecture : 32bit
Operating System Locale : en_IN.ISO8859-1
Python Version : 2.5.2
OpenERP-Client Version : 5.0.3
Last revision No. & ID : 984 <email address hidden>
Traceback (most recent call last):
  File "/home/deven/workspace/server/bin/service/web_services.py", line 686, in go
    obj = netsvc.LocalService('report.'+object)
  File "/home/deven/workspace/server/bin/netsvc.py", line 66, in __init__
    self._service = SERVICES[name]
KeyError: 'report.purchase.by.product'
-------------------------------------------------------------------------------------------

Hi,

Yes, the model name is ok.

report_sxw.report_sxw('report.purchase.by.product','arihant_stage1.arihant_stage1','addons/arihant_stage1/report/purchase_by_product.rml',parser=purchase_by_product)

First Argument should be 'report.purchase.by.product.report' (report.REPORTNAME)
Because, the name of report is name="purchase.by.product.report".
Did you change this?

Thank you.

Deven Moga (erpsupport) said : #8

Hello Jay,

Yes, i have changed it and because of that i am facing below error

----------------------------------------------------------------------------------
Environment Information :
System : Linux-2.6.27-14-generic-i686-with-debian-lenny-sid
OS Name : posix
Distributor ID: Ubuntu
Description: Ubuntu 8.10
Release: 8.10
Codename: intrepid
Operating System Release : 2.6.27-14-generic
Operating System Version : #1 SMP Tue Aug 18 16:25:45 UTC 2009
Operating System Architecture : 32bit
Operating System Locale : en_IN.ISO8859-1
Python Version : 2.5.2
OpenERP-Client Version : 5.0.3
Last revision No. & ID : 984 <email address hidden>
Traceback (most recent call last):
  File "/home/deven/workspace/server/bin/service/web_services.py", line 686, in go
    obj = netsvc.LocalService('report.'+object)
  File "/home/deven/workspace/server/bin/netsvc.py", line 66, in __init__
    self._service = SERVICES[name]
KeyError: 'report.purchase.by.product'
-------------------------------------------------------------------------------------------

Dear Deven,

Did you change the name of report from WIZARD?

If I recall correctly, you are calling report from wizard.

Thanks.

Deven Moga (erpsupport) said : #10

Hello jay,

Yes, i am calling report from wizard but i not getting your question "Did you change the name of report from WIZARD?".

Thanks.
Deven

I meant :

you should alter :

'result': {'type':'print', 'report':'purchase.by.product.report', 'state':'end'},

The name of the report(WITHOUT 'report.').

Thanks.

Husen Daudi (husendaudi) said : #12

Hello deven,
I told you twice that please check the names.
There is a mistake in name.
Code:
'report': {
            'actions': "",
            'result': {'type':'print', 'report':'purchase.by.product.report', 'state':'print'}
        }

Here 'report':'purchase.by.product.report' is the report name and you have defined 'report':'purchase.by.product'.

one more bug in your report tag
Code:
.
<report auto="False"
 id="purchase_by_product_rep"
 menu="False" model="arihant_stage1.arihant_stage1"
 name="purchase.by.product.report"
 rml="arihant_stage1/report/purchase_by_product.rml"
 string="Purchase by Product"/>

Here model="arihant_stage1.arihant_stage1"
but there is no model defined in your module called "arihant_stage1.arihant_stage1"

Please refer technical doc on doc.openerp.com for more technical details.
_________________
OpenERP=Easier, Adaptable, Affordable, Modular

Deven Moga (erpsupport) said : #13

Yes Jay,

i have done that. below is my wizard code.

class wizard_report(wizard.interface):
     states = {
        'init': {
            'actions': "",
           'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]}
        },

        'report': {
            'actions': "",
            'result': {'type':'print', 'report':'purchase.by.product.report', 'state':'report'}
        }
    }

wizard_report('arihant_stage1.purchase.by.product.report')

Deven Moga (erpsupport) said : #14

Hi jay,

I am waiting for your reply. Is anything there which you want to tell me?

Thanks..
Deven

Hi,

If the Names have proper synchro with wizard and report,there is no scope for this error to appear.

Can you check account/sale module to have perfect coding conventions?

Here can be the root of the problem:
In the class wizard_report, 'the 'report' has the wrong state.

Maliciously, it is causing recursive loop.

'state':'end' no 'state':'report'.

Thanks.

Hello Deven,

Would you please close this thread if satisfied?

Thank you.

Deven Moga (erpsupport) said : #17

Thanks Jay (Open ERP), that solved my question.