From 876b30b1079a7f40901d80442beedd80ac81c278 Mon Sep 17 00:00:00 2001 From: behruz-dev Date: Wed, 5 Nov 2025 16:25:39 +0500 Subject: [PATCH] fix --- .../apps/finance/management/commands/count.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 core/apps/finance/management/commands/count.py diff --git a/core/apps/finance/management/commands/count.py b/core/apps/finance/management/commands/count.py new file mode 100644 index 0000000..6ef8624 --- /dev/null +++ b/core/apps/finance/management/commands/count.py @@ -0,0 +1,43 @@ +from django.db.models import Count +from core.apps.finance.models import Expence +from django.core.management import BaseCommand + +def get_duplicate_expenses_all(): + """ + Barcha counterparty boyicha bir xil summada yaratilgan expenselarni topadi + """ + expences = Expence.objects.filter( + is_deleted=False + ).values('counterparty', 'price', 'currency').annotate( + count=Count('id') + ).filter(count__gt=1).order_by('-count') + + return expences + +class Command(BaseCommand): + def handle(self, *args, **options): + + + duplicate_data = get_duplicate_expenses_all() + + result = [] + for item in duplicate_data: + expenses = Expence.objects.filter( + is_deleted=False, + counterparty_id=item['counterparty'], + price=item['price'], + currency=item['currency'] + ) + + counterparty = expenses.first().counterparty if expenses.exists() else None + + result.append({ + 'counterparty': counterparty, + 'amount': item['price'], + 'currency': item['currency'], + 'count': item['count'], + 'expenses': expenses + }) + + print(result) +