If I have a payment term configured with the following values:
- Number of months: 2
- Day of month: 20
Then I try on “Test Payment Term” to see how is the maturity date define, so I fill in the following values:
- Payment term: “Number of months”: 2 “Day of month”: 20
- Date: 31/10/2023
- Amount: 500
The maturity date proposed is 20/12/2023
Why does it propose this date? Shouldn’t it be 20/01/2024 having into account the payment term configuration?
31/10/2023 + 2 Months = 31/12/2023
Then you said you want to make the payment on day 20 of the month, so 20/12/2023.
Probably what you want is what is explained here: Fixed day payment terms - #25 by pokoli
Hope it helps!
The behavior is documented at relativedelta — dateutil 2.8.2 documentation
But mainly what is done is:
- add 2 months → 31/12/2023
- set the day of the month → 20/10/2023
So I guess what you want is:
- add 73 (2 * 31 + 11) days → 01/01/2024
- set the day of the month → 20/01/2024
This is done using two deltas:
I use 73 days because I guess what you want is that if the start is before 20 it is the 20 of December. So so it is 2 times the largest months, plus the remaining days from 20 to go at the end of the month.
It is complicated because your term is complex because there is an implicit condition.
Because the rule is add 2 months then if it is before 20 go to 20 of the month otherwise add 1 month and go to 20.
Another way is:
>>> dt.date(2023, 10, 21) + relativedelta(days=-20) + relativedelta(months=3) + relativedelta(day=20)
datetime.date(2024, 1, 20)