有人知道在自定义报告中更改文档来源的方法吗?我需要从从我的模型继承的视图中加载数据集。列与模型相同,只是一个数据过滤器。
问问题
6937 次
3 回答
3
在 v11 中,报表模块与报表对象一起被移除。因此,您正面临此错误。您必须从依赖中删除报告,因为它是在基本模块中添加/合并的。你可以在这里查看。
您可以使用 report_action 方法调用您的报告,如下所示:
self.env.ref('your_report_name').report_action(self, data=data)
希望这将帮助您并解决您的问题。
于 2018-01-01T11:24:50.923 回答
1
奥多 11
不再需要使用odoo.report
库。它已被弃用。您可以使用 odoo.tools 安装:
from odoo.tools import report
正如这里所解释的
你可以像 Muhsin k 在他的回答中所说的那样发送数据
self.env.ref('your_report_name').report_action(self, data=data)
以前的 Odoo 版本
你有所有的文档在这里。无论如何,如果您想自定义可以在报告中使用的数据,您可以使用如下方法:
from odoo import api, models
class ParticularReport(models.AbstractModel):
_name = 'report.module.report_name'
@api.model
def render_html(self, docids, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('module.report_name')
custom_data = self.env['model.name'].get_data()
docargs = {
'doc_ids': docids,
'doc_model': report.model,
'docs': self,
'custom_data': custom_data,
}
return report_obj.render('module.report_name', docargs)
模型model.name
是您要获取信息的模型
继承 Qweb 模板
标签template
是某些视图的快捷方式。该inherit_id
属性也可以在这里使用。大多数报告都是用这种视图构建的:
<template id='report_invoice_document' inherit_id='account.report_invoice_document'>
<xpath expr="//p[@t-if='o.payment_term.note']" position="after">
<!-- You can use you data object here -->
</xpath>
</template>
于 2017-12-07T10:59:09.393 回答
0
被render_html
替换为函数get_report_values
:
@api.model
def get_report_values(self, docids, data=None):
docs = self.env['model.name'].browse(docids)
return {
'doc_ids': docids,
'doc_model': 'model.name',
'docs': docs,
'lines': self.some_func(docs),
'data': data,
}
于 2019-05-09T09:54:06.613 回答