Добавить пользовательский парсер для отчета QWeb

Я попытался создать собственный синтаксический анализатор для моего отчета qweb на основе некоторых руководств в Интернете:

ig_account_object_printout_report_parser.py

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

class ig_account_object_printout_report_parser(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context): 
    super(ig_account_object_printout_report_parser, self).__init__(cr, uid, name, context=context)
    self.localcontext.update({
        'time': time,
        'hello_world': self._hello_world,
    })

    def _hello_world(self, field):
        return "Hello World!"

class ig_account_object_report(osv.AbstractModel):
    _name = 'ig_account.ig_account_object_printout_report_template'
    _inherit = 'report.abstract_report'
    _template = 'ig_account.ig_account_object_printout_report_template'
    _wrapped_report_class = ig_account_object_printout_report_parser

ig_account_object_printout_report.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <report 
            id="ig_account_object_printout"
            model="ig.account.object"
            string="Print Account Object"
            report_type="qweb-pdf"
            name="ig_account.ig_account_object_printout_report_template"
            attachment_use="False"
            file="ig_account.ig_account_object_printout_report_template"
        />
    </data>
</openerp>

ig_account_object_printout_report_template.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data> 
<template id="ig_account_object_printout_report_template">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="o">
            <div class="page">                   
                <span t-esc="hello_world()"/>
            </div>
        </t>
    </t>
</template>
</data>
</openerp>

Мне нужен собственный парсер, потому что без него я не смогу вызвать функцию python для обработки некоторых данных.

Но когда я попытался запустить отчет, он возвращает:

QWebException: "'NoneType' object is not callable" while evaluating
'hello_world()'

Я включил ig_account_object_printout_report_parser.py в __init__.py

Я что-то упускаю?


person William Wino    schedule 22.05.2015    source источник


Ответы (1)


Проверяйте аргумент метода при вызове метода в Qweb View.

def _hello_world(self, field):
    return "Hello World!"

приведенная выше функция использует некоторый аргумент в качестве поля, но вы можете попробовать вызвать эту функцию примерно так.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data> 
<template id="ig_account_object_printout_report_template">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="o">
            <div class="page">                   
                <span t-esc="hello_world(o.some_field_name)"/>
            </div>
        </t>
    </t>
</template>
</data>
</openerp>

вы можете проверить с помощью обновления вашего модуля и попытаться снова распечатать отчет

Я надеюсь, что это должно быть полезно для вас ..:)

person DASADIYA CHAITANYA    schedule 22.05.2015
comment
Боже мой, я не могу поверить, что пропустил это!! Благодарю вас! Что, черт возьми, не так с сообщением об ошибке, оно настолько вводит в заблуждение! - person William Wino; 22.05.2015