如何在odoo中通过python代码生成的报告中显示公司徽标



我有一个报告,我想自定义它,在报告中添加公司徽标,问题是整个报告都是由代码生成的。我想在报告上打印公司标志,我可以打印表明其工作的公司名称,但有了标志,似乎由于路径问题,它似乎不起作用。这是我的代码,其中包含了我迄今为止所做工作的一个片段。

def get_pdf(self, options, minimal_layout=True):
if not config['test_enable']:
self = self.with_context(commit_assetsbundle=True)
base_url = self.env['ir.config_parameter'].sudo().get_param('report.url') or self.env['ir.config_parameter'].sudo().get_param('web.base.url')
rcontext = {
'mode': 'print',
'base_url': base_url,
'company': self.env.company,
}
body = self.env['ir.ui.view'].render_template(
"account_reports.print_template",
values=dict(rcontext),
)
body_html = self.with_context(print_mode=True).get_html(options)
logging.info(self.env.user.company_id.name)
logging.info(self.env.user.company_id.logo)
test = "<header>"
"<img style='width: 7.0cm; height: 1.8cm;' src='/web/binary/{}' alt='logo'/>"
"</header>".format(self.env.user.company_id.logo)
ttt = bytes(test, 'utf-8')

就像我说的,它显示公司的名称,但不显示徽标,即使徽标是在系统中设置的。

所以我修复了它,我记得odoo有一个image_data_url函数,它用来获取存储在数据库中的图像的路径并显示在qweb报告模板中,所以我在odoo.tools中检查并找到了该函数,我在我的模型中调用了这个函数,将公司标志作为参数传递给该函数,并在image src属性中调用它,所以它看起来像这个

from odoo import tools
test = "<header style='margin-left: 750px;'>"
"<img style='width: 7.0cm; height: 1.8cm;'" 
"src='{}' alt='logo'/>"
"</header>". 
format(tools.image_data_uri(self.env.user.company_id.logo))
ttt = bytes(test, 'utf-8')```

最新更新