fix: Adjust date filter to 1st of month 12 months back
v1.3.136: - Changed filter from 365 days to exactly 12 months - Uses 1st day of the month 12 months ago - Example: Jan 27, 2026 -> fetches from Feb 1, 2025
This commit is contained in:
parent
180933948f
commit
86ad68c362
@ -450,9 +450,18 @@ class EconomicService:
|
||||
List of invoice records with lines from the last year
|
||||
"""
|
||||
try:
|
||||
# Calculate date 1 year ago
|
||||
one_year_ago = (datetime.now() - timedelta(days=365)).strftime('%Y-%m-%d')
|
||||
logger.info(f"📅 Fetching invoices from {one_year_ago} onwards (1 year filter)")
|
||||
# Calculate first day of the month 12 months ago
|
||||
now = datetime.now()
|
||||
# Go back 12 months
|
||||
if now.month > 12:
|
||||
start_month = now.month - 12
|
||||
start_year = now.year
|
||||
else:
|
||||
start_month = 12 - (12 - 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 (12 months from 1st of month)")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
# Try multiple endpoints to find invoices
|
||||
@ -483,7 +492,7 @@ class EconomicService:
|
||||
params={
|
||||
"pagesize": 1000,
|
||||
"skippages": page,
|
||||
"filter": f"date$gte:{one_year_ago}"
|
||||
"filter": f"date$gte:{start_date}"
|
||||
},
|
||||
headers=self._get_headers()
|
||||
) as response:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user