This question has been flagged
1 Reply
7820 Views

I would like to extend the "Purchase Order" RML report with custom functionality. This module can be found at:

openerp\addons\purchase\report

and contains the python files:

__init__.py
order.py
purchase_report.py
request_quotation.py

I tried to add the simple function

def testme():
  return "testme"

to all of the above files and to call it from order.rml but the call failed under all circumstances. Then I tried to add a new dedicated file "testme.py" into this directory and import it into all of the above mentioned files. Still no luck.

Where am I supposed to add my little function so that it is "visible" to the report template order.rml?

Thanks in advance!

Avatar
Discard
Author Best Answer

I found the solution and I'm posting it here for the benefit of other poor souls who make their first steps with OpenERP.

One have to insert the function into the localcontext of the class definition. So if this is the original class definition:

class order(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(order, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({'time': time})

The new one shall look like this:

class order(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(order, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({'time': time, 'testme': self._testme})

def _testme(self):
  return "testme"

And the function can be used in the RML file like this:

<td>
  <para style="terp_default_9">[[ testme() ]]</para>
</td>
Avatar
Discard

Hello Velko, I also try that but it's seem like my __init__() function did not execute, do you have any idea? and here is my code http://help.openerp.com/question/30908/call-function-in-report/

In my case there is a same issue. It says "tools.safe_eval: Cannot eval - my_function()"