跳至內容
選單
此問題已被標幟
1 回覆
8929 瀏覽次數

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!

頭像
捨棄
作者 最佳答案

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/

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

相關帖文 回覆 瀏覽次數 活動
2
5月 23
3008
0
9月 19
3046
1
1月 17
3849
1
3月 15
4931
0
3月 15
3188