如何将 CSS 文件添加到 Odoo 10 中的 qweb 报告?

How to add CSS file to qweb report in Odoo 10?

我想将自定义 css 文件添加到 qweb 报告模板。我尝试添加如下内容,但没有成功:

    <?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <report id="my_module.report_id" model="my_module.report_model" string="Some Model Report" report_type="qweb-pdf" name="my_module.report_name" file="my_module.report_name_file" menu="False"/>
        <template id="my_module_inherit_id" inherit_id="report.minimal_layout">
            <xpath expr="." position="inside">
                <link rel='stylesheet' href="/my_module/static/src/css/report_style.css"/>
            </xpath>
        </template>
        <template id="my_module.report_name">
            <t t-call="report.html_container">
                <t t-call="report.internal_layout">
                    <div class="page">
                        <style>
                        .test_class{color:blue;}
                        </style>
                        <!-- <div class="header">
                        </div> -->

                        <div class="body">
                            <h1 class="test_class" t-esc="test_variable['subVariable']"/>
                            <h1 class="test_class2" t-esc="test_variable['subVariable']"/>

                        </div>
                    </div>
                </t>
            </t>
        </template>
    </data>
</odoo>

分类为 div 的页面中定义的样式运行良好。但我也想添加 css 文件。我也尝试在下面继承 ID,但其中 none 有效:

report.minimal_layout
report.internal_layout
report.assets_common
web.assets_backend
report.style
report.external_layout

css 文件:

.test_class2{
    color: red;
}

css 文件路径:

/my_module/static/src/css/report_style.css

尽量不要将标签模板放入标签报告中:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
<template id="my_module_inherit_id" inherit_id="report.minimal_layout">
            <xpath expr="." position="inside">
                <link rel='stylesheet' href="/my_module/static/src/css/report_style.css"/>
            </xpath>
        </template>
        <report id="my_module.report_id" model="my_module.report_model" string="Some Model Report" report_type="qweb-pdf" name="my_module.report_name" file="my_module.report_name_file" menu="False"/>
        <template id="my_module.report_name">
            <t t-call="report.html_container">
                <t t-call="report.internal_layout">
                    <div class="page">
                        <style>
                        .test_class{color:blue;}
                        </style>
                        <!-- <div class="header">
                        </div> -->

                        <div class="body">
                            <h1 class="test_class" t-esc="test_variable['subVariable']"/>
                            <h1 class="test_class2" t-esc="test_variable['subVariable']"/>

                        </div>
                    </div>
                </t>
            </t>
        </template>
    </data>
</odoo>

按照以下步骤: https://www.surekhatech.com/blog/apply-css-from-external-file-in-odoo-qweb-reports

谢谢

我解决了这个问题:

<template id="report_style_inherit" inherit_id="report.internal_layout">
            <xpath expr="." position="inside">

                <link href="http://127.0.0.1:8069/module_name/static/src/css/libs/custom.css" rel="stylesheet" />

            </xpath>
        </template>

使用 "report.internal_layout" 作为 inherit_id 并将 odoo 服务器 link 添加到 css 路径解决了我的问题。