Field TimeDelta define a period in month

Is it possible to use a TimeDelta field to store a period in months and add it to a date?
For example :

  • Warranty: 12M
  • Start date: 07/20/2021
  • End date: 07/15/2022 (start_date + warranty) but should be 07/20/2022

I understand the why (the duration is stored in days). Is there a way to go back to a number of months before adding it to a date?

No the Python datetime.timedelta store a fixed duration. Indeed you need to store a dateutil.relativedelta.relativedelta like it is done with account.invoice.payment_term.line.delta.
It may be a good improvement to have a reusable Mixin in trytond.

I will see.

in addition, I saw that in base the field is stored in an interval type of postgres, wouldn’t it be easier to use the posgres possibility to store the data in months directly?

There is no exact matching for SQL INTERVAL in Python but a timedelta can always be stored as and retrieved from an INTERVAL (by using only days and seconds).

psyopg2 casting of INTERVAL

It uses the fixed values of 30 days per month and 365 days per year (which are the same default value used by the client to format timedelta).
But normally there should be no values above days in INTERVAL that Tryton writes.

A relativedelta can not be fully stored as an INTERVAL because it is missing some concept like weekday, day of the month etc.

In Tryton the data input is always a Python object so we can only use object that can be stored without loose.