Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
7070 Weergaven

Hello

I want to make a simple call function from rml but does not work. could anyone help me please...

this is my .py file:

import time

from openerp.report import report_sxw

class sellsheet(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context=None):
        super(sellsheet, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
            'test': self._testfunc,
            'foo' : "this is test",
        })
    def _testfunc(self):
        return "this the test text."

report_sxw.report_sxw('report.product.sellsheet', 'product.product', 'addons/product_extensions/report/product_sellsheet.rml', parser=sellsheet, header=False)

and here is the rml file:

<drawString x="110" y="-251">[[ test() ]]</drawString>

here is my __init__.py of report:

import product_sellsheet

and here is my __init__.py of module:

import product_extensions
import report

and it's show error in log:

openerp.tools.safe_eval: Cannot eval 'test()'
Traceback (most recent call last):
  File "/opt/openerp/server/openerp/tools/safe_eval.py", line 241, in safe_eval
    return eval(test_expr(expr, _SAFE_OPCODES, mode=mode), globals_dict, locals_dict)
  File "", line 1, in <module>
NameError: name 'test' is not defined

I have tested my .py file is called. but I'm not sure my __init__() function will execute or not. but I guest not. and I think this is the problem.

Avatar
Annuleer

Your code looks good. Seems that somehow your parser is not called. I would debug it and check whether your __init__() function is executed.

Auteur

Hello Andreas, I think my __init__() have never been call! , so what can I do to fix that?

You can check whether the report 'report.product.sellsheet' exists more that once in the addons path.

Auteur

Thanks you Andreas, But where can i check that? in the database or in the files.

Beste antwoord

Make sure your report py file is imported in __init__.py file.

Avatar
Annuleer
Auteur

Hello Sudhir, I can't see anything wrong with my __init__.py file.

Auteur

Thank you Sudhir, I have tested my .py file is called. but I'm not sure my __init__() function will execute or not. but I guest not. and I think this is the problem. do you have any idea about this?

Auteur Beste antwoord

I've found the solution. and It's worked. by declare the sellsheet class.

class sellsheet(osv.osv):
    _name='sellsheet'
    print "sellsheet_class"    
sellsheet()
Avatar
Annuleer

So if i want 2 function do i need to code 2 different classes and on which place should i code?