fix: Fix month calculation bug in date filter
v1.3.138: - Fixed ValueError: month must be in 1..12 - Use python-dateutil for proper month arithmetic - Uses relativedelta for correct 13 month calculation
This commit is contained in:
parent
1bf04d45b1
commit
e0909d4586
@ -451,17 +451,9 @@ class EconomicService:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Calculate first day of the month 13 months ago (for yearly billed items)
|
# Calculate first day of the month 13 months ago (for yearly billed items)
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
# Go back 13 months
|
start_date = (now - relativedelta(months=13)).replace(day=1).strftime('%Y-%m-%d')
|
||||||
months_back = 13
|
|
||||||
if now.month > months_back:
|
|
||||||
start_month = now.month - months_back
|
|
||||||
start_year = now.year
|
|
||||||
else:
|
|
||||||
start_month = 12 - (months_back - now.month)
|
|
||||||
start_year = now.year - 1
|
|
||||||
|
|
||||||
start_date = datetime(start_year, start_month, 1).strftime('%Y-%m-%d')
|
|
||||||
logger.info(f"📅 Fetching invoices from {start_date} onwards (13 months for yearly billed items)")
|
logger.info(f"📅 Fetching invoices from {start_date} onwards (13 months for yearly billed items)")
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
|
|||||||
@ -5,6 +5,7 @@ pydantic==2.10.3
|
|||||||
pydantic-settings==2.6.1
|
pydantic-settings==2.6.1
|
||||||
python-dotenv==1.0.1
|
python-dotenv==1.0.1
|
||||||
python-multipart==0.0.17
|
python-multipart==0.0.17
|
||||||
|
python-dateutil==2.8.2
|
||||||
jinja2==3.1.4
|
jinja2==3.1.4
|
||||||
aiohttp==3.10.10
|
aiohttp==3.10.10
|
||||||
msal==1.31.1
|
msal==1.31.1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user