تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
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
مايو 23
3008
0
سبتمبر 19
3046
1
يناير 17
3849
1
مارس 15
4931
0
مارس 15
3188