Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Where to add a python function so that is callable by a RML report template?

By
Velko Hristov
on 6/19/13, 7:51 AM 3,270 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!

3
Velko Hristov
On 6/19/13, 2:27 PM

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>

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/

voathnak lim
on 9/16/13, 10:28 PM

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

Amit Patel
on 12/9/13, 3:59 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 6/19/13, 7:51 AM
Seen: 3270 times
Last updated: 3/16/15, 8:10 AM