ODOO 11中qweb模板中math.ceil等python模块的使用

ODOO 11中qweb模板中math.ceil等python模块的使用,odoo,Odoo,错误:“非类型”对象没有属性“ceil” 回溯(最近一次呼叫最后一次): 文件“/home/sachin/Documents/ODOO_11/sources/odoo11-1104/ODOO/addons/base/ir/ir_qweb/qweb.py”,第341行,在 返回已编译(self、append、new、options、log) 文件“”,第1行,在模板_336_8中 文件“”,第2行,在正文\u调用\u内容\u 7中 AttributeError:“非类型”对象没有属性“ceil”

错误:“非类型”对象没有属性“ceil” 回溯(最近一次呼叫最后一次): 文件“/home/sachin/Documents/ODOO_11/sources/odoo11-1104/ODOO/addons/base/ir/ir_qweb/qweb.py”,第341行,在 返回已编译(self、append、new、options、log) 文件“”,第1行,在模板_336_8中 文件“”,第2行,在正文\u调用\u内容\u 7中 AttributeError:“非类型”对象没有属性“ceil”

在编译AST时出现错误 AttributeError:“非类型”对象没有属性“ceil” 模板:336 路径:/templates/t/t/div/section[2]/t[2] 节点:

Odoo报告(用于html和pdf)实际上是渲染视图(键入QWeb)。此类视图的模型是
ir.ui.view
。您将在
base
模块中找到渲染方法。看

@api.multi
def render(self,values=None,engine='ir.qweb'):
断言isinstance(self.id,(int,long))
qcontext=dict(
env=self.env,
keep_query=keep_query,
request=request,#如果不在httprequest上下文中,则可能未绑定
debug=request.debug如果request else为False,
json=json,
quote_plus=werkzeug.url_quote_plus,
时间=时间,
datetime=datetime,
relativedelta=relativedelta,
xmlid=self.key,
)
qcontext.update(值或{})
返回self.env[engine].render(self.id,qcontext)
有趣的部分是
qcontext
,它使得在呈现QWeb模板时可以使用一些python库。所以只需继承/扩展model
ir.ui.view
并覆盖/extend
render()


编辑:我的例子是Odoo v10。

在qweb中不允许使用外部库函数,因为在使用之前必须在上下文中导入这些库。因此,您应该将这些值从控制器中计算出来,或者在这里写下qweb的逻辑,因为
ceil()
没有任何复杂的逻辑。

您是否使用它会给出错误“找到了非类型对象“math”,但ceil()不存在?@SachinBurnawal继承该fcntion添加您想要的函数,是正确的。@SachinBurnawal inherit thar函数add package what you want,您可以用xml调用它。
<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>