Odoo网站首页添加一个ICP备案号

效果图:

odoo_icp1.png

新建文件:models/res_company.py

# -*- coding: utf-8 -*-
from odoo import fields, models

class ResCompany(models.Model):
    _inherit = 'res.company'

    icp_beian = fields.Char(string="ICP备案号")

然后在models/ __init__.py中引入该文件

xml代码: views/res_company.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="view_company_form" model="ir.ui.view">
        <field name="name">res.company.form</field>
        <field name="model">res.company</field>
        <field name="inherit_id" ref="base.view_company_form"/>
        <field name="arch" type="xml">
            <xpath expr="//field[@name='currency_id']" position="after">
                <field name="icp_beian"/>
            </xpath>
        </field>
    </record>
</odoo>

新建一个website_templates模板文件:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id="icp_beian" name="ICP Template">
        <t t-if="res_company.icp_beian">
            <span>
                <a href='http://www.beian.miit.gov.cn/' target='_blank'>
                    <span><t t-esc="res_company.icp_beian"/></span>
                </a>
            </span>
        </t>
    </template>

    <template id="layout" name="Main layout" inherit_id="portal.frontend_layout">
        <xpath expr="//div[hasclass('o_footer_copyright')]//span[@t-field='res_company.name']" position="after">
            <t t-call="cdszxy_icp_web.icp_beian"/><!--注意这里的cdszxy_icp_web替换为你的模块名-->
        </xpath>
    </template>
</odoo>

编辑模块下的__manifest__.py文件引入views中这两个xml文件

重启odoo,安装或升级模块

完成后,到设置--->公司中填写公司的ICP备案号,最后进入网站首页查看效果。

odoo_icp2.png

完整模块代码: 点击下载

Last modification:March 12th, 2020 at 01:12 pm
If you think my article is useful to you, please feel free to appreciate