From 27db599e8c901033eb81f1bc70db5e6fdff609fd Mon Sep 17 00:00:00 2001 From: Sayyid Hamid Mahdavi Date: Sat, 7 Feb 2026 12:37:14 +0330 Subject: [PATCH] new Dockerfile --- apps/core/utils/jalali_date.py | 4 ++-- apps/wallet/models.py | 37 ++++++++++++++++++++++++++++++++++ wallet/settings.py | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/apps/core/utils/jalali_date.py b/apps/core/utils/jalali_date.py index 6c7fd93..8b65cd1 100644 --- a/apps/core/utils/jalali_date.py +++ b/apps/core/utils/jalali_date.py @@ -5,8 +5,8 @@ from django.contrib.admin.widgets import AdminDateWidget from django.forms.fields import DateField, SplitDateTimeField, TimeField, DateTimeField from django.utils.encoding import force_str from datetime import date as datetime_date, datetime as datetime_datetime -from jdatetime import GregorianToJalali, datetime as jalali_datetime -import jdatetime +# from jdatetime import GregorianToJalali, datetime as jalali_datetime +# import jdatetime class JalaliDateField(DateField): def __init__(self, *, input_formats=None, **kwargs): diff --git a/apps/wallet/models.py b/apps/wallet/models.py index b004945..0b7aca9 100755 --- a/apps/wallet/models.py +++ b/apps/wallet/models.py @@ -8,6 +8,10 @@ from django.db import transaction from django.db.models import F from django.utils import timezone from django.utils.translation import gettext_lazy as _ + +from collections import defaultdict +from django.db.models import Count, Sum + from rest_framework.exceptions import APIException from django.conf import settings from oauth2_provider import settings as oauth2_settings @@ -97,6 +101,39 @@ class TransactionQuerySet(models.QuerySet): def available(self): return self.select_related('payer_account', 'payee_account') + def group_by_reference(self, reference): + from collections import defaultdict + from django.db.models import Count, Sum + + # 'id': id, + # 'appid': appid, + # 'message': message, + # 'title': title, + # 'priority': priority, + # 'date': date.toIso8601String(), + + Transaction.objects.values('reference').annotate( + total=Sum('amount'), + count=Count('id') + ).values_list('refrence', 'total', 'count') + + # کوئری ۲: همه تراکنش‌ها + transactions = Transaction.objects.all().order_by('refrence', 'created_at') + + # گروه‌بندی در پایتون + groups = defaultdict(list) + for t in transactions: + groups[t.refrence].append(t) + + # ترکیب + result = [] + for ref, items in groups.items(): + result.append({ + 'refrence': ref, + 'stats': {'total': stats.get(ref, 0), 'count': len(items)}, + 'transactions': items + }) + class Transaction(BaseModel): amount = models.PositiveBigIntegerField(_('amount'), blank=False, validators=[MinValueValidator(1)]) diff --git a/wallet/settings.py b/wallet/settings.py index 5837519..66aece4 100644 --- a/wallet/settings.py +++ b/wallet/settings.py @@ -47,7 +47,7 @@ INSTALLED_APPS = [ 'crispy_forms', 'crispy_bootstrap5', 'django_filters', - 'jalali_date', + # 'jalali_date', # local apps 'apps.core',