Odoo Help

1

How to add custom python function to QWeb report in odoo 9?

By
Bartosz Dmytrak
on 1/14/16, 6:07 PM 5,204 views

HI All

I’d like to add custom python function to be computed on my report, but I stuck with common known error:

"'NoneType' object is not callable" while evaluating 'testme()'

I’ve checked this forum and other tutorials and I can’t see any mistake in my code, but for sure there is one. Could you be so kind and point what I am doing wrong?

Files structure:

/__init__.py

/__openerp__.py

/controllers/__init__.py

/models/__init__.py

/report/__init__.py

/report/reports.xml

/report/sample_report.xml

/report/sample_report_document.xml

/raport/sample_report_parser.py

/demo/demo.xml

File Content:

/__init__.py

from . import controllers 
from . import models
import report

/__openerp__.py

{
'name': "bmbi_test",

'summary': """
Test""",

'description': """
Long description of module's purpose
""",

'author': "b",
'website': "",

'category': 'Uncategorized',
'version': '0.1',

  'data': [
'views/views.xml',
'views/templates.xml',
'report/sample_report.xml',
'report/sample_report_document.xml',
'report/reports.xml',
],

'demo': [
'demo.xml',
],
}

report/__init__.py

import sample_report_parser 

/report/reports.xml

 <?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<report
id="bmbi_sample"
model="account.invoice"
string="Test"
report_type="qweb-html"
name="bmbi_test.report_bmbi_sample"
file="bmbi_test.report_bmbi_sample"
attachment_use="False"
attachment="(object.state in ('open','paid')) and ('FV '+(object.number or '').replace('/','')+'.pdf')">
</report>
</data>
</odoo>

/report/sample_report.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_bmbi_sample" name="bmbi_test.report_bmbi_sample">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="bmbi_test.report_bmbi_sample_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>
</data>
</odoo>

/report/sample_report_document.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_bmbi_sample_document" name="bmbi_test.report_bmbi_sample_document">
<div class="page">
<div class="row">
<div>
<t t-esc="testme()"/>
</div>
</div>
</div>
</template>
</data>
</odoo>

/raport/sample_report_parser.py

from openerp.osv import osv
from openerp.report import report_sxw
import time

class sample_raport_parser (report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(bmbi_invoice_report_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'testme':self._testme
})

  def _testme(self):
return "ABC"

class bmbi_sample_report_parser(osv.AbstractModel):
_name = 'report.bmbi_test.report_bmbi_sample'
_inherit = 'report.abstract_report'
_template = 'bmbi_test.report_bmbi_sample'
_wrapped_report_class = sample_raport_parser


1
Axel Mendoza
On 1/21/16, 3:42 PM

See how to do it here:

https://www.odoo.com/fr_FR/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

thanks Axel, I read it earlier. I think my problem was related with indents. After code cleansing everything works fine - I'm quite new to odoo and python. Thanks for your post and help

Bartosz Dmytrak
on 1/21/16, 3:53 PM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/14/16, 6:07 PM
Seen: 5204 times
Last updated: 1/21/16, 3:53 PM