odoo - 生成html并在qweb中渲染

标签 odoo odoo-10 odoo-9

是否可以在 .py 文件中生成 html 并在 qweb 中呈现?

<openerp>
    <data>
        <record id="paperformat_time" model="report.paperformat">
            <field name="name">Time</field>
            <field name="font_size">10</field>
        </record>

        <report id="time_qweb" model="hr_timesheet_sheet.sheet" string="Time" 
        report_type="qweb-pdf" name="time.report_time" file="time.report_time" />

        <record id="time_qweb" model="ir.actions.report.xml">
            <field name="paperformat_id" ref="time.paperformat_time" />
        </record>
      </data>
</openerp>

qweb    

<template id="report_time">
    <t t-call="report.html_container">
        <t t-foreach="docs" t-as="t">
            <span t-esc="t.__compute_html()" />
            <div class="page">
                <span t-field="t.html_text " />
            </div>
        </t>
    </t>
</template>

.py文件

class Time(models.Model):

   _inherit = 'hr_timesheet_sheet.sheet'

   html_text = fields.Html(string = 'Html')

   @api.one
   def _compute_html(self):
        html_value = "<h1>TEST</h1>" 
        html_value += "<h1>TEST 2</h1>"

        self.html_text = html_value

例如。

html_value = "<h1> + employee_id.name + "</h1>" 
html_value += "<h1> + employee_id.phone + "</h1>"

现在我需要在 qweb 中呈现 html_value 并放入 <div class="page"> put here html_value </div>

现在我将文本保存在数据库中,有更好的解决方案吗?................................................

最佳答案

是的,如果你有一个包含 html 代码的变量,如果你使用 t-esct-field odoo 会将其打印为文本。

如果你想渲染它使用。 t-raw

  <div t-raw="doc.some_attribute" > </div>

或者

   <t t-raw="doc.some_attribute" > </t>

关于odoo - 生成html并在qweb中渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50750410/

相关文章:

odoo - Odoo 10(Windows+Eclipse IDE)中的配置文件在哪里?

python - Openerp : onChange event to create lines on account move

Odoo 标题按钮上的 JavaScript 事件

python - def 在odoo 10、python 中创建带有many2one 字段的函数

Odoo-隐藏多个组的字段或对多个组可见

python - 如何与 Odoo 9 一起运行 Odoo 8?

odoo - 在odoo配置文件中设置和获取默认值

odoo - 如何在odoo网站上上传图片?

python - 字段未显示在 product.template odoo8 中

python - 使用服务器操作运行 python 代码时出错