I create a report using 2 parent-child models:
- UserTimesheet
- UserTimesheetRecord
UserTimesheetRecord has a field Many2One to a model called Project
In database UserTimesheetRecord table is like below, in which the column ‘project’ holds the ID of a project record in project table:
And below is Project data in DB:
based on opportunity tutorial, to renders party module field value, all you need to do is calling it from field placeholder at FODT file like this: opportunity.party.rec_name.
So at FODT or FODS template, I try to renders Project’s name (should be derives from Project table, with field placeholder: record.project.proj_name (at FODT) or relatorio://record.project.proj_name (at FODS).
But both throws error says:
File "/genshi/template/eval.py", line 397, in undefined
raise UndefinedError(key, owner=owner)
genshi.template.eval.UndefinedError: None has no member named "proj_name"
I am not stopping there. So I read in the API Ref Doc that you can load a desired module into the context at Report class, and I tried, but it seems cannot works. My code is below.
class UserTimesheetReport(Report):
"User Timesheet Report"
__name__ = 'user.timesheet.report'
@classmethod
def get_context(cls, records, header, data):
logger.warning(">>>>>>>> PROCESSING GET CONTEXT <<<<<<<")
pool = Pool()
Project = pool.get('afx.project')
context = super().get_context(records, header, data)
project_id = Transaction().context.get('project')
project = Project(project_id) if project_id else None
context['project'] = project
return context
I click PRINT button, and I was hoping I can see the LOG Message in the console, but that also not happened (I already have a custom logging config file and executed when I start trytond).
My questions:
- Is there any link sample to do this that explains the proper way to use get_context method or any other workable solution that enable me to render the correct project name?
- Is there anyway I can print my logging message to console from overridden method?
Any advice would be very helpful to me
Regards
Bromo