【问题标题】:How to inherit and customize controller in Odoo V12如何在 Odoo V12 中继承和自定义控制器
【发布时间】:2023-03-19 15:03:01
【问题描述】:

我正在尝试继承 Odoo Web 控制器以添加新参数以在视图中使用它,但我无法做到。

这是渲染视图需要继承的类的方法:

class CustomerPortal(Controller):
@route(['/my', '/my/home'], type='http', auth="user", website=True)
    def home(self, **kw):
        values = self._prepare_portal_layout_values()
        return request.render("portal.portal_my_home", values)

这是我需要添加自定义字段的视图:

所以这是我的尝试,我没有错误,但也没有任何反应。 我尝试过的控制器(我也尝试将声明 @route 作为 @route() ):

class websiteContact(CustomerPortal):
    @http.route('/my/home', type='http', auth="user", website=True)
    def home(self): 
        response = super(websiteContact, self).home() 
        if self.env.user.id != SUPERUSER_ID:
            response['isAdmin'] = False 
        else:
            response['isAdmin'] = True
        return response

我尝试过的观点:

//视图portal.portal_contact被视图portal.portal_my_home调用

<template id="website_contact_template" inherit_id="portal.portal_contact">
    <xpath expr="//div[@class='o_portal_contact_details mb-5']" position="inside">
            <t t-esc="isAdmin"/>
    </xpath>
    </template>

有人知道如何继承一个控制器,添加一个新字段并在视图中显示它吗? 感谢阅读!

【问题讨论】:

    标签: python xml odoo odoo-12


    【解决方案1】:

    Controller添加你的自定义逻辑在这个方法_prepare_portal_layout_values

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多