From 0b5d98fdc463e35cc80b3473990d11e77d125625 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 27 Jan 2026 00:59:02 +0100 Subject: [PATCH] fix: Prefer line-level period text and broaden invoice title parsing - Parse 'periode/abonnement' from line description - Broaden invoice title fields used for period detection - Prefer line period over invoice period - Improve month assignment accuracy --- app/services/subscription_matrix.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/services/subscription_matrix.py b/app/services/subscription_matrix.py index 9d87127..58fd289 100644 --- a/app/services/subscription_matrix.py +++ b/app/services/subscription_matrix.py @@ -174,6 +174,11 @@ class SubscriptionMatrixService: invoice_text_parts.append(str(val)) elif notes: invoice_text_parts.append(str(notes)) + # Common title/description fields + for key in ["heading", "description", "text", "subject"]: + val = invoice.get(key) + if val: + invoice_text_parts.append(str(val)) other_ref = invoice.get('otherReference') or invoice.get('orderNumberDb') if other_ref: invoice_text_parts.append(str(other_ref)) @@ -194,6 +199,7 @@ class SubscriptionMatrixService: and "abonnement" not in invoice_text ): continue + line_period = self._extract_period_from_text(line_description) or invoice_period if not product_number and not product_name: logger.debug(f"Skipping line without product number: {line}") @@ -210,7 +216,12 @@ class SubscriptionMatrixService: # If no period on line, use invoice date as month if not period_from_str: - if invoice_period: + if line_period: + period_from = line_period + period_to = self._end_of_month(period_from) + period_from_str = period_from.isoformat().split('T')[0] + period_to_str = period_to.isoformat().split('T')[0] + elif invoice_period: period_from = invoice_period period_to = self._end_of_month(period_from) period_from_str = period_from.isoformat().split('T')[0]