odoo[QWEB] 无法从模板调用方法

odoo[QWEB] can not call method from template

我尝试从模板调用模型方法并收到错误:

QWebException: "'NoneType' object has no attribute 'get_session_data'" while evaluating
'testmodule.get_session_data()'

模特有这样的看法:

class testmodule(models.Model):
    _name = 'testmodule'

    def get_session_data(self, cr, uid, ids, context=None):
        return u'READING'

安全设置:

access_testmodule,testmodule,model_testmodule,,1,1,1,1

Qweb 模板:

<t t-esc="testmodule.get_session_data()" /> 

我做错了什么?如果我尝试从网站模型调用方法,一切正常。我想使用我自己的 类 和他们的方法。我该怎么做?

更新: templates.xml:

<template id="website.user_navbar" inherit_id="website.layout" groups="base.group_user">
    <xpath expr="//body/div['id=wrawrap']" position="before">
        <div style="background-color: #000800; height:110px;color: red">
            | <t t-raw="website.is_user()" /> |<br />
            | <t t-esc="testmodule.get_session_data()" /> |
        </div>
    </xpath>
</template>

如果你查看方法 _prepare_qcontext (odoo/addons/website/models/ir_ui_view.py),你会看到变量 website 定义在那里,这就是调用 [=12 的原因=] 有效。所以我认为您可能需要覆盖 _prepare_qcontext 并将 testmodule 的实例添加到它的返回对象,这样您就可以从 xml 调用 get_session_data