2cadz
(Christophe)
October 5, 2020, 7:45am
1
I would like to add a value to the context of the sales report:
[...]
from trytond.modules.sale import SaleReport
class MySaleReport(SaleReport):
__name__ = 'sale.my_sale'
@classmethod
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 'trytond.modules.sale' (/xxx/xxx/trytond/trytond/modules/sale/__init__.py)
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?
Regards
pokoli
(Sergi Almacellas Abellana)
October 5, 2020, 8:03am
2
You have to override the context of a class with the same name as the internal name of the report.
You should use sale.sale
as class name in order to extend the sale report.
2cadz
(Christophe)
October 5, 2020, 8:23am
3
Ok, i have corrected my classe name …
class MySaleReport(SaleReport):
__name__ = 'sale.sale'
… but i still have the same error
ced
(Cédric Krier)
October 5, 2020, 8:29am
4
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.
dave
(David Harper)
October 5, 2020, 8:31am
5
@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 trytond.modules.sale.sale import SaleReport
2cadz
(Christophe)
October 5, 2020, 9:44am
7
it works 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
system
(system)
Closed
November 4, 2020, 9:44am
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.