Xml Odoo12中负责顶部导航栏的视图

Xml Odoo12中负责顶部导航栏的视图,xml,odoo,odoo-12,Xml,Odoo,Odoo 12,我试图在顶部导航栏中添加一个徽标,并寻找要继承的视图id,该id允许我使用xpath以propper元素为目标 我在定位负责包含两个相邻元素的导航栏布局的视图时遇到问题 我发现了类似这样的东西:addons\website\views\website\u navbar\u templates.xml。但它不定义这两个相邻节点(位于浏览器“检查图元”工具中): 及 这个标志在哪里?我在Odoo12中没有看到任何徽标。我认为没有名为“navbar brand”的类。我最终用我的自定义模块覆

我试图在顶部导航栏中添加一个徽标,并寻找要继承的视图id,该id允许我使用xpath以propper元素为目标

我在定位负责包含两个相邻元素的导航栏布局的视图时遇到问题

我发现了类似这样的东西:
addons\website\views\website\u navbar\u templates.xml
。但它不定义这两个相邻节点(位于浏览器“检查图元”工具中):



这个标志在哪里?我在Odoo12中没有看到任何徽标。我认为没有名为“navbar brand”的类。

我最终用我的自定义模块覆盖了静态xml文件,如下所示:


    我把这个文件放在
    static/src/xml
    中,并在manifest.py中调用它

    “qweb”:[
    'static/src/xml/*.xml',
    ],
    
    这也可以动态完成。在本例中,我们将在前端使用JavaScript代码,并使用控制器通知前端是否存在该公司的公司徽标,然后使用前端的get请求获取公司徽标

    首先,我们将img标记添加到XML中,以显示公司徽标

    <?xml version="1.0" encoding="UTF-8"?>
    <templates id="template" xml:space="preserve">
        <t t-extend="Menu">
            <t t-jquery=".o_menu_apps" t-operation="prepend">
                <a id="company-logo-link" href="/web">
                    <img id="company-logo" alt="Logo"/>
                </a>
            </t>
        </t>
    </templates>
    
    odoo.define('web_company_logo.Menu', function (require) {
    'use strict';
    
    var session = require('web.session');
    var Menu = require('web.Menu');
    
    Menu.include({
        /**
        * @override
        */
        start: function (parent, options) {
            this._super.apply(this, arguments);
    
            // current url, <domain_name>:<port_number>
            var url = window.location.origin;
    
            // company id from the session
            var companyId = session.company_id;
    
            // use ajax to check if the company has a logo.
            // if there is no logo, remove the anchor, else
            // use the company's logo as the img src
            $.ajax({
                type: 'GET',
                data: {'company_id': companyId},
                url: `${url}/check_company_logo`,
                success: function (result) {
                    console.log('Inside the success function');
                    var result = JSON.parse(result);
                    if (result.has_logo == true) {
                        $('#company-logo')[0].src = `${url}/web/image?model=res.company&id=${companyId}&field=logo`;
                    }
                    else {
                        $('#company-logo-link')[0].remove();
                    }
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    console.log('Error encountered');
                },
            });
        },
       });
    });
    
    import json
    
    from odoo import http
    from odoo.http import request
    
    
    class WebCompanyLogoController(http.Controller):
    
    @http.route(['/check_company_logo'], type='http',
                auth="public", methods=['GET'],
                website=True, sitemap=False)
    def check_company_logo(self, company_id=0):
        """
        Check if company has a logo
        :param company_id: ID of the company as an integer
        :return: bool
        """
        has_logo = bool(request.env['res.company'].browse(int(company_id)).logo)
    
        return json.dumps({
            'has_logo': has_logo,
        }, ensure_ascii=False)