콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
7 답글
38353 화면

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?

아바타
취소
베스트 답변

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'?

베스트 답변

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.

Hi,

Can someone tell me what does t-if="o.currency_id" do in the above code and also the def currency_text is returning some values so where and how is the above code receiving them in QWEB report for a later access?

관련 게시물 답글 화면 활동
0
12월 15
4279
1
3월 15
14355
0
3월 15
3411
3
3월 15
17831
Inherit Qweb 해결 완료
4
2월 24
48112