2
votes
<xpath expr="//*[@id='wrap']/section[2]/div" position="replace">
    <t t-set="Math" t-value="math"/>
    <t t-foreach="range(0, Math.ceil(number_of_device_issue/2))" t-as="num">
    <t t-esc="num"/>
</t>

Error : 'NoneType' object has no attribute 'ceil' Traceback (most recent call last): File "/home/sachin/Documents/ODOO_11/sources/odoo11-1104/odoo/addons/base/ir/ir_qweb/qweb.py", line 341, in _compiled_fn return compiled(self, append, new, options, log) File "", line 1, in template_336_8 File "", line 2, in body_call_content_7 AttributeError: 'NoneType' object has no attribute 'ceil'

Error to render compiling AST AttributeError: 'NoneType' object has no attribute 'ceil' Template: 336 Path: /templates/t/t/div/section[2]/t[2] Node: <t t-foreach="range(0, Math.ceil(number_of_device_issue/2))" t-as="num"> <t t-esc="num"/> </t>

2
did you use <span t-esc="math.ceil(field)"/> - Lakshminarayanan
it gives error "Nonetype object 'math' is found" - Sachin Burnawal

2 Answers

1
votes

Odoo Reports (for html and pdf) are actually rendered views (type QWeb). The model of such views is ir.ui.view. You will find the render method in the base module. Look here

@api.multi
def render(self, values=None, engine='ir.qweb'):
    assert isinstance(self.id, (int, long))

    qcontext = dict(
        env=self.env,
        keep_query=keep_query,
        request=request, # might be unbound if we're not in an httprequest context
        debug=request.debug if request else False,
        json=json,
        quote_plus=werkzeug.url_quote_plus,
        time=time,
        datetime=datetime,
        relativedelta=relativedelta,
        xmlid=self.key,
    )
    qcontext.update(values or {})

    return self.env[engine].render(self.id, qcontext)

The interesting part is the qcontext which makes it possible to use some python libs while rendering QWeb templates. So just inherit/extend model ir.ui.view and override/extend render().

Edit: My example is for Odoo v10.

1
votes

Using External lib functions are not allowed in qweb as you have to import these libs in the context before use. So You should bring these values evaluated form controller or write down the logic here is qweb as ceil() does not have any complicated logic.