TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta'

I have an issue and am stuck on ,

For the first time I want to display the sum of durations of the lines (from the timesheet lines) in a printout report.

and i have made this method for the format of the duration:

    def format_duration(cls, duration , lang, digits=2, grouping=True,
        pool = Pool()
        Lang = pool.get('ir.lang')
        total_seconds = duration.total_seconds()
        hours = total_seconds // 3600
        minutes = (total_seconds % 3600) // 60
        duration_hours = hours + minutes / 60
        duration_days = duration_hours / 8
        if lang is None:
            lang = Lang.get()
        return lang.format('%.' + str(digits) + 'f',
            duration_days, grouping=grouping, monetary=monetary)

and here it’s the XML code:

      <text:p text:style-name="P31"><text:placeholder text:placeholder-type="text">&lt;format_duration(sum(line.duration for line in timesheet.lines))&gt;</text:placeholder></text:p>

when i have tried to print it , an error was displayed:

          File "<string>", line 480, in <Expression '__relatorio_guess_type(__relatorio_store_cache(140377602530056, format_duration(sum(line.duration for line in timesheet.lines))))'>
TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta'

How i can solve it am stuck on.

Thanks in advance.

Python sum uses 0 as default start. So you have to use a compatible start type when summing timedelta like:
sum((line.duration for line in timesheet.lines), start=datetime.timedelta())

1 Like