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

How to call python function from QWeb

By
Shawn Varghese
on 2/3/15, 2:16 AM 6,492 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?

2

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
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)

    @api.multi
    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.

Shawn Varghese
on 2/5/15, 4:20 AM
1
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'?

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

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

2 follower(s)

Stats

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