首页 文章

如何在Qweb中的Odoo 11中自定义报告?如何将数据从其他模型发送到qweb报告?

提问于
浏览
2

有人知道在自定义报告中更改文档来源的方法吗?我需要从继承自我的模型的视图中加载数据集 . 列与模型相同,它只是一个数据过滤器 .

2 回答

  • 2

    在v11中,报告模块已与报告对象一起删除 . 因此,您将面临此错误 . 您必须从依赖中删除报告,因为它是在基本模块中添加/合并的 . 你可以在这里查看 .

    您可以使用report_action方法调用报告,如下所示:

    self.env.ref('your_report_name').report_action(self, data=data)
    

    希望这会帮助您解决您的问题 .

  • 1

    Odoo 11

    无需再使用 odoo.report 库 . 它已被弃用 . 你可以使用odoo.tools:

    from odoo.tools import report
    

    正如解释here

    你可以发送数据,就像Muhsin k在his answer中所说的那样

    self.env.ref('your_report_name').report_action(self, data=data)
    

    以前的Odoo版本

    你有所有的文件here . 无论如何,如果你想自定义可以在报告中使用的数据,你可以使用这样的方法:

    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>
    

相关问题