custom report through python odoo 9

后端 未结 2 2071
醉酒成梦
醉酒成梦 2021-01-14 16:22

How to pass multiple module data to a QWeb report? Is there something similar to passing dictionary in rendering html from controller?



        
2条回答
  •  借酒劲吻你
    2021-01-14 16:58

    Below is the code to create a custom Model report which is wrapped on v9 API. Creating custom object report is three step process

    1. Create RML Prase Custom Report Object
    2. Wrap RML Report to AbstractModel Report for qweb engine.
    3. Design template for the custom object.
    4. Register your under report registry.

    All Four Part listed here with possible sample code.

    RML Prase Custom Report Object

    import time
    from openerp.osv import osv
    from openerp.report import report_sxw
    
    
    class CustomReportPrint(report_sxw.rml_parse):
    
        def __init__(self, cr, uid, name, context):
            super(CustomReportPrint, self).__init__(cr, uid, name, context=context)
            self.localcontext.update({
                'time': time,
                'lst': self._lst,
                'total': self._some_total,
                'get_records':self._get_records,
            })
    
        def _get_records(self, res_ids):
            records = self.pool.get('res.partner').browse(self.cr, self.uid, res_ids)
            return records
    
        def _lst(self, employee_id, dt_from, dt_to, max, *args):
            #Your code goes here
            return res
    
        def _some_total(self, employee_id, dt_from, dt_to, max, *args):
            #Your code goes here
            return [result_dict]
    

    Wrapping RML Prase Object tot he QWeb Engine.

    class report_custom_print(osv.AbstractModel):
        _name = 'report..report_custom_print'
        _inherit = 'report.abstract_report'
        _template = '.report_custom_print'
        _wrapped_report_class = CustomReportPrint
    

    Report XML look as below as you can see I am calling get_records from custom report model.

    
    
        
            
        
    
    

    Registering Report

        
            Custom Print Report
            qweb-pdf
            res.partner
            .report_custom_print
            .report_custom_print
        
    

    In custom Rml report Object you can define as many functions as you like and register them under __int__ and you can call those function directly on yor rpeort and mutpllate data as you need.

    PS: replace with your module to make wit works correct.

    Hope this will help.

提交回复
热议问题