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

**URL:** <https://discuss.tryton.org/t/typeerror-unsupported-operand-type-s-for-int-and-datetime-timedelta/4966>\
**Category:** Developer\
**Created:** [January 28, 2022, 6:16pm UTC](https://discuss.tryton.org/t/typeerror-unsupported-operand-type-s-for-int-and-datetime-timedelta/4966 "2022-01-28T18:16:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mimo\_Alva](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@mimo\_Alva](https://discuss.tryton.org/u/mimo_Alva)\
**Post date:** [January 28, 2022, 6:16pm UTC](https://discuss.tryton.org/t/typeerror-unsupported-operand-type-s-for-int-and-datetime-timedelta/4966/1 "2022-01-28T18:16:17Z")

</div>

Hi;  
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:

```auto
    @classmethod
    def format_duration(cls, duration , lang, digits=2, grouping=True,
            monetary=None):
        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:**

```auto
      <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:

```auto
          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.

```auto

Thanks in advance.
```

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [January 28, 2022, 11:54pm UTC](https://discuss.tryton.org/t/typeerror-unsupported-operand-type-s-for-int-and-datetime-timedelta/4966/2 "2022-01-28T23:54:35Z")

</div>

Python [`sum`](https://docs.python.org/3/library/functions.html#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())`
