How to change the context of an existing report?

I would like to add a value to the context of the sales report:

from import SaleReport

class MySaleReport(SaleReport):
    __name__ = 'sale.my_sale'

    def get_context(cls, records, data):
        context = super(MySaleReport, cls).get_context(records, data)
        context['totals'] = 'Test totals'
        return context

But I have the following error:

ImportError: cannot import name 'SaleReport' from '' (/xxx/xxx/trytond/trytond/modules/sale/

by looking more closely at the definition of the CompanyReport report I realize that in the __init__ I have:

from .company import CompanyReport

__all__ = ['register', 'CompanyReport']

Is this why I cannot import the SaleReport?
How to overload the context of a report?


You have to override the context of a class with the same name as the internal name of the report.

You should use as class name in order to extend the sale report.

Ok, i have corrected my classe name …

class MySaleReport(SaleReport):
    __name__ = ''

… but i still have the same error :frowning:

If the goal is to extend the existing report, you must not inherit from the class but register in the report pool just a class inheriting from PoolMeta. It is exactly the same as for the models.

@ced’s reply above is the right answer, but the reason for the error is because you are trying to import it from the package instead of the module.

Instead try:

from import SaleReport

obviously, thank you.

it works :slight_smile: a syntax error in the name of the module made me think that it was necessary to do differently … sorry for the noise

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.