0

My report file contains

class AccountInvoice_Report(report_sxw.rml_parse):

    def __init__(self, cr, uid, name, context):

        super(AccountInvoice_Report, self).__init__(cr, uid, name, context=context)

        self.localcontext.update({

        'time': time,
        'cr':cr,
        'uid': uid,
        'get_address': self.get_address,
    })

and I have written get_address function. when i call that function in my mako file as

    <% get_address() %>

Then it gives Error as

   File "memory:0xb23c67ccL", line 208, in render_body
   <% get_address()%>
   TypeError: 'Undefined' object is not callable

What mistake I am doing file defining or calling the function.

New_User123
  • 104
  • 11

4 Answers4

0

my_parser.py

import time
from openerp.report import report_sxw

class AccountInvoice_Report(report_sxw.rml_parse):

    def __init__(self, cr, uid, name, context):
        super(AccountInvoice_Report, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
                                  'time': time,
                                  'cr':cr,
                                  'uid': uid,
                                  'get_address': self.get_address,})
    def get_address(self):
        #your code
        return 'address'

report_sxw.report_sxw('report.your_report_name', 'model', 'path/to/mako', parser=AccountInvoice_Report)

Include this parser in __init__.py

import my_parser

also don't forget to import your report folder in main __init__.py

sajadkk
  • 764
  • 1
  • 5
  • 19
  • That's the basic thing. I have included it. If I haven't then Error will be different. Please check the Error. – New_User123 Feb 21 '14 at 05:50
  • 1
    the error will be same if you don't import the folder.I faced same issue before as i forgot to include it. Did you check your custom parser is getting called, put a breakpoint and check. – sajadkk Feb 21 '14 at 06:25
  • AccountInvoice_Report is your parser class, did you write something like this? `report_sxw.report_sxw('report.your_report_name', 'model', 'path/to/mako', parser=AccountInvoice_Report)` – sajadkk Feb 21 '14 at 11:53
  • i mean check whether your parser class is being called, can you access cr,time,uid from your mako? – sajadkk Feb 21 '14 at 13:08
0

Also try to restart your IDE/server. It works for me. Sometimes you can have many instances running the same time.

levolutionniste
  • 424
  • 1
  • 6
  • 16
0

On:

report_sxw.report_sxw('report.your_report_name', 'model', 'path/to/mako', parser=AccountInvoice_Report)

You should ensure your 'your_report_name' is identical to the field 'report_name' on the model 'ir.actions.report.xml' (where you configure your report).

The function report_sxw.report_sxw() can't find the 'report_name' of the report to link the parser.

Shide
  • 71
  • 4
0

It's an old question but maybe someone can make use of this. I have used the approach you are trying to do, and the following code worked for me on 6.0: On your init instead of

'get_address': self.get_address,})

I used:

'get_address': self.get_address(),})

Then I declared my method as:

def get_address(self):

Finally on my mako i called it with:

${get_address}

Note that on the mako file I'm not using 'get_address()' because it sent me an error saying that the string get_address is not a callable object. Hope it helps.

KyonHS
  • 11
  • 2