|
2 | 2 |
|
3 | 3 | import calendar |
4 | 4 | import math |
5 | | -from collections.abc import Callable |
6 | 5 | from decimal import Decimal |
7 | 6 | from operator import attrgetter |
8 | 7 | from typing import TYPE_CHECKING, cast |
|
27 | 26 | from .models import Interaction |
28 | 27 |
|
29 | 28 | if TYPE_CHECKING: |
| 29 | + from collections.abc import Callable |
| 30 | + |
30 | 31 | from django.http import HttpRequest |
31 | 32 |
|
32 | 33 | from weblate_web.payments.models import CustomerQuerySet |
@@ -367,9 +368,7 @@ def get_title(self) -> str: |
367 | 368 | return f"Income Tracking - {year}/{month:02d}" |
368 | 369 | return f"Income Tracking - {year}" |
369 | 370 |
|
370 | | - def generate_svg_pie_chart( |
371 | | - self, data: dict[InvoiceCategory, Decimal] |
372 | | - ) -> str: # noqa: PLR0914 |
| 371 | + def generate_svg_pie_chart(self, data: dict[InvoiceCategory, Decimal]) -> str: |
373 | 372 | """Generate a simple SVG pie chart for category distribution with legend.""" |
374 | 373 | if not data or sum(data.values()) == 0: |
375 | 374 | return "" |
@@ -602,6 +601,7 @@ def _aggregate_income_by_period( |
602 | 601 |
|
603 | 602 | Returns: |
604 | 603 | Tuple of (period_totals_dict, invoices_list) |
| 604 | +
|
605 | 605 | """ |
606 | 606 | invoices, invoice_totals = self._get_invoices_and_totals(year, month) |
607 | 607 |
|
@@ -639,14 +639,18 @@ def get_income_data( |
639 | 639 |
|
640 | 640 | def get_monthly_data(self, year: int) -> tuple[dict[str, Decimal], list]: |
641 | 641 | """Get monthly income data for the year.""" |
| 642 | + |
642 | 643 | def filter_by_month(inv: object, key: str) -> bool: |
643 | 644 | return inv.issue_date.month == int(key) |
644 | 645 |
|
645 | 646 | monthly_keys = [f"{month:02d}" for month in range(1, 13)] |
646 | | - return self._aggregate_income_by_period(year, None, filter_by_month, monthly_keys) |
| 647 | + return self._aggregate_income_by_period( |
| 648 | + year, None, filter_by_month, monthly_keys |
| 649 | + ) |
647 | 650 |
|
648 | 651 | def get_daily_data(self, year: int, month: int) -> tuple[dict[str, Decimal], list]: |
649 | 652 | """Get daily income data for a specific month.""" |
| 653 | + |
650 | 654 | def filter_by_day(inv: object, key: str) -> bool: |
651 | 655 | return inv.issue_date.day == int(key) |
652 | 656 |
|
@@ -694,7 +698,7 @@ def get_context_data(self, **kwargs): |
694 | 698 |
|
695 | 699 | # Get income data (returns dict with InvoiceCategory keys) |
696 | 700 | income_data = self.get_income_data(year, month) |
697 | | - |
| 701 | + |
698 | 702 | # Convert to label-keyed dict for template display |
699 | 703 | income_data_labels = {cat.label: amount for cat, amount in income_data.items()} |
700 | 704 | context["income_data"] = income_data_labels |
|
0 commit comments