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.

1

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

By
Bartosz Dmytrak
on 1/14/16, 6:07 PM 2,994 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

--Axel Mendoza--
10203
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

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

1 follower(s)

Stats

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