Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
8979 Vues

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
Ignorer
Auteur Meilleure réponse

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
Ignorer

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()"

Publications associées Réponses Vues Activité
2
mai 23
3051
0
sept. 19
3071
1
janv. 17
3893
1
mars 15
4993
0
mars 15
3220