【问题标题】:How to add CSS file to qweb report in Odoo 10?如何在 Odoo 10 中将 CSS 文件添加到 qweb 报告?
【发布时间】:2019-07-04 08:08:37
【问题描述】:

我想将自定义 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,但它们都不起作用:

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

【问题讨论】:

  • &lt;h1 style="color: red;" t-esc="test_variable['subVariable']"/&gt; 怎么样。它在ir.ui.view 中用于表单视图
  • 是的,在 qweb 中使用样式是可行的,但我的 css 文件只是一个示例,我想在 qweb 报告中添加 css 文件。
  • 您在__manifest__.py 中添加了'css': ['static/src/css/report_style.css',], 吗?
  • 是的,我添加它并再次尝试但仍然相同(我在清单文件中定义 report_template.xml 之前定义了 css 行)

标签: css report odoo qweb


【解决方案1】:

我解决了这个问题:

<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服务器链接添加到css路径解决了我的问题。

【讨论】:

    【解决方案2】:

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

    <?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

    谢谢

    【讨论】:

    • report 标签是关闭的,里面没有任何模板标签。如果您的意思是在报告之前定义 css 文件,我也尝试过,但没有任何改变
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多