How to dump variables and fields in a report

I need to see what data can I use to compose a report. How can I insert the proper code in a .FODT document to use it and present a complete structure of usable data?

For example in a sale:
<FOR EACH=“sale in records”>… dump all object hierachy with named data., including lines, possible relations, etc.</FOR>

There is no such things. And it is probably not possible to do it as it will probably generate infinite loop as data are mainly all interleaved.
See Where can I find a database relations map? to know available fields.

records here is the default value from model that you selected for print.
You may read more for “def get_context” to understand the how to passing value to report.
Reports

And below is how to create the custom report:
Creating custom report

1 Like

Thank you Markus; where do I need to insert that InvoiceReport() example class from “Passing custom data to a report” chapter?

I want to do something like Zoredache proposes at https://stackoverflow.com/questions/383944/what-is-a-python-equivalent-of-phps-var-dump
But how can I insert that many python code with fields (?) in an .FODT document?

you may need to create a class to inherit from “Report” (from trytond.report import Report)
Example:
Invoice Report

Then you may passing any parameter to override method “get_context”
Example:
get_context

Then to declare the report using xml: Invoice xml
<field name="report_name">account.invoice</field>
the report_name is the model you declare in your class.
PS. the model can be any name you named it.

then register to init.py
init.py

Above steps are for new report.

If you just want to put extra parameter for existing InvoiceReport. Then below code might help by not tested:

invoice_update.py

from trytond.modules.account_invoice import InvoiceReport
__all__ = ['UpdateExisintInvoice']

class UpdateExisintInvoice(InvoiceReport):
     __name__ = 'module.invoice_report'
    @classmethod
    def get_context(cls, records, data):
        context = super().get_context(records, data):
        context['anyParam'] = 'TEST PARAM'
        return context

deactivate existing invoicereport and using new:

<record model="ir.action.report" id="account_invoice.report_invoice">
  <field name="active" eval="False"/>
</record>
<record model="ir.action.report" id="report_invoice">
  <field name="name">Invoice</field>
  <field name="report_name">module.invoice_report</field>
  <field name="model">account.invoice</field>
  <field name="report">my_module/invoice.odt</field>
  <field name="template_extension">odt</field>
</record>
<record model="ir.action.keyword" id="report_invoice_update_keyword">
    <field name="keyword">form_print</field>
    <field name="model">account.invoice,-1</field>
    <field name="action" ref="report_invoice"/>
</record>

register to init:

from .invoice_update import UpdateExisintInvoice

Pool.register(
        UpdateExisintInvoice,
        module='my_module', type_='report')
2 Likes