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.

0

call function in report

By
voathnak lim
on 9/12/13, 7:49 AM 2,452 views

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.

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

Andreas Brueckl
on 9/13/13, 8:23 AM

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

voathnak lim
on 9/15/13, 11:31 PM

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

Andreas Brueckl
on 9/16/13, 5:24 AM

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

voathnak lim
on 9/16/13, 10:32 PM
0
voathnak lim
On 9/18/13, 1:51 AM

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

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

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

Amit Patel
on 12/9/13, 4:02 PM
0

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 9/14/13, 6:10 PM

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

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

voathnak lim
on 9/15/13, 10:47 PM

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?

voathnak lim
on 9/15/13, 11:56 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: 9/12/13, 7:49 AM
Seen: 2452 times
Last updated: 3/16/15, 8:10 AM