Skip to Content
Menu
This question has been flagged
1 Reply
4312 Views

I have this code which inherits the function that passes the data to be shown in the report. I wanted to add a new "docs"  like so:

================

class MyCustomReport(models.AbstractModel):

    _inherit = 'report.my_addon.custom_report'


    def _get_report_values(self, docids, data=None):

​# here i get the original data first

        res = super(MyCustomReport, self)._get_report_values(docids, data)

        docs = res['docs']

        # i add my additional data

        dict_docs = {

            'my_add_on': self._my_function_to_get_the_data()

         }

​# i update the result

        res.update({

            'additional_docs': dict_docs

        })


        return res

======== ========

This returns:

{'doc_ids': [3], 'doc_model': 'account.move', 'docs': account.move(3,), 'qr_code_urls': {}, 'additional_docs': {'my_add_on': None}}


I tried adding it to my qweb .xml custom report. See code below for what i am currently working on. This custom_report_inherit_first_customis my first custom which works well since i am using the "docs" data.  This  custom_report_inherit_addon_second_custom returns an error because i can't pull the "additional_docs" data.


# inherit report invoice document > then add my customization

< # template id="second_custom_report_inherit" inherit_id="my_adodn.first_custom_report_inherit">

#  I tried logging what i have fetched

​< t t-esc="o"/> # this returns 'docs'

​< t t-esc="o_a"/> # this returns nothing and causes an error when i call the parameter i added, saying it does not exist

< # / template>


# i try to inherit the report_invoice to add my new parameter

< # / template id="report_invoice_inherit" inherit_id="account.report_invoice">

​# i inherit the xpath : < xpath expr="'web.html_container'" position="inside" >


and the do the for each like the account.report_invoice and then call the template

               t t-foreach="additional_docs" t-as="o_a"   

                    t t-call="my_addon.second_custom_report_inherit" 

               

[close tags for all]

 

               

[close tags for all]

            

               

               

[close tags for all]

 

 

(sorry for the format)

I'm not sure how to get the second data to show in the report. Please help



Avatar
Discard
Best Answer

Hi,

docs: records of the current model


doc_ids: list of ids for the current model


doc_model: current model record


Since the docs item provides the records for the current model, it is easy to access each field value inside the template. Thereby the Odoo report engine makes it easier to customize reports.

If you need to add your own data you can return it like this


def _get_report_values(self, docids, data=None):

​ # get the report action back as we will need its data

​ report = self.env['ir.actions.report']._get_report_from_name('module.report_name')

​ # get the records selected for this rendering of the report

​ obj = self.env[report.model].browse(docids)

​ # return a custom rendering context

​ return {

​ 'lines': docids.get_lines()

​ }


OR:


def _get_report_values(self, docids, data=None):

​ res = super(MyCustomReport, self)._get_report_values(docids, data)

​ docs = res['docs 

​ my_add_on = self._my_function_to_get_the_data()

​ res.update({

​ 'additional_docs': my_add_on

​ })

​ return res


Hope it helps



Avatar
Discard
Related Posts Replies Views Activity
0
Apr 24
1095
1
Sep 23
2554
4
Nov 24
6658
4
Jul 19
7745
0
Dec 18
3198