Odoo Help


How to call python function from QWeb

Shawn Varghese
on 2/3/15, 2:16 AM 8,841 views

How do I call a python function from QWeb. In my custom module, I have inherited the purchase order template, and have the following function call:

<span t-esc="call_function1(o.amount_total)" />

The function is defined in a python file in the same module.

However I get an error saying:

QWebException: ""'NoneType' object is not callable" while evaluating 'call_function1(o.amount_total)'" while evaluating "translate_doc(doc_id, doc_model, 'partner_id.lang', 'purchase.report_purchaseorder_document')"

Does anyone have an idea as to what I am doing wrong?

On 2/3/15, 3:47 AM

You have to create your own report parser like this (see method currency_text):

<span t-if="o.currency_id" t-esc="currency_text(o.amount_total, o.currency_id.name, o.partner_id.lang or 'pl_PL')"/>

class report_invoice(models.AbstractModel):
    _name = 'report.account.report_invoice'
    _template = 'account__pl.report_invoice_pl'

    def currency_text(self, sum, currency, language):
        return currency_to_text(sum, currency, language)

    def render_html(self, data=None):
        report_obj = self.env['report']
        report = report_obj._get_report_from_name(self._template)        
        docargs = {
            'currency_text': self.currency_text,        
            'doc_ids': self._ids,
            'doc_model': report.model,
            'docs': self,

        return report_obj.render(self._template, docargs)

Thanks zbik. I will try this out and get back.

ePillars Systems LLC, Shawn Varghese
on 2/5/15, 4:20 AM
Sajin Aziz
On 2/3/15, 6:23 AM

if it is in the same model then you can use  <span t-esc="o.call_function1(o.amount_total)" />

Thanks Sajin. I am extending the quotation report, so the model is 'sale.order'. Does that mean that I have to define call_function1() inside 'class sale_order'?

ePillars Systems LLC, Shawn Varghese
on 2/5/15, 4:25 AM

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.


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

2 follower(s)


Asked: 2/3/15, 2:16 AM
Seen: 8841 times
Last updated: 3/16/15, 8:10 AM