Hi,
I want to generate a printout for the module timesheet**(the window Lines)** [timesheet/menu---->Lines],
and one of the fields that i want to display is the sum of the duration on the printout, I have called the duration of each line then i have applied the sum directly to those lines and Here is the code:
File "/site-packages/genshi/template/eval.py", line 160, in evaluate
return eval(self.code, _globals, {'__data__': data})
File "<string>", line 485, in <Expression 'format_duration(sum(line.duration), line.company.party.lang) if line.duration else " "'>
TypeError: 'datetime.timedelta' object is not iterable
```How i can solve that to reach the goal of displaying the sum of the duration, Thanks in advance.
But this time give me another error has no member named “duration”`:
genshi.template.eval.UndefinedError: <trytond.report.report.Report._get_records.<locals>.TranslateModel object at 0x7f40ab45b080> has no member named "duration"
Here is the code after the modification :
<table:table-cell table:style-name="Tabelle1.A3" table:number-columns-spanned="2" office:value-type="string">
<text:p text:style-name="P30">Summe:</text:p>
<text:p text:style-name="P31"><text:placeholder text:placeholder-type="text"><for each="line in timesheet.lines"></text:placeholder></text:p>
<text:p text:style-name="P31"><text:placeholder text:placeholder-type="text"><format_duration(sum(line.duration for line in records))></text:placeholder></text:p>
<text:p text:style-name="P31"><text:placeholder text:placeholder-type="text"></for></text:placeholder></text:p>
</table:table-cell>
and this is the method **get_context**
@classmethod
def get_context(cls, records, data):
pool = Pool()
TimesheetLine = pool.get('line.printable')
context = Transaction().context
report_context = super(TimesheetLineReport, cls).get_context(records, data)
report_context['timesheet'] = report_context['record']
report_context['format_duration'] = cls.format_duration
return report_context
There is no need to include a for loop in relatorio (because this will produce a single text for each line). THe for loop is done in the calculation of the expression, so relation will sum all the values and just print a single value.
The following code should print what you expect:
<table:table-cell table:style-name="Tabelle1.A3" table:number-columns-spanned="2" office:value-type="string">
<text:p text:style-name="P30">Summe:</text:p>
<text:p text:style-name="P31"><text:placeholder text:placeholder-type="text"><format_duration(sum(line.duration for line in timesheet.lines))></text:placeholder></text:p>
</table:table-cell>
Thanks again, but it seems now that it see the duration as an integer and not as a time
Here is the error displayed:
` File "<string>", line 480, in <Expression '__relatorio_guess_type(__relatorio_store_cache(140239495126792, format_duration(sum(line.duration for line in timesheet.lines))))'>
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta'`