我想在自定义QWeb报告中从数据库中检索配置参数。
我该怎么办?
具体来说,我想得到等价物(在模型中):
self.env['ir.config_parameter'].get_param('my_param', '')
有人可以突出显示从哪里开始吗?
作为附加信息,我尝试使用的报告继承了report.minimal_layout:
<?xml version="1.0"?>
<odoo>
<data>
<template id="report_saleorder_css" inherit_id="report.minimal_layout">
<xpath expr="html/head/*[position() = last()]" position="after">
<style>
body {
color: <t t-esc="color"/>;
}
</style>
</xpath>
</template>
</data>
</odoo>
这是我尝试的自定义渲染功能:
class CustomReport(models.AbstractModel):
_name = 'report.mymodule.report_saleorder_css'
@api.model
def render_html(self, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('mymodule.report_saleorder_css')
docargs = {
'doc_ids': self._ids,
'doc_model': report.model,
'docs': self,
'color': 'red'
}
return report_obj.render('mymodule.report_saleorder_css', docargs)
没有成功
答案 0 :(得分:1)
简单来说,只要打印qweb报告,就要检索配置参数。
我们不能在qweb报告中直接使用self.env,但是我们可以调用一个执行该操作的函数并返回config参数值。为此,首先在模型中创建python函数。
@api.model
def get_system_para(self):
para_value = self.env['ir.config_parameter'].get_param('web.base.url','')
return para_value
现在在qweb报告中调用此函数
<span t-esc="docs.get_system_para()"/>
答案 1 :(得分:0)
您必须事先检索该值并将其传递给模板以供使用。
您可以为报告定义自己的解析器,然后查看documentation。
请参阅自定义报告,了解如何创建自己的解析器(Python类)以及如何使用docargs。基本上在render_html
方法中搜索您的值,将其插入docargs,然后将其传递给render
方法。然后您可以在模板中使用它,例如:
<t t-esc="my_param" />